Skip to content

Commit

Permalink
feat(client): allow configuring where the hotbar is rendered
Browse files Browse the repository at this point in the history
fixes #37
  • Loading branch information
Jamalam360 committed Apr 3, 2024
1 parent 89ecc79 commit 6719644
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
10 changes: 10 additions & 0 deletions common/src/main/java/io/github/jamalam360/utility_belt/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ public class Config {
public boolean displayUtilityBeltWhenNotSelected = true;
public boolean invertScrolling = false;
public HotbarKeyBehaviour hotbarKeyBehaviour = HotbarKeyBehaviour.SWITCH_BELT_SLOT;
public Position hotbarPosition = Position.MIDDLE_LEFT;

public enum HotbarKeyBehaviour {
SWITCH_BACK_TO_HOTBAR,
SWITCH_BELT_SLOT
}

public enum Position {
TOP_LEFT,
MIDDLE_LEFT,
BOTTOM_LEFT,
TOP_RIGHT,
MIDDLE_RIGHT,
BOTTOM_RIGHT
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.jamalam360.utility_belt.client;

import com.mojang.blaze3d.systems.RenderSystem;
import io.github.jamalam360.utility_belt.Config;
import io.github.jamalam360.utility_belt.StateManager;
import io.github.jamalam360.utility_belt.UtilityBelt;
import io.github.jamalam360.utility_belt.UtilityBeltInventory;
Expand All @@ -26,14 +27,23 @@ public static void render(GuiGraphics graphics, float tickDelta) {
if (player != null && stateManager.hasBelt(player) && (stateManager.isInBelt(player)
|| UtilityBelt.CONFIG.get().displayUtilityBeltWhenNotSelected)) {
int scaledHeight = Minecraft.getInstance().getWindow().getGuiScaledHeight();
int x = switch (UtilityBelt.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 (UtilityBelt.CONFIG.get().hotbarPosition) {
case TOP_LEFT, TOP_RIGHT -> 2;
case MIDDLE_LEFT, MIDDLE_RIGHT -> scaledHeight / 2 - 44;
case BOTTOM_LEFT, BOTTOM_RIGHT -> scaledHeight - 84;
};

RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShader(GameRenderer::getPositionTexShader);

graphics.blit(UTILITY_BELT_WIDGET_TEXTURE, 2, scaledHeight / 2 - 44, 0, 0, 22, 88);
graphics.blit(UTILITY_BELT_WIDGET_TEXTURE, x, y, 0, 0, 22, 88);

if (stateManager.isInBelt(player)) {
graphics.blitSprite(HOTBAR_SELECTION_SPRITE, 1, scaledHeight / 2 - 45 + stateManager.getSelectedBeltSlot(player) * 20, 0, 24, 23);
graphics.blitSprite(HOTBAR_SELECTION_SPRITE, x - 1, y - 1 + stateManager.getSelectedBeltSlot(player) * 20, 0, 24, 23);
}

UtilityBeltInventory inv = stateManager.getInventory(player);
Expand All @@ -42,12 +52,12 @@ public static void render(GuiGraphics graphics, float tickDelta) {
int m = 1;

for (int n = 0; n < inv.getContainerSize(); ++n) {
renderHotbarItem(graphics, scaledHeight / 2 - 45 + n * 20 + 4, tickDelta, player, inv.getItem(n), m++);
renderHotbarItem(graphics, x, y + n * 20 + 3, tickDelta, player, inv.getItem(n), m++);
}
}
}

private static void renderHotbarItem(GuiGraphics graphics, int y, float tickDelta, Player player, ItemStack stack, int seed) {
private static void renderHotbarItem(GuiGraphics graphics, int x, int y, float tickDelta, Player player, ItemStack stack, int seed) {
if (!stack.isEmpty()) {
float f = (float) stack.getPopTime() - tickDelta;
if (f > 0.0F) {
Expand All @@ -58,12 +68,12 @@ private static void renderHotbarItem(GuiGraphics graphics, int y, float tickDelt
graphics.pose().translate(-12, -(y + 12), 0);
}

graphics.renderItem(player, stack, 5, y, seed);
graphics.renderItem(player, stack, x + 3, y, seed);
if (f > 0.0F) {
graphics.pose().popPose();
}

graphics.renderItemDecorations(Minecraft.getInstance().font, stack, 4, y);
graphics.renderItemDecorations(Minecraft.getInstance().font, stack, x + 3, y);
}
}
}
7 changes: 7 additions & 0 deletions common/src/main/resources/assets/utility_belt/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"key.utility_belt.open_screen": "Open Utility Belt GUI",
"config.utility_belt.invertScrolling": "Invert Scrolling in Belt Hotbar",
"config.utility_belt.displayUtilityBeltWhenNotSelected": "Show Utility Belt Hotbar When Not Selected",
"config.utility_belt.hotbarPosition": "Hotbar Position",
"config.utility_belt.hotbarPosition.top_left": "Top Left",
"config.utility_belt.hotbarPosition.middle_left": "Middle Left",
"config.utility_belt.hotbarPosition.bottom_left": "Bottom Left",
"config.utility_belt.hotbarPosition.top_right": "Top Right",
"config.utility_belt.hotbarPosition.middle_right": "Middle Right",
"config.utility_belt.hotbarPosition.bottom_right": "Bottom Right",
"config.utility_belt.hotbarKeyBehaviour": "Hotbar Key Behaviour While in Belt",
"config.utility_belt.hotbarKeyBehaviour.tooltip": "When set to 'Switch Back', pressing the hotbar key while in the belt will switch back to the hotbar. When set to 'Switch Belt Slot', pressing the hotbar key will switch to the corresponding belt slot.",
"config.utility_belt.hotbarKeyBehaviour.switch_back_to_hotbar": "Switch Back",
Expand Down

0 comments on commit 6719644

Please sign in to comment.