Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit b62f827

Browse files
committed
add options to display durability on the ArmorHud
1 parent 0147fcd commit b62f827

File tree

23 files changed

+706
-186
lines changed

23 files changed

+706
-186
lines changed

1.16_combat-6/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dependencies {
5454
implementation(include("org.slf4j:slf4j-api:1.7.36")!!)
5555
localRuntime("org.slf4j:slf4j-jdk14:1.7.36")
5656

57-
api("org.lwjgl:lwjgl-nanovg:3.3.2")
57+
api("org.lwjgl:lwjgl-nanovg:3.2.2")
5858
runtimeOnly("org.lwjgl:lwjgl-nanovg:3.2.2:natives-linux")
5959
runtimeOnly("org.lwjgl:lwjgl-nanovg:3.2.2:natives-windows")
6060
runtimeOnly("org.lwjgl:lwjgl-nanovg:3.2.2:natives-macos")
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright © 2024 moehreag <[email protected]> & Contributors
3+
*
4+
* This file is part of AxolotlClient.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*
20+
* For more information, see the LICENSE file.
21+
*/
22+
23+
package io.github.axolotlclient.mixin;
24+
25+
import io.github.axolotlclient.AxolotlClientConfig.impl.ui.vanilla.widgets.VanillaButtonWidget;
26+
import io.github.axolotlclient.modules.hud.util.DrawUtil;
27+
import io.github.axolotlclient.util.ButtonWidgetTextures;
28+
import net.minecraft.client.MinecraftClient;
29+
import net.minecraft.client.font.TextRenderer;
30+
import net.minecraft.client.gui.widget.AbstractButtonWidget;
31+
import net.minecraft.client.gui.widget.ButtonWidget;
32+
import net.minecraft.client.util.math.MatrixStack;
33+
import net.minecraft.text.Text;
34+
import net.minecraft.util.Identifier;
35+
import org.spongepowered.asm.mixin.Mixin;
36+
import org.spongepowered.asm.mixin.Shadow;
37+
import org.spongepowered.asm.mixin.injection.At;
38+
import org.spongepowered.asm.mixin.injection.Inject;
39+
import org.spongepowered.asm.mixin.injection.Redirect;
40+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
41+
42+
public abstract class ButtonWidgetMixin {
43+
@Mixin(AbstractButtonWidget.class)
44+
private abstract static class Game {
45+
@Shadow
46+
public int x;
47+
48+
@Shadow
49+
public int y;
50+
51+
@Shadow
52+
protected int width;
53+
54+
@Shadow
55+
protected int height;
56+
57+
@Shadow
58+
protected boolean hovered;
59+
60+
@Shadow
61+
protected abstract int getYImage(boolean hovered);
62+
63+
@Redirect(method = "renderButton", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/AbstractButtonWidget;drawCenteredText(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)V"))
64+
private void drawScrollableString(MatrixStack matrixStack, TextRenderer textRenderer, Text text, int centerX, int y_original, int color) {
65+
int left = x + 2;
66+
int right = x + width - 1 - 2;
67+
DrawUtil.drawScrollableText(matrixStack, MinecraftClient.getInstance().textRenderer, text, left, y, right, y + height, color);
68+
}
69+
70+
@Redirect(method = "renderButton", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/AbstractButtonWidget;drawTexture(Lnet/minecraft/client/util/math/MatrixStack;IIIIII)V"))
71+
private void remove2Slice(AbstractButtonWidget instance, MatrixStack stack, int x, int y, int u, int v, int width, int height) {
72+
73+
}
74+
75+
@Inject(method = "renderButton", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/AbstractButtonWidget;renderBg(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/MinecraftClient;II)V"))
76+
private void addSlices(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
77+
Identifier tex = ButtonWidgetTextures.get(getYImage(hovered));
78+
DrawUtil.blitSprite(tex, x, y, width, height, new DrawUtil.NineSlice(200, 20, 3));
79+
}
80+
}
81+
82+
// Ignoring the mixin warning that it can't resolve the superclass, it works and is correct
83+
@Mixin(value = VanillaButtonWidget.class, remap = false)
84+
private static abstract class Config extends ButtonWidget {
85+
private Config(int x, int y, int width, int height, Text message, PressAction onPress, TooltipSupplier tooltipSupplier) {
86+
super(x, y, width, height, message, onPress, tooltipSupplier);
87+
throw new UnsupportedOperationException("Mixin failure");
88+
}
89+
90+
@Shadow
91+
public abstract int getX();
92+
93+
@Shadow
94+
public abstract int getY();
95+
96+
@Redirect(method = "renderButton", at = @At(value = "INVOKE", target = "Lio/github/axolotlclient/AxolotlClientConfig/impl/ui/vanilla/widgets/VanillaButtonWidget;drawTexture(Lnet/minecraft/client/util/math/MatrixStack;IIIIII)V"))
97+
private void remove2Slice(VanillaButtonWidget instance, MatrixStack stack, int x, int y, int u, int v, int width, int height) {
98+
99+
}
100+
101+
@Inject(method = "renderButton", at = @At(value = "INVOKE", target = "Lio/github/axolotlclient/AxolotlClientConfig/impl/ui/vanilla/widgets/VanillaButtonWidget;drawScrollableText(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/font/TextRenderer;I)V"))
102+
private void addSlices(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
103+
Identifier tex = ButtonWidgetTextures.get(!active ? 0 : (hovered ? 2 : 1));
104+
DrawUtil.blitSprite(tex, getX(), getY(), getWidth() , getHeight(), new DrawUtil.NineSlice(200, 20, 3));
105+
}
106+
}
107+
}

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/entry/SimpleTextHudEntry.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
import com.mojang.blaze3d.systems.RenderSystem;
2929
import io.github.axolotlclient.AxolotlClientConfig.api.options.Option;
3030
import io.github.axolotlclient.AxolotlClientConfig.api.util.Color;
31+
import io.github.axolotlclient.AxolotlClientConfig.impl.options.BooleanOption;
3132
import io.github.axolotlclient.AxolotlClientConfig.impl.options.EnumOption;
3233
import io.github.axolotlclient.AxolotlClientConfig.impl.options.IntegerOption;
3334
import io.github.axolotlclient.modules.hud.gui.component.DynamicallyPositionable;
3435
import io.github.axolotlclient.modules.hud.gui.layout.AnchorPoint;
3536
import io.github.axolotlclient.modules.hud.gui.layout.Justification;
3637
import io.github.axolotlclient.modules.hud.util.DefaultOptions;
3738
import io.github.axolotlclient.modules.hud.util.DrawPosition;
39+
import net.minecraft.client.resource.language.I18n;
3840
import net.minecraft.client.util.math.MatrixStack;
3941

4042
/**
@@ -49,6 +51,7 @@ public abstract class SimpleTextHudEntry extends TextHudEntry implements Dynamic
4951
protected final EnumOption<Justification> justification = new EnumOption<>("justification", Justification.class,
5052
Justification.CENTER);
5153
protected final EnumOption<AnchorPoint> anchor = DefaultOptions.getAnchorPoint();
54+
protected final BooleanOption showBrackets = new BooleanOption("show_brackets", false);
5255

5356
private final IntegerOption minWidth;
5457

@@ -73,7 +76,7 @@ public void renderComponent(MatrixStack matrices, float delta) {
7376
GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
7477
RenderSystem.disableTexture();
7578
DrawPosition pos = getPos();
76-
String value = getValue();
79+
String value = wrapWithBrackets(getValue());
7780

7881
int valueWidth = client.textRenderer.getWidth(value);
7982
int elementWidth = valueWidth + 4;
@@ -98,15 +101,17 @@ public void renderComponent(MatrixStack matrices, float delta) {
98101
@Override
99102
public void renderPlaceholderComponent(MatrixStack matrices, float delta) {
100103
DrawPosition pos = getPos();
101-
String value = getPlaceholder();
104+
String value = wrapWithBrackets(getPlaceholder());
102105
drawString(matrices, value,
103106
pos.x() + justification.get().getXOffset(value, getWidth() - 4) + 2,
104107
pos.y() + (Math.round((float) getHeight() / 2)) - 4, textColor.get().toInt(), shadow.get());
105108
}
106109

107-
@Override
108-
public boolean movable() {
109-
return true;
110+
protected String wrapWithBrackets(String value) {
111+
if (showBrackets.get()) {
112+
return I18n.translate("bracket_format", value);
113+
}
114+
return value;
110115
}
111116

112117
public abstract String getPlaceholder();
@@ -123,6 +128,7 @@ public List<Option<?>> getConfigurationOptions() {
123128
options.add(justification);
124129
options.add(anchor);
125130
options.add(minWidth);
131+
options.add(showBrackets);
126132
return options;
127133
}
128134

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/item/ArmorHud.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import net.minecraft.item.Items;
3636
import net.minecraft.nbt.ListTag;
3737
import net.minecraft.util.Identifier;
38+
import net.minecraft.util.math.MathHelper;
3839

3940
/**
4041
* This implementation of Hud modules is based on KronHUD.
@@ -51,13 +52,23 @@ public class ArmorHud extends TextHudEntry {
5152
private final ItemStack[] placeholderStacks = new ItemStack[]{new ItemStack(Items.IRON_BOOTS),
5253
new ItemStack(Items.IRON_LEGGINGS), new ItemStack(Items.IRON_CHESTPLATE), new ItemStack(Items.IRON_HELMET),
5354
new ItemStack(Items.IRON_SWORD)};
55+
private final BooleanOption showDurabilityNumber = new BooleanOption("show_durability_num", false);
56+
private final BooleanOption showMaxDurabilityNumber = new BooleanOption("show_max_durability_num", false);
5457

5558
public ArmorHud() {
5659
super(20, 100, true);
5760
}
5861

5962
@Override
6063
public void renderComponent(MatrixStack matrices, float delta) {
64+
int width = 20;
65+
if (showDurabilityNumber.get()) {
66+
width += 15;
67+
}
68+
if (showMaxDurabilityNumber.get()) {
69+
width += 15;
70+
}
71+
setWidth(width);
6172
DrawPosition pos = getPos();
6273
int lastY = 2 + (4 * 20);
6374
renderMainItem(matrices, client.player.inventory.getMainHandStack(), pos.x() + 2, pos.y() + lastY);
@@ -89,12 +100,30 @@ public void renderMainItem(MatrixStack matrices, ItemStack stack, int x, int y)
89100
}
90101
ItemUtil.renderGuiItemOverlay(matrices, client.textRenderer, stack, x, y, total, textColor.get().toInt(),
91102
shadow.get());
103+
renderDurabilityNumber(matrices, stack, x, y);
92104
}
93105

94106
public void renderItem(MatrixStack matrices, ItemStack stack, int x, int y) {
95107
ItemUtil.renderGuiItemModel(getScale(), stack, x, y);
96108
ItemUtil.renderGuiItemOverlay(matrices, client.textRenderer, stack, x, y, null, textColor.get().toInt(),
97109
shadow.get());
110+
renderDurabilityNumber(matrices, stack, x, y);
111+
}
112+
113+
private void renderDurabilityNumber(MatrixStack graphics, ItemStack stack, int x, int y) {
114+
boolean showDurability = showDurabilityNumber.get();
115+
boolean showMaxDurability = showMaxDurabilityNumber.get();
116+
if (!(showMaxDurability || showDurability)) {
117+
return;
118+
}
119+
String text = showDurability && showMaxDurability ? (stack.getMaxDamage() - stack.getDamage())+"/"+stack.getMaxDamage() : String.valueOf((showDurability ? stack.getMaxDamage() - stack.getDamage() : stack.getMaxDamage()));
120+
int textX = x - client.textRenderer.getWidth(text) - 2;
121+
int textY = y + 10 - client.textRenderer.fontHeight/2;
122+
float f = (float) stack.getDamage();
123+
float g = (float) stack.getMaxDamage();
124+
float h = Math.max(0.0F, (g - f) / g);
125+
int j = MathHelper.hsvToRgb(h / 3.0F, 1.0F, 1.0F);
126+
drawStringWithShadow(graphics, client.textRenderer, text, textX, textY, (((255 << 8) + (j >> 16 & 255) << 8) + (j >> 8 & 255) << 8) + (j & 255));
98127
}
99128

100129
@Override
@@ -110,11 +139,6 @@ public void renderPlaceholderComponent(MatrixStack matrices, float delta) {
110139
}
111140
}
112141

113-
@Override
114-
public boolean movable() {
115-
return true;
116-
}
117-
118142
@Override
119143
public Identifier getId() {
120144
return ID;
@@ -124,6 +148,8 @@ public Identifier getId() {
124148
public List<Option<?>> getConfigurationOptions() {
125149
List<Option<?>> options = super.getConfigurationOptions();
126150
options.add(showProtLvl);
151+
options.add(showDurabilityNumber);
152+
options.add(showMaxDurabilityNumber);
127153
return options;
128154
}
129155
}

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/util/DrawUtil.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,18 @@ public record Tile(int width, int height) implements GuiSpriteScaling{
138138

139139
}
140140
public record NineSlice(int width, int height, Border border, boolean stretchInner) implements GuiSpriteScaling {
141+
public NineSlice(int width, int height, Border border) {
142+
this(width, height, border, false);
143+
}
144+
public NineSlice(int width, int height, int borderSize) {
145+
this(width, height, new Border(borderSize));
146+
}
147+
}
148+
public record Border(int left, int right, int top, int bottom){
149+
public Border(int size) {
150+
this(size, size, size, size);
151+
}
141152
}
142-
public record Border(int left, int right, int top, int bottom){}
143153

144154
public static void blitSprite(Identifier texture, int i, int j, int k, int l, GuiSpriteScaling guiSpriteScaling) {
145155
blitSprite(texture, i, j, k, l, -1, guiSpriteScaling);

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/util/ItemUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import com.mojang.blaze3d.platform.GlStateManager;
3030
import com.mojang.blaze3d.systems.RenderSystem;
31-
import io.github.axolotlclient.AxolotlClientConfig.api.util.Color;
3231
import io.github.axolotlclient.util.ClientColors;
3332
import lombok.experimental.UtilityClass;
3433
import net.minecraft.client.MinecraftClient;
@@ -223,7 +222,7 @@ public static void renderGuiItemOverlay(MatrixStack matrices, TextRenderer rende
223222
int j = MathHelper.hsvToRgb(h / 3.0F, 1.0F, 1.0F);
224223
DrawUtil.fillRect(matrices, x + 2, y + 13, 13, 2, ClientColors.BLACK.toInt());
225224
DrawUtil.fillRect(matrices, x + 2, y + 13, i, 1,
226-
new Color(j >> 16 & 255, j >> 8 & 255, j & 255, 255).toInt());
225+
(((255 << 8) + (j >> 16 & 255) << 8) + (j >> 8 & 255) << 8) + (j & 255));
227226
RenderSystem.enableBlend();
228227
RenderSystem.enableTexture();
229228
RenderSystem.enableDepthTest();

0 commit comments

Comments
 (0)