From 030268bfc36866fb9c8bc72c77d737da705a4db1 Mon Sep 17 00:00:00 2001 From: Sen Date: Mon, 18 Aug 2025 15:41:33 +0200 Subject: [PATCH] improve hotbar gui --- client/src/main/java/client/Client.java | 26 ++++++++++++++----- .../java/common/entity/npc/EntityNPC.java | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index 21dab296..2a0fd1b1 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -1077,12 +1077,13 @@ public class Client implements IThreadListener { int selected = this.player.getSelectedIndex(); int scale = this.scaleHotbar ? 2 : 1; int size = this.player.getHotbarSize(); + int x = this.fbX / 2 - size * (size <= 12 ? 10 : 6) * scale + 2 * scale - (size > 12 && selected != 0 ? 20 - 12 : 0) * scale; + int y = this.fbY - 20 * scale; for(int n = 0; n < size; n++) { - int x = this.fbX / 2 - size * 10 * scale + n * 20 * scale + 2 * scale; - int y = this.fbY - 20 * scale; if(selected == n) Drawing.drawRect(x - scale * 2, y - scale * 2, 20 * scale, 20 * scale, 0xffffffff); InventoryButton.drawButton(this, x - scale, y - scale, 18 * scale, 18 * scale, this.scaleHotbar); + x += (size <= 12 || selected == n || selected == n + 1 ? 20 : 12) * scale; } ItemStack itemstack = this.player.getHeldItem(); @@ -1231,19 +1232,29 @@ public class Client implements IThreadListener { GlState.color(1.0F, 1.0F, 1.0F, 1.0F); ItemRenderer.enableGUIStandardItemLighting(); GL11.glPushMatrix(); + int selected = this.player.getSelectedIndex(); int scale = this.scaleHotbar ? 2 : 1; int size = this.player.getHotbarSize(); - GL11.glTranslatef((float)(this.fbX / 2 - size * 10 * scale + 2 * scale), (float)(this.fbY - 20 * scale), 0.0f); + int bx = this.fbX / 2 - size * (size <= 12 ? 10 : 6) * scale + 2 * scale; + int by = this.fbY - 20 * scale; + GL11.glTranslatef((float)bx, (float)by, 0.0f); if(this.scaleHotbar) GL11.glScalef(2.0f, 2.0f, 2.0f); + int xPos = - (size > 12 && selected != 0 ? 20 - 12 : 0); for(int index = 0; index < size; ++index) { - int xPos = index * 20; ItemStack itemstack = this.player.getStackInSlot(index); if(itemstack != null) { + if(size > 12 && selected != index && selected != index + 1 && index != size - 1) { + this.scissor(bx + xPos * scale, this.fbY - (by + 16 * scale), 11 * scale, 16 * scale); + GL11.glEnable(GL11.GL_SCISSOR_TEST); + } GlState.enableDepth(); this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, 0); + if(size > 12 && selected != index && selected != index + 1 && index != size - 1) + GL11.glDisable(GL11.GL_SCISSOR_TEST); } + xPos += size <= 12 || selected == index || selected == index + 1 ? 20 : 12; } if(this.infoOverlay) { @@ -1273,14 +1284,17 @@ public class Client implements IThreadListener { GlState.enableBlend(); GlState.disableDepth(); if(this.world != null && this.open == null && this.player != null && this.viewEntity == this.player) { + int selected = this.player.getSelectedIndex(); int scale = this.scaleHotbar ? 2 : 1; int size = this.player.getHotbarSize(); + int xPos = - (size > 12 && selected != 0 ? 20 - 12 : 0) * scale; for(int index = 0; index < size; ++index) { ItemStack itemstack = this.player.getStackInSlot(index); - if(itemstack != null) { + if(itemstack != null && (size <= 12 || index == selected)) { GuiContainer.renderItemOverlay(itemstack, - this.fbX / 2 - size * 10 * scale + 2 * scale + index * 20 * scale, this.fbY - 20 * scale, null, index == this.player.getSelectedIndex() ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), scale); + this.fbX / 2 - size * (size <= 12 ? 10 : 6) * scale + 2 * scale + xPos, this.fbY - 20 * scale, null, index == this.player.getSelectedIndex() ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), scale); } + xPos += (size <= 12 || selected == index || selected == index + 1 ? 20 : 12) * scale; } } if(this.open != null) diff --git a/common/src/main/java/common/entity/npc/EntityNPC.java b/common/src/main/java/common/entity/npc/EntityNPC.java index 96ceda1d..5535e4d6 100755 --- a/common/src/main/java/common/entity/npc/EntityNPC.java +++ b/common/src/main/java/common/entity/npc/EntityNPC.java @@ -2484,7 +2484,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory } public int getHotbarSize() { - return 12; + return this.getInventoryCapacity(); } public int getSelectedIndex() {