Skip to content

Commit dfd114f

Browse files
committed
feat: implement belt upgrades
1 parent 32c731f commit dfd114f

40 files changed

Lines changed: 491 additions & 108 deletions

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,26 @@
2525

2626
<div align="center">
2727

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

3032
</div>
3133

32-
1. **Craft** a Utility Belt using the recipe above.
33-
2. **Equip** it in your belt slot.
34-
3. **Fill** it with your tools and weapons.
34+
1. **Craft** two belt pouches using the recipe above.
35+
2. **Craft** a Utility Belt using the recipe above.
36+
3. **Equip** it in your belt slot.
37+
4. **Fill** it with your tools and weapons.
38+
39+
## ⬆️ Upgrading the Belt
40+
41+
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.
42+
43+
<div align="center">
44+
45+
![The recipe for the belt upgrade](https://cdn.jamalam.tech/mod-assets/utility-belt-belt-upgrade-recipe.png)
46+
47+
</div>
3548

3649
## 🎮 Controls
3750

common/src/client/java/io/github/jamalam360/utility_belt/client/Config.java renamed to common/src/client/java/io/github/jamalam360/utility_belt/client/ClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import java.util.List;
77

8-
public class Config implements ConfigExtensions<Config> {
8+
public class ClientConfig implements ConfigExtensions<ClientConfig> {
99
public boolean displayUtilityBeltWhenNotSelected = true;
1010
public boolean invertScrolling = false;
1111
public boolean useSneakSwapping = true;

common/src/client/java/io/github/jamalam360/utility_belt/client/UtilityBeltClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.lwjgl.glfw.GLFW;
2828

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

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

90-
if (CONFIG.get().invertScrolling) {
90+
if (CLIENT_CONFIG.get().invertScrolling) {
9191
scrollY = -scrollY;
9292
}
9393

common/src/client/java/io/github/jamalam360/utility_belt/client/mixin/MinecraftMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class MinecraftMixin {
4343
private boolean utilitybelt$useHotbarKeysInBelt(boolean pressed, @Local int i) {
4444
StateManager stateManager = StateManager.getStateManager(true);
4545
if (stateManager.isInBelt(this.player) && pressed) {
46-
switch (UtilityBeltClient.CONFIG.get().hotbarKeyBehaviour) {
46+
switch (UtilityBeltClient.CLIENT_CONFIG.get().hotbarKeyBehaviour) {
4747
case SWITCH_BACK_TO_HOTBAR:
4848
stateManager.setInBelt(this.player, false);
4949
ClientNetworking.sendNewStateToServer(false, stateManager.getSelectedBeltSlot(this.player), this.player.isCrouching());

common/src/client/java/io/github/jamalam360/utility_belt/client/network/ClientNetworking.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void init() {
2020
}
2121

2222
public static void sendNewStateToServer(boolean inBelt, int slot, boolean swapItems) {
23-
if (swapItems && !UtilityBeltClient.CONFIG.get().useSneakSwapping) {
23+
if (swapItems && !UtilityBeltClient.CLIENT_CONFIG.get().useSneakSwapping) {
2424
swapItems = false;
2525
}
2626

common/src/client/java/io/github/jamalam360/utility_belt/client/render/BeltHotbarRenderer.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414

1515
public class BeltHotbarRenderer {
1616

17-
private static final ResourceLocation UTILITY_BELT_HOTBAR_TEXTURE = UtilityBelt
18-
.id("utility_belt_hotbar");
17+
private static final ResourceLocation HOTBAR_SLOT_TOP_SPRITE = UtilityBelt
18+
.id("utility_belt_hotbar_slot_top");
19+
private static final ResourceLocation HOTBAR_SLOT_MIDDLE_SPRITE = UtilityBelt
20+
.id("utility_belt_hotbar_slot_middle");
21+
private static final ResourceLocation HOTBAR_SLOT_BOTTOM_SPRITE = UtilityBelt
22+
.id("utility_belt_hotbar_slot_bottom");
1923
private static final ResourceLocation HOTBAR_SELECTION_SPRITE = ResourceLocation.withDefaultNamespace("hud/hotbar_selection");
2024

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

3034
if (stateManager.hasBelt(player) && (stateManager.isInBelt(player)
31-
|| UtilityBeltClient.CONFIG.get().displayUtilityBeltWhenNotSelected)) {
35+
|| UtilityBeltClient.CLIENT_CONFIG.get().displayUtilityBeltWhenNotSelected)) {
36+
UtilityBeltInventory inv = stateManager.getInventory(player);
3237
int scaledHeight = Minecraft.getInstance().getWindow().getGuiScaledHeight();
33-
int x = switch (UtilityBeltClient.CONFIG.get().hotbarPosition) {
38+
int hotbarHeight = inv.getContainerSize() * 20 + 2;
39+
int x = switch (UtilityBeltClient.CLIENT_CONFIG.get().hotbarPosition) {
3440
case TOP_LEFT, MIDDLE_LEFT, BOTTOM_LEFT -> 2;
3541
case TOP_RIGHT, MIDDLE_RIGHT, BOTTOM_RIGHT -> Minecraft.getInstance().getWindow().getGuiScaledWidth() - 24;
3642
};
37-
int y = switch (UtilityBeltClient.CONFIG.get().hotbarPosition) {
43+
int y = switch (UtilityBeltClient.CLIENT_CONFIG.get().hotbarPosition) {
3844
case TOP_LEFT, TOP_RIGHT -> 2;
39-
case MIDDLE_LEFT, MIDDLE_RIGHT -> scaledHeight / 2 - 44;
40-
case BOTTOM_LEFT, BOTTOM_RIGHT -> scaledHeight - 90;
45+
case MIDDLE_LEFT, MIDDLE_RIGHT -> scaledHeight / 2 - (hotbarHeight / 2);
46+
case BOTTOM_LEFT, BOTTOM_RIGHT -> scaledHeight - hotbarHeight - 2;
4147
};
4248

43-
x += UtilityBeltClient.CONFIG.get().hotbarOffsetX;
44-
y += UtilityBeltClient.CONFIG.get().hotbarOffsetY;
49+
x += UtilityBeltClient.CLIENT_CONFIG.get().hotbarOffsetX;
50+
y += UtilityBeltClient.CLIENT_CONFIG.get().hotbarOffsetY;
4551

46-
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, UTILITY_BELT_HOTBAR_TEXTURE, x, y, 22, 88);
52+
int m = 1;
53+
int slotY = y;
54+
for (int n = 0; n < inv.getContainerSize(); n++) {
55+
if (n == 0) {
56+
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SLOT_TOP_SPRITE, x, slotY, 22, 21);
57+
slotY += 21;
58+
} else if (n == inv.getContainerSize() - 1) {
59+
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SLOT_BOTTOM_SPRITE, x, slotY, 22, 21);
60+
slotY += 21;
61+
} else {
62+
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SLOT_MIDDLE_SPRITE, x, slotY, 22, 20);
63+
slotY += 20;
64+
}
4765

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

52-
UtilityBeltInventory inv = stateManager.getInventory(player);
53-
int m = 1;
54-
55-
for (int n = 0; n < inv.getContainerSize(); n++) {
56-
renderHotbarItem(graphics, x, y + n * 22 + 3, deltaTracker.getGameTimeDeltaTicks(), player, inv.getItem(n), m++);
69+
if (stateManager.isInBelt(player)) {
70+
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, HOTBAR_SELECTION_SPRITE, x - 1, y - 1 + stateManager.getSelectedBeltSlot(player) * 20, 24, 23);
5771
}
5872
}
5973
}

common/src/client/java/io/github/jamalam360/utility_belt/client/render/BeltRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public <S extends LivingEntityRenderState> void render(AccessoryRenderState acce
3131
throw new IllegalStateException("Utility belt can only be rendered on players");
3232
}
3333

34-
if (UtilityBeltClient.CONFIG.get().renderBelts) {
34+
if (UtilityBeltClient.CLIENT_CONFIG.get().renderBelts) {
3535
this.render(accessoryState, (HumanoidRenderState) entityState, (HumanoidModel<HumanoidRenderState>) model, matrices, collector);
3636
}
3737
}

common/src/client/java/io/github/jamalam360/utility_belt/client/screen/UtilityBeltScreen.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
import net.minecraft.world.entity.player.Inventory;
1111

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

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

2628
@Override
2729
protected void renderBg(GuiGraphics graphics, float delta, int mouseX, int mouseY) {
28-
graphics.blit(RenderPipelines.GUI_TEXTURED, TEXTURE, this.leftPos, this.topPos, 0F, 0F, this.imageWidth, this.imageHeight, 256, 256);
30+
int rows = this.menu.getBeltRows();
31+
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, BACKGROUND_TOP_SPRITE, this.leftPos, this.topPos, 176, 16);
32+
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, BACKGROUND_BOTTOM_SPRITE, this.leftPos, this.topPos + 16 + rows * 18, 176, 96);
33+
34+
for (int i = 0; i < rows; i++) {
35+
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, BACKGROUND_SLOT_ROW_SPRITE, this.leftPos, this.topPos + 16 + i * 18, 176, 18);
36+
}
37+
38+
int x = 0;
39+
int y = 0;
40+
while ((x + y * 9) < this.menu.getBeltInventorySize()) {
41+
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_SPRITE, this.leftPos + 7 + x * 18, this.topPos + 16 + y * 18, 18, 18);
42+
43+
x += 1;
44+
if (x == 9) {
45+
x = 0;
46+
y += 1;
47+
}
48+
}
2949
}
3050

3151
@Override

common/src/client/java/io/github/jamalam360/utility_belt/client/state/ClientStateManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.jamalam360.utility_belt.client.state;
22

3+
import io.github.jamalam360.utility_belt.UtilityBelt;
34
import io.github.jamalam360.utility_belt.UtilityBeltInventory;
45
import io.github.jamalam360.utility_belt.UtilityBeltItem;
56
import io.github.jamalam360.utility_belt.state.StateManager;
@@ -35,7 +36,7 @@ public UtilityBeltInventory getInventory(Player player) {
3536
ItemStack belt = UtilityBeltItem.getBelt(player);
3637

3738
if (belt == null) {
38-
return UtilityBeltInventory.EMPTY;
39+
return UtilityBeltInventory.empty(UtilityBelt.COMMON_CONFIG.get().initialBeltSize);
3940
} else {
4041
return UtilityBeltItem.getInventory(belt);
4142
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"model": {
3+
"type": "minecraft:model",
4+
"model": "utility_belt:item/pouch"
5+
}
6+
}

0 commit comments

Comments
 (0)