Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,26 @@

<div align="center">

![The recipe for the Utility Belt](https://cdn.jamalam.tech/mod-assets/utility-belt-recipe.png)
![The recipe for the belt pouch](https://cdn.jamalam.tech/mod-assets/utility-belt-pouch-recipe.png)

![The recipe for the belt](https://cdn.jamalam.tech/mod-assets/utility-belt-belt-recipe.png)

</div>

1. **Craft** a Utility Belt using the recipe above.
2. **Equip** it in your belt slot.
3. **Fill** it with your tools and weapons.
1. **Craft** two belt pouches using the recipe above.
2. **Craft** a Utility Belt using the recipe above.
3. **Equip** it in your belt slot.
4. **Fill** it with your tools and weapons.

## ⬆️ Upgrading the Belt

By default, the belt has **4** slots and can be upgraded to have up to **6** slots (_these values can be changed in the mod configuration_). You can add a slot to a belt in a **Smithing Table** using the recipe below.

<div align="center">

![The recipe for the belt upgrade](https://cdn.jamalam.tech/mod-assets/utility-belt-belt-upgrade-recipe.png)

</div>

## 🎮 Controls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.List;

public class Config implements ConfigExtensions<Config> {
public class ClientConfig implements ConfigExtensions<ClientConfig> {
public boolean displayUtilityBeltWhenNotSelected = true;
public boolean invertScrolling = false;
public boolean useSneakSwapping = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.lwjgl.glfw.GLFW;

public class UtilityBeltClient {
public static final ConfigManager<Config> CONFIG = new ConfigManager<>(UtilityBelt.MOD_ID, Config.class);
public static final ConfigManager<ClientConfig> CLIENT_CONFIG = new ConfigManager<>(UtilityBelt.MOD_ID, "client", ClientConfig.class);
private static final KeyMapping.Category KEY_CATEGORY = KeyMapping.Category.register(UtilityBelt.id("utility_belt"));
private static final KeyMapping SWAP_TOGGLE = new KeyMapping("key.utility_belt.swap_toggle", GLFW.GLFW_KEY_B, KEY_CATEGORY);
private static final KeyMapping SWAP_HOLD = new KeyMapping("key.utility_belt.swap_hold", GLFW.GLFW_KEY_N, KEY_CATEGORY);
Expand Down Expand Up @@ -87,7 +87,7 @@ private static EventResult onMouseScrolled(Minecraft client, double scrollX, dou

int beltSize = stateManager.getInventory(player).getContainerSize();

if (CONFIG.get().invertScrolling) {
if (CLIENT_CONFIG.get().invertScrolling) {
scrollY = -scrollY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class MinecraftMixin {
private boolean utilitybelt$useHotbarKeysInBelt(boolean pressed, @Local int i) {
StateManager stateManager = StateManager.getStateManager(true);
if (stateManager.isInBelt(this.player) && pressed) {
switch (UtilityBeltClient.CONFIG.get().hotbarKeyBehaviour) {
switch (UtilityBeltClient.CLIENT_CONFIG.get().hotbarKeyBehaviour) {
case SWITCH_BACK_TO_HOTBAR:
stateManager.setInBelt(this.player, false);
ClientNetworking.sendNewStateToServer(false, stateManager.getSelectedBeltSlot(this.player), this.player.isCrouching());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void init() {
}

public static void sendNewStateToServer(boolean inBelt, int slot, boolean swapItems) {
if (swapItems && !UtilityBeltClient.CONFIG.get().useSneakSwapping) {
if (swapItems && !UtilityBeltClient.CLIENT_CONFIG.get().useSneakSwapping) {
swapItems = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@

public class BeltHotbarRenderer {

private static final ResourceLocation UTILITY_BELT_HOTBAR_TEXTURE = UtilityBelt
.id("utility_belt_hotbar");
private static final ResourceLocation HOTBAR_SLOT_TOP_SPRITE = UtilityBelt
.id("utility_belt_hotbar_slot_top");
private static final ResourceLocation HOTBAR_SLOT_MIDDLE_SPRITE = UtilityBelt
.id("utility_belt_hotbar_slot_middle");
private static final ResourceLocation HOTBAR_SLOT_BOTTOM_SPRITE = UtilityBelt
.id("utility_belt_hotbar_slot_bottom");
private static final ResourceLocation HOTBAR_SELECTION_SPRITE = ResourceLocation.withDefaultNamespace("hud/hotbar_selection");

public static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
Expand All @@ -28,32 +32,42 @@ public static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
StateManager stateManager = StateManager.getStateManager(player);

if (stateManager.hasBelt(player) && (stateManager.isInBelt(player)
|| UtilityBeltClient.CONFIG.get().displayUtilityBeltWhenNotSelected)) {
|| UtilityBeltClient.CLIENT_CONFIG.get().displayUtilityBeltWhenNotSelected)) {
UtilityBeltInventory inv = stateManager.getInventory(player);
int scaledHeight = Minecraft.getInstance().getWindow().getGuiScaledHeight();
int x = switch (UtilityBeltClient.CONFIG.get().hotbarPosition) {
int hotbarHeight = inv.getContainerSize() * 20 + 2;
int x = switch (UtilityBeltClient.CLIENT_CONFIG.get().hotbarPosition) {
case TOP_LEFT, MIDDLE_LEFT, BOTTOM_LEFT -> 2;
case TOP_RIGHT, MIDDLE_RIGHT, BOTTOM_RIGHT -> Minecraft.getInstance().getWindow().getGuiScaledWidth() - 24;
};
int y = switch (UtilityBeltClient.CONFIG.get().hotbarPosition) {
int y = switch (UtilityBeltClient.CLIENT_CONFIG.get().hotbarPosition) {
case TOP_LEFT, TOP_RIGHT -> 2;
case MIDDLE_LEFT, MIDDLE_RIGHT -> scaledHeight / 2 - 44;
case BOTTOM_LEFT, BOTTOM_RIGHT -> scaledHeight - 90;
case MIDDLE_LEFT, MIDDLE_RIGHT -> scaledHeight / 2 - (hotbarHeight / 2);
case BOTTOM_LEFT, BOTTOM_RIGHT -> scaledHeight - hotbarHeight - 2;
};

x += UtilityBeltClient.CONFIG.get().hotbarOffsetX;
y += UtilityBeltClient.CONFIG.get().hotbarOffsetY;
x += UtilityBeltClient.CLIENT_CONFIG.get().hotbarOffsetX;
y += UtilityBeltClient.CLIENT_CONFIG.get().hotbarOffsetY;

graphics.blitSprite(RenderPipelines.GUI_TEXTURED, UTILITY_BELT_HOTBAR_TEXTURE, x, y, 22, 88);
int m = 1;
int slotY = y;
for (int n = 0; n < inv.getContainerSize(); n++) {
if (n == 0) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SLOT_TOP_SPRITE, x, slotY, 22, 21);
slotY += 21;
} else if (n == inv.getContainerSize() - 1) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SLOT_BOTTOM_SPRITE, x, slotY, 22, 21);
slotY += 21;
} else {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SLOT_MIDDLE_SPRITE, x, slotY, 22, 20);
slotY += 20;
}

if (stateManager.isInBelt(player)) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SELECTION_SPRITE, x - 1, y - 1 + stateManager.getSelectedBeltSlot(player) * 22, 24, 23);
renderHotbarItem(graphics, x, y + 3 + n * 20, deltaTracker.getGameTimeDeltaTicks(), player, inv.getItem(n), m++);
}

UtilityBeltInventory inv = stateManager.getInventory(player);
int m = 1;

for (int n = 0; n < inv.getContainerSize(); n++) {
renderHotbarItem(graphics, x, y + n * 22 + 3, deltaTracker.getGameTimeDeltaTicks(), player, inv.getItem(n), m++);
if (stateManager.isInBelt(player)) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SELECTION_SPRITE, x - 1, y - 1 + stateManager.getSelectedBeltSlot(player) * 20, 24, 23);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public <S extends LivingEntityRenderState> void render(AccessoryRenderState acce
throw new IllegalStateException("Utility belt can only be rendered on players");
}

if (UtilityBeltClient.CONFIG.get().renderBelts) {
if (UtilityBeltClient.CLIENT_CONFIG.get().renderBelts) {
this.render(accessoryState, (HumanoidRenderState) entityState, (HumanoidModel<HumanoidRenderState>) model, matrices, collector);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import net.minecraft.world.entity.player.Inventory;

public class UtilityBeltScreen extends AbstractContainerScreen<UtilityBeltMenu> {
private static final ResourceLocation TEXTURE = UtilityBelt.id("textures/gui/utility_belt_gui.png");
private static final ResourceLocation BACKGROUND_TOP_SPRITE = UtilityBelt.id("utility_belt_gui_top");
private static final ResourceLocation BACKGROUND_SLOT_ROW_SPRITE = UtilityBelt.id("utility_belt_gui_slot_row");
private static final ResourceLocation BACKGROUND_BOTTOM_SPRITE = UtilityBelt.id("utility_belt_gui_bottom");
private static final ResourceLocation SLOT_SPRITE = UtilityBelt.id("slot");

public UtilityBeltScreen(UtilityBeltMenu menu, Inventory inventory, Component title) {
super(menu, inventory, Component.translatable("container.utility_belt.utility_belt"));
Expand All @@ -19,13 +22,30 @@ public UtilityBeltScreen(UtilityBeltMenu menu, Inventory inventory, Component ti
@Override
protected void init() {
super.init();
this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2;
this.inventoryLabelY = this.imageHeight - 130;
this.inventoryLabelY = this.imageHeight - 130 + (this.menu.getBeltRows() - 1) * 18;
}

@Override
protected void renderBg(GuiGraphics graphics, float delta, int mouseX, int mouseY) {
graphics.blit(RenderPipelines.GUI_TEXTURED, TEXTURE, this.leftPos, this.topPos, 0F, 0F, this.imageWidth, this.imageHeight, 256, 256);
int rows = this.menu.getBeltRows();
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, BACKGROUND_TOP_SPRITE, this.leftPos, this.topPos, 176, 16);
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, BACKGROUND_BOTTOM_SPRITE, this.leftPos, this.topPos + 16 + rows * 18, 176, 96);

for (int i = 0; i < rows; i++) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, BACKGROUND_SLOT_ROW_SPRITE, this.leftPos, this.topPos + 16 + i * 18, 176, 18);
}

int x = 0;
int y = 0;
while ((x + y * 9) < this.menu.getBeltInventorySize()) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_SPRITE, this.leftPos + 7 + x * 18, this.topPos + 16 + y * 18, 18, 18);

x += 1;
if (x == 9) {
x = 0;
y += 1;
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.jamalam360.utility_belt.client.state;

import io.github.jamalam360.utility_belt.UtilityBelt;
import io.github.jamalam360.utility_belt.UtilityBeltInventory;
import io.github.jamalam360.utility_belt.UtilityBeltItem;
import io.github.jamalam360.utility_belt.state.StateManager;
Expand Down Expand Up @@ -35,7 +36,7 @@ public UtilityBeltInventory getInventory(Player player) {
ItemStack belt = UtilityBeltItem.getBelt(player);

if (belt == null) {
return UtilityBeltInventory.EMPTY;
return UtilityBeltInventory.empty(UtilityBelt.COMMON_CONFIG.get().initialBeltSize);
} else {
return UtilityBeltItem.getInventory(belt);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "utility_belt:item/pouch"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "utility_belt:item/pouch"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_diamond": {
"conditions": {
"items": [
{
"items": "minecraft:diamond"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_leather": {
"conditions": {
"items": [
{
"items": "minecraft:leather"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_string": {
"conditions": {
"items": [
{
"items": "minecraft:string"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "utility_belt:pouch"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_string",
"has_leather",
"has_diamond"
]
],
"rewards": {
"recipes": [
"utility_belt:pouch"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_pouch": {
"conditions": {
"items": [
{
"items": "utility_belt:pouch"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "utility_belt:upgrade_utility_belt"
},
"trigger": "minecraft:recipe_unlocked"
},
"has_utility_belt": {
"conditions": {
"items": [
{
"items": "utility_belt:utility_belt"
}
]
},
"trigger": "minecraft:inventory_changed"
}
},
"requirements": [
[
"has_the_recipe",
"has_utility_belt",
"has_pouch"
]
],
"rewards": {
"recipes": [
"utility_belt:upgrade_utility_belt"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_diamond": {
"has_leather": {
"conditions": {
"items": [
{
"items": "minecraft:diamond"
"items": "minecraft:leather"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_leather": {
"has_pouch": {
"conditions": {
"items": [
{
"items": "minecraft:leather"
"items": "utility_belt:pouch"
}
]
},
Expand All @@ -41,8 +41,8 @@
"requirements": [
[
"has_the_recipe",
"has_diamond",
"has_leather",
"has_pouch",
"has_string"
]
],
Expand Down
18 changes: 18 additions & 0 deletions common/src/generated/resources/data/utility_belt/recipe/pouch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type": "minecraft:crafting_shaped",
"category": "equipment",
"key": {
"D": "minecraft:diamond",
"L": "minecraft:leather",
"S": "minecraft:string"
},
"pattern": [
"SDS",
"L L",
"SLS"
],
"result": {
"count": 1,
"id": "utility_belt:pouch"
}
}
Loading
Loading