1
0
Fork 0

fix hotbar rendering and window icon

This commit is contained in:
Sen 2025-08-22 00:06:53 +02:00
parent 156ba97505
commit 906517479f
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
3 changed files with 47 additions and 48 deletions

View file

@ -559,6 +559,8 @@ public class Client implements IThreadListener {
public boolean scaleItems = false;
@Variable(name = "gui_scale_hotbar", category = CVarCategory.GUI, display = "Leiste vergrößern")
public boolean scaleHotbar = false;
@Variable(name = "hud_margin", category = CVarCategory.GUI, min = 0, max = 120, unit = "px", display = "Seitenabstand der HUD")
private int hudMargin = 8;
@Variable(name = "phy_sensitivity", category = CVarCategory.INPUT, min = 0.01f, max = 10.0f, display = "Mausempfindlichkeit", precision = 2, unit = "%")
private float sensitivity = 1.0f;
@Variable(name = "gui_dclick_delay", category = CVarCategory.INPUT, min = 150, max = 750, display = "Doppelklick bei", unit = "ms")
@ -1061,6 +1063,13 @@ public class Client implements IThreadListener {
}
public void renderHud() {
final int selected = this.world != null && this.player != null && this.viewEntity == this.player ? this.player.getSelectedIndex() : -1;
final int scale = this.scaleHotbar ? 2 : 1;
final int size = this.world != null && this.player != null && this.viewEntity == this.player ? this.player.getHotbarSize() : 1;
final int width = (this.fbX / scale - 20) / size;
// final int bx = this.fbX / 2 - size * (width >= 20 ? 10 : width / 2) * scale + 2 * scale;
final int by = this.fbY - 20 * scale;
final int xoff = (this.fbX / scale - (width < 20 ? ((size - 2) * width + 40 + width / 2) : (size * 20 - 2))) / 2 + (width < 20 && selected == 0 ? 20 - width : 0) - 2;
this.setupOverlay();
if(this.world != null && !(this.open instanceof GuiConsole) && this.player != null && this.viewEntity == this.player) {
if(this.open == null) {
@ -1074,16 +1083,12 @@ 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;
int x = xoff * scale;
for(int n = 0; n < size; n++) {
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;
Drawing.drawRect(x - scale * 2, by - scale * 2, 20 * scale, 20 * scale, 0xffffffff);
InventoryButton.drawButton(this, x - scale, by - scale, 18 * scale, 18 * scale, this.scaleHotbar);
x += (width >= 20 || selected == n || selected == n + 1 ? 20 : width) * scale;
}
ItemStack itemstack = this.player.getHeldItem();
@ -1116,8 +1121,8 @@ public class Client implements IThreadListener {
}
if(!this.drawDebug || this.open != null) {
x = 40;
y = 40;
x = this.hudMargin;
y = this.hudMargin;
for(StatusEffect effect : this.player.getEffects()) {
Effect potion = effect.getPotion();
int color = potion.getColor();
@ -1140,8 +1145,8 @@ public class Client implements IThreadListener {
if(entity.getEnergy(energy) > 0)
stats += 1;
}
x = this.fbX - 40 - 250;
y = this.fbY - 40 - stats * 40;
x = this.fbX - this.hudMargin - 250;
y = this.fbY - this.hudMargin - 14 - (this.scaleHotbar ? 24 : 0) - stats * 40;
int hp = entity.getHealth();
int max = entity.getMaxHealth();
y = this.drawStat(x, y, Color.RED + "Schaden", hp, max, 0xff0000);
@ -1173,8 +1178,8 @@ public class Client implements IThreadListener {
}
}
x = 40;
y = this.fbY - 40 - (this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f ? 2 : 1) * 40;
x = this.hudMargin;
y = this.fbY - this.hudMargin - 14 - (this.scaleHotbar ? 24 : 0) - (this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f ? 2 : 1) * 40;
if(this.player.isRidingHorse() && this.player.getHorseJumpPower() != 0.0f) // {
y = this.drawBar(x, y, String.format(Color.NEON + "Sprungkraft: " + Color.CYAN + "%d %%", (int)(this.player.getHorseJumpPower() * 100.0f)),
this.player.getHorseJumpPower(), 0x4040ff);
@ -1210,15 +1215,15 @@ public class Client implements IThreadListener {
}
}
if(desc != null) {
Drawing.drawRectBorder(this.fbX / 2 - 180, 20, 360, 60, 0xff6f6f6f, 0xff000000, 0xffafafaf, 0xff4f4f4f);
Drawing.drawTextCentered(desc, this.fbX / 2, 24, 0xffffffff);
Drawing.drawRectBorder(this.fbX / 2 - 180, this.hudMargin, 360, 60, 0xff6f6f6f, 0xff000000, 0xffafafaf, 0xff4f4f4f);
Drawing.drawTextCentered(desc, this.fbX / 2, this.hudMargin + 4, 0xffffffff);
if(line1 != null)
Drawing.drawTextCentered(line1, this.fbX / 2, 80 - 4 - Font.HEIGHT * 2 - 2, 0xffffffff);
Drawing.drawTextCentered(line1, this.fbX / 2, this.hudMargin + 60 - 4 - Font.HEIGHT * 2 - 2, 0xffffffff);
if(line2 != null)
Drawing.drawTextCentered(line2, this.fbX / 2, 80 - 4 - Font.HEIGHT, 0xffffffff);
Drawing.drawTextCentered(line2, this.fbX / 2, this.hudMargin + 60 - 4 - Font.HEIGHT, 0xffffffff);
if(bar >= 0.0f) {
Drawing.drawRect(this.fbX / 2 - 140, 24 + Font.HEIGHT + 2, 280, 6, 0xff202020, 0xffcfcfcf, 0xff3f3f3f);
Drawing.drawGradient(this.fbX / 2 - 140 + 1, 24 + Font.HEIGHT + 2 + 1, (int)(278.0f * bar), 4, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000));
Drawing.drawRect(this.fbX / 2 - 140, this.hudMargin + 4 + Font.HEIGHT + 2, 280, 6, 0xff202020, 0xffcfcfcf, 0xff3f3f3f);
Drawing.drawGradient(this.fbX / 2 - 140 + 1, this.hudMargin + 4 + Font.HEIGHT + 2 + 1, (int)(278.0f * bar), 4, color | 0xff000000, Util.mixColor(color | 0xff000000, 0xff000000));
}
}
}
@ -1232,29 +1237,24 @@ 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();
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);
GL11.glTranslatef(0.0f, (float)by, 0.0f);
if(this.scaleHotbar)
GL11.glScalef(2.0f, 2.0f, 2.0f);
int xPos = - (size > 12 && selected != 0 ? 20 - 12 : 0);
int xPos = xoff;
for(int index = 0; index < size; ++index) {
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);
if(width < 20 && selected != index && selected != index + 1 && index != size - 1) {
this.scissor(xPos * scale, this.fbY - (by + 16 * scale), (width - 1) * 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)
if(width < 20 && selected != index && selected != index + 1 && index != size - 1)
GL11.glDisable(GL11.GL_SCISSOR_TEST);
}
xPos += size <= 12 || selected == index || selected == index + 1 ? 20 : 12;
xPos += width >= 20 || selected == index || selected == index + 1 ? 20 : width;
}
if(this.infoOverlay) {
@ -1266,7 +1266,7 @@ public class Client implements IThreadListener {
if(item != null) {
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glTranslatef((float)(this.fbX / 2 - 180 + 4 + 1), (float)(40 + 1), 0.0f);
GL11.glTranslatef((float)(this.fbX / 2 - 180 + 4 + 1), (float)(this.hudMargin + 20 + 1), 0.0f);
GL11.glScalef(2.0f, 2.0f, 2.0f);
GlState.enableDepth();
this.renderItem.renderItemAndEffectIntoGUI(new ItemStack(item), 0, 0);
@ -1284,17 +1284,14 @@ 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;
int xPos = xoff * scale;
for(int index = 0; index < size; ++index) {
ItemStack itemstack = this.player.getStackInSlot(index);
if(itemstack != null && (size <= 12 || index == selected)) {
if(itemstack != null && (width >= 20 || index == selected)) {
GuiContainer.renderItemOverlay(itemstack,
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, by, null, index == this.player.getSelectedIndex() ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), scale);
}
xPos += (size <= 12 || selected == index || selected == index + 1 ? 20 : 12) * scale;
xPos += (width >= 20 || selected == index || selected == index + 1 ? 20 : width) * scale;
}
}
if(this.open != null)
@ -3142,7 +3139,7 @@ public class Client implements IThreadListener {
int by = 0;
for(Entry<String, Integer> elem : this.playerList.entrySet()) {
int x = this.fbX / 2 - (w * 300) / 2 + bx * 300;
int y = 10 + by * (Font.HEIGHT + 2);
int y = this.hudMargin + by * (Font.HEIGHT + 2);
Drawing.drawGradient(x, y, 300, Font.HEIGHT + 2, 0x7f404040, 0x7f101010, 0x7f5f5f5f, 0x7f000000);
Drawing.drawText(elem.getKey(), x + 4, y + 1, 0xffffffff);
drawPing(x + 300 - 4, y + 1, elem.getValue());
@ -3727,12 +3724,12 @@ public class Client implements IThreadListener {
private static byte[] genTriwave(int w, int h, int color1, int color2, int color3, int color4, int color5, int color6) {
byte[] data = new byte[w * h * 4];
byte[] color = new byte[24];
color1 = (color1 << 8) | (color1 >> 24);
color2 = (color2 << 8) | (color2 >> 24);
color3 = (color3 << 8) | (color3 >> 24);
color4 = (color4 << 8) | (color4 >> 24);
color5 = (color5 << 8) | (color5 >> 24);
color6 = (color6 << 8) | (color6 >> 24);
color1 = (color1 << 8) | (color1 >>> 24);
color2 = (color2 << 8) | (color2 >>> 24);
color3 = (color3 << 8) | (color3 >>> 24);
color4 = (color4 << 8) | (color4 >>> 24);
color5 = (color5 << 8) | (color5 >>> 24);
color6 = (color6 << 8) | (color6 >>> 24);
for(int z = 0; z < 4; z++) {
color[z] = (byte)((color1 >> ((3 - z) * 8)) & 0xff);
color[z+4] = (byte)((color2 >> ((3 - z) * 8)) & 0xff);

View file

@ -17,6 +17,8 @@ public class GuiGraphics extends GuiOptions {
this.addSelector("crosshair_color_notarget", 0, 80, 240, 0);
this.addSelector("crosshair_color_target", 242, 80, 240, 0);
this.addSelector("hud_margin", 0, 120, 240, 0);
super.init(width, height);
}

View file

@ -102,9 +102,9 @@ public abstract class Window {
img.width(w);
img.height(h);
// java.nio.ByteBuffer pbuf = ;
img.pixels(BufferUtils.createByteBuffer(icon.length).put(icon));
img.pixels(BufferUtils.createByteBuffer(icon.length).put(icon).rewind());
// img.pixels(icon.length / 4);
GLFWImage.Buffer buf = GLFWImage.create(1).put(img);
GLFWImage.Buffer buf = GLFWImage.create(1).put(img).rewind();
glfwSetWindowIcon(window, buf);
}
}