1
0
Fork 0

improve hotbar gui

This commit is contained in:
Sen 2025-08-18 15:41:33 +02:00
parent e1759b853e
commit 030268bfc3
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
2 changed files with 21 additions and 7 deletions

View file

@ -1077,12 +1077,13 @@ public class Client implements IThreadListener {
int selected = this.player.getSelectedIndex(); int selected = this.player.getSelectedIndex();
int scale = this.scaleHotbar ? 2 : 1; int scale = this.scaleHotbar ? 2 : 1;
int size = this.player.getHotbarSize(); int size = this.player.getHotbarSize();
for(int n = 0; n < size; n++) { int x = this.fbX / 2 - size * (size <= 12 ? 10 : 6) * scale + 2 * scale - (size > 12 && selected != 0 ? 20 - 12 : 0) * scale;
int x = this.fbX / 2 - size * 10 * scale + n * 20 * scale + 2 * scale;
int y = this.fbY - 20 * scale; int y = this.fbY - 20 * scale;
for(int n = 0; n < size; n++) {
if(selected == n) if(selected == n)
Drawing.drawRect(x - scale * 2, y - scale * 2, 20 * scale, 20 * scale, 0xffffffff); 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); 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(); ItemStack itemstack = this.player.getHeldItem();
@ -1231,19 +1232,29 @@ public class Client implements IThreadListener {
GlState.color(1.0F, 1.0F, 1.0F, 1.0F); GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
ItemRenderer.enableGUIStandardItemLighting(); ItemRenderer.enableGUIStandardItemLighting();
GL11.glPushMatrix(); GL11.glPushMatrix();
int selected = this.player.getSelectedIndex();
int scale = this.scaleHotbar ? 2 : 1; int scale = this.scaleHotbar ? 2 : 1;
int size = this.player.getHotbarSize(); 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) if(this.scaleHotbar)
GL11.glScalef(2.0f, 2.0f, 2.0f); GL11.glScalef(2.0f, 2.0f, 2.0f);
int xPos = - (size > 12 && selected != 0 ? 20 - 12 : 0);
for(int index = 0; index < size; ++index) { for(int index = 0; index < size; ++index) {
int xPos = index * 20;
ItemStack itemstack = this.player.getStackInSlot(index); ItemStack itemstack = this.player.getStackInSlot(index);
if(itemstack != null) { 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(); GlState.enableDepth();
this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, 0); 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) { if(this.infoOverlay) {
@ -1273,14 +1284,17 @@ public class Client implements IThreadListener {
GlState.enableBlend(); GlState.enableBlend();
GlState.disableDepth(); GlState.disableDepth();
if(this.world != null && this.open == null && this.player != null && this.viewEntity == this.player) { 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 scale = this.scaleHotbar ? 2 : 1;
int size = this.player.getHotbarSize(); int size = this.player.getHotbarSize();
int xPos = - (size > 12 && selected != 0 ? 20 - 12 : 0) * scale;
for(int index = 0; index < size; ++index) { for(int index = 0; index < size; ++index) {
ItemStack itemstack = this.player.getStackInSlot(index); ItemStack itemstack = this.player.getStackInSlot(index);
if(itemstack != null) { if(itemstack != null && (size <= 12 || index == selected)) {
GuiContainer.renderItemOverlay(itemstack, 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) if(this.open != null)

View file

@ -2484,7 +2484,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
} }
public int getHotbarSize() { public int getHotbarSize() {
return 12; return this.getInventoryCapacity();
} }
public int getSelectedIndex() { public int getSelectedIndex() {