Skip to content

Commit c57b8ba

Browse files
committed
(armorhud) add option to hide the main hand item
1 parent e0ea99d commit c57b8ba

File tree

12 files changed

+306
-67
lines changed

12 files changed

+306
-67
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/AxolotlClient.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void onInitializeClient() {
123123

124124
io.github.axolotlclient.AxolotlClientConfig.api.AxolotlClientConfig.getInstance()
125125
.register(configManager = new VersionedJsonConfigManager(AxolotlClientCommon.getInstance().getMainConfigFile(),
126-
CONFIG.config, 2, (oldVersion, newVersion, config, json) -> {
126+
CONFIG.config, 3, (oldVersion, newVersion, config, json) -> {
127127
if (oldVersion.getMajor() == 1) {
128128
var keystrokes = json.get("hud").getAsJsonObject().get("keystrokehud")
129129
.getAsJsonObject();
@@ -133,6 +133,15 @@ public void onInitializeClient() {
133133
mousemovement.addProperty("mouseMovementIndicatorOuter", keystrokes.get("mouseMovementIndicatorOuter").getAsString());
134134
json.get("hud").getAsJsonObject().add("mousemovementhud", mousemovement);
135135
}
136+
if (oldVersion.getMajor() == 2) {
137+
var armorhud = json.get("hud").getAsJsonObject().get("armorhud").getAsJsonObject();
138+
if (armorhud.has("armorhud.main_hand_item_top")) {
139+
var mainItemTop = armorhud.get("armorhud.main_hand_item_top").getAsBoolean();
140+
if (mainItemTop) {
141+
armorhud.addProperty("armorhud.main_hand_item_position", "armorhud.main_hand_item_position.top");
142+
}
143+
}
144+
}
136145
return json;
137146
}));
138147
configManager.load();

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

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.util.Arrays;
2626
import java.util.List;
27+
import java.util.Locale;
2728
import java.util.stream.Stream;
2829

2930
import io.github.axolotlclient.AxolotlClientConfig.api.options.Option;
@@ -63,7 +64,7 @@ public class ArmorHud extends TextHudEntry implements DynamicallyPositionable {
6364
private final BooleanOption showMaxDurabilityNumber = new BooleanOption("show_max_durability_num", false);
6465
private final BooleanOption customDurabilityNumColor = new BooleanOption("armorhud.custom_durability_num_color", false);
6566
private final ColorOption durabilityNumColor = new ColorOption("armorhud.durability_num_color", Colors.WHITE);
66-
private final BooleanOption mainHandItemOnTop = new BooleanOption("armorhud.main_hand_item_top", false);
67+
private final EnumOption<MainHandItemPosition> mainHandItemPosition = new EnumOption<>("armorhud.main_hand_item_position", MainHandItemPosition.class, MainHandItemPosition.BOTTOM);
6768

6869
private final EnumOption<AnchorPoint> anchor = new EnumOption<>("anchorpoint", AnchorPoint.class,
6970
AnchorPoint.TOP_RIGHT);
@@ -75,6 +76,8 @@ public ArmorHud() {
7576
@Override
7677
public void renderComponent(MatrixStack matrices, float delta) {
7778
int width = 20;
79+
int height = 100;
80+
boolean boundsChanged = false;
7881
boolean showDurability = showDurabilityNumber.get();
7982
boolean showMaxDurability = showMaxDurabilityNumber.get();
8083
int labelWidth = showDurability || showMaxDurability ? Stream.concat(Stream.of(client.player.inventory.getMainHandStack()), client.player.inventory.armor.stream())
@@ -83,12 +86,22 @@ public void renderComponent(MatrixStack matrices, float delta) {
8386
width += labelWidth;
8487
if (width != getWidth()) {
8588
setWidth(width);
86-
onBoundsUpdate();
89+
boundsChanged = true;
8790
}
8891
DrawPosition pos = getPos();
89-
int lastY = 2 + (4 * 20);
90-
boolean mainHandItemTop = mainHandItemOnTop.get();
91-
if (!mainHandItemTop) {
92+
MainHandItemPosition mainHandItemTop = mainHandItemPosition.get();
93+
if (mainHandItemTop == MainHandItemPosition.DISABLED) {
94+
height -= 20;
95+
}
96+
if (height != getHeight()) {
97+
setHeight(height);
98+
boundsChanged = true;
99+
}
100+
if (boundsChanged) {
101+
onBoundsUpdate();
102+
}
103+
int lastY = 2 + (height-20);
104+
if (mainHandItemTop == MainHandItemPosition.BOTTOM) {
92105
renderMainItem(matrices, client.player.inventory.getMainHandStack(), pos.x() + 2, pos.y() + lastY, labelWidth);
93106
lastY = lastY - 20;
94107
}
@@ -109,7 +122,7 @@ public void renderComponent(MatrixStack matrices, float delta) {
109122
renderItem(matrices, stack, pos.x() + 2, lastY + pos.y(), labelWidth);
110123
lastY = lastY - 20;
111124
}
112-
if (mainHandItemTop) {
125+
if (mainHandItemTop == MainHandItemPosition.TOP) {
113126
renderMainItem(matrices, client.player.inventory.getMainHandStack(), pos.x() + 2, pos.y() + lastY, labelWidth);
114127
}
115128
}
@@ -158,6 +171,8 @@ private void renderDurabilityNumber(MatrixStack graphics, ItemStack stack, int x
158171
@Override
159172
public void renderPlaceholderComponent(MatrixStack matrices, float delta) {
160173
int width = 20;
174+
int height = 100;
175+
boolean boundsChanged = false;
161176
boolean showDurability = showDurabilityNumber.get();
162177
boolean showMaxDurability = showMaxDurabilityNumber.get();
163178
int labelWidth = showDurability || showMaxDurability ? Arrays.stream(placeholderStacks)
@@ -166,12 +181,22 @@ public void renderPlaceholderComponent(MatrixStack matrices, float delta) {
166181
width += labelWidth;
167182
if (width != getWidth()) {
168183
setWidth(width);
169-
onBoundsUpdate();
184+
boundsChanged = true;
170185
}
171186
DrawPosition pos = getPos();
172-
int lastY = 2 + (4 * 20);
173-
boolean mainHandItemTop = mainHandItemOnTop.get();
174-
if (!mainHandItemTop) {
187+
MainHandItemPosition mainHandItemTop = mainHandItemPosition.get();
188+
if (mainHandItemTop == MainHandItemPosition.DISABLED) {
189+
height -= 20;
190+
}
191+
if (height != getHeight()) {
192+
setHeight(height);
193+
boundsChanged = true;
194+
}
195+
if (boundsChanged) {
196+
onBoundsUpdate();
197+
}
198+
int lastY = 2 + (height-20);
199+
if (mainHandItemTop == MainHandItemPosition.BOTTOM) {
175200
renderItem(matrices, placeholderStacks[4], pos.x() + 2, pos.y() + lastY, labelWidth);
176201
lastY = lastY - 20;
177202
}
@@ -180,7 +205,7 @@ public void renderPlaceholderComponent(MatrixStack matrices, float delta) {
180205
renderItem(matrices, item, pos.x() + 2, lastY + pos.y(), labelWidth);
181206
lastY = lastY - 20;
182207
}
183-
if (mainHandItemTop) {
208+
if (mainHandItemTop == MainHandItemPosition.TOP) {
184209
renderItem(matrices, placeholderStacks[4], pos.x() + 2, pos.y() + lastY, labelWidth);
185210
}
186211
}
@@ -199,11 +224,23 @@ public List<Option<?>> getConfigurationOptions() {
199224
options.add(customDurabilityNumColor);
200225
options.add(durabilityNumColor);
201226
options.add(anchor);
202-
options.add(mainHandItemOnTop);
227+
options.add(mainHandItemPosition);
203228
return options;
204229
}
205230

206231
public AnchorPoint getAnchor() {
207232
return anchor.get();
208233
}
234+
235+
private enum MainHandItemPosition {
236+
BOTTOM,
237+
TOP,
238+
DISABLED,
239+
;
240+
241+
@Override
242+
public String toString() {
243+
return "armorhud.main_hand_item_position."+super.toString().toLowerCase(Locale.ROOT);
244+
}
245+
}
209246
}

1.20/src/main/java/io/github/axolotlclient/AxolotlClient.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void onInitializeClient() {
126126

127127
io.github.axolotlclient.AxolotlClientConfig.api.AxolotlClientConfig.getInstance()
128128
.register(configManager = new VersionedJsonConfigManager(AxolotlClientCommon.getInstance().getMainConfigFile(),
129-
CONFIG.getConfig(), 2, (oldVersion, newVersion, config, json) -> {
129+
CONFIG.getConfig(), 3, (oldVersion, newVersion, config, json) -> {
130130
if (oldVersion.getMajor() == 1) {
131131
var keystrokes = json.get("hud").getAsJsonObject().get("keystrokehud")
132132
.getAsJsonObject();
@@ -136,6 +136,15 @@ public void onInitializeClient() {
136136
mousemovement.addProperty("mouseMovementIndicatorOuter", keystrokes.get("mouseMovementIndicatorOuter").getAsString());
137137
json.get("hud").getAsJsonObject().add("mousemovementhud", mousemovement);
138138
}
139+
if (oldVersion.getMajor() == 2) {
140+
var armorhud = json.get("hud").getAsJsonObject().get("armorhud").getAsJsonObject();
141+
if (armorhud.has("armorhud.main_hand_item_top")) {
142+
var mainItemTop = armorhud.get("armorhud.main_hand_item_top").getAsBoolean();
143+
if (mainItemTop) {
144+
armorhud.addProperty("armorhud.main_hand_item_position", "armorhud.main_hand_item_position.top");
145+
}
146+
}
147+
}
139148
return json;
140149
}));
141150
configManager.load();

1.20/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/item/ArmorHud.java

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.util.Arrays;
2626
import java.util.List;
27+
import java.util.Locale;
2728
import java.util.stream.Stream;
2829

2930
import io.github.axolotlclient.AxolotlClientConfig.api.options.Option;
@@ -62,7 +63,7 @@ public class ArmorHud extends TextHudEntry implements DynamicallyPositionable {
6263
private final BooleanOption showMaxDurabilityNumber = new BooleanOption("show_max_durability_num", false);
6364
private final BooleanOption customDurabilityNumColor = new BooleanOption("armorhud.custom_durability_num_color", false);
6465
private final ColorOption durabilityNumColor = new ColorOption("armorhud.durability_num_color", Colors.WHITE);
65-
private final BooleanOption mainHandItemOnTop = new BooleanOption("armorhud.main_hand_item_top", false);
66+
private final EnumOption<MainHandItemPosition> mainHandItemPosition = new EnumOption<>("armorhud.main_hand_item_position", MainHandItemPosition.class, MainHandItemPosition.BOTTOM);
6667

6768
private final EnumOption<AnchorPoint> anchor = new EnumOption<>("anchorpoint", AnchorPoint.class,
6869
AnchorPoint.TOP_RIGHT);
@@ -74,6 +75,8 @@ public ArmorHud() {
7475
@Override
7576
public void renderComponent(GuiGraphics graphics, float delta) {
7677
int width = 20;
78+
int height = 100;
79+
boolean boundsChanged = false;
7780
boolean showDurability = showDurabilityNumber.get();
7881
boolean showMaxDurability = showMaxDurabilityNumber.get();
7982
int labelWidth = showDurability || showMaxDurability ? Stream.concat(Stream.of(client.player.getInventory().getMainHandStack()), client.player.getInventory().armor.stream())
@@ -82,12 +85,22 @@ public void renderComponent(GuiGraphics graphics, float delta) {
8285
width += labelWidth;
8386
if (width != getWidth()) {
8487
setWidth(width);
85-
onBoundsUpdate();
88+
boundsChanged = true;
8689
}
8790
DrawPosition pos = getPos();
88-
int lastY = 2 + (4 * 20);
89-
boolean mainHandItemTop = mainHandItemOnTop.get();
90-
if (!mainHandItemTop) {
91+
MainHandItemPosition mainHandItemTop = mainHandItemPosition.get();
92+
if (mainHandItemTop == MainHandItemPosition.DISABLED) {
93+
height -= 20;
94+
}
95+
if (height != getHeight()) {
96+
setHeight(height);
97+
boundsChanged = true;
98+
}
99+
if (boundsChanged) {
100+
onBoundsUpdate();
101+
}
102+
int lastY = 2 + (height-20);
103+
if (mainHandItemTop == MainHandItemPosition.BOTTOM) {
91104
renderMainItem(graphics, client.player.getInventory().getMainHandStack(), pos.x() + 2, pos.y() + lastY, labelWidth);
92105
lastY = lastY - 20;
93106
}
@@ -108,7 +121,7 @@ public void renderComponent(GuiGraphics graphics, float delta) {
108121
renderItem(graphics, stack, pos.x() + 2, lastY + pos.y(), labelWidth);
109122
lastY = lastY - 20;
110123
}
111-
if (mainHandItemTop) {
124+
if (mainHandItemTop == MainHandItemPosition.TOP) {
112125
renderMainItem(graphics, client.player.getInventory().getMainHandStack(), pos.x() + 2, pos.y() + lastY, labelWidth);
113126
}
114127
}
@@ -145,6 +158,8 @@ private void renderDurabilityNumber(GuiGraphics graphics, ItemStack stack, int x
145158
@Override
146159
public void renderPlaceholderComponent(GuiGraphics graphics, float delta) {
147160
int width = 20;
161+
int height = 100;
162+
boolean boundsChanged = false;
148163
boolean showDurability = showDurabilityNumber.get();
149164
boolean showMaxDurability = showMaxDurabilityNumber.get();
150165
int labelWidth = showDurability || showMaxDurability ? Arrays.stream(placeholderStacks)
@@ -153,12 +168,22 @@ public void renderPlaceholderComponent(GuiGraphics graphics, float delta) {
153168
width += labelWidth;
154169
if (width != getWidth()) {
155170
setWidth(width);
156-
onBoundsUpdate();
171+
boundsChanged = true;
157172
}
158173
DrawPosition pos = getPos();
159-
int lastY = 2 + (4 * 20);
160-
boolean mainHandItemTop = mainHandItemOnTop.get();
161-
if (!mainHandItemTop) {
174+
MainHandItemPosition mainHandItemTop = mainHandItemPosition.get();
175+
if (mainHandItemTop == MainHandItemPosition.DISABLED) {
176+
height -= 20;
177+
}
178+
if (height != getHeight()) {
179+
setHeight(height);
180+
boundsChanged = true;
181+
}
182+
if (boundsChanged) {
183+
onBoundsUpdate();
184+
}
185+
int lastY = 2 + (height-20);
186+
if (mainHandItemTop == MainHandItemPosition.BOTTOM) {
162187
renderItem(graphics, placeholderStacks[4], pos.x() + 2, pos.y() + lastY, labelWidth);
163188
lastY = lastY - 20;
164189
}
@@ -167,7 +192,7 @@ public void renderPlaceholderComponent(GuiGraphics graphics, float delta) {
167192
renderItem(graphics, item, pos.x() + 2, lastY + pos.y(), labelWidth);
168193
lastY = lastY - 20;
169194
}
170-
if (mainHandItemTop) {
195+
if (mainHandItemTop == MainHandItemPosition.TOP) {
171196
renderItem(graphics, placeholderStacks[4], pos.x() + 2, pos.y() + lastY, labelWidth);
172197
}
173198
}
@@ -186,11 +211,23 @@ public List<Option<?>> getConfigurationOptions() {
186211
options.add(customDurabilityNumColor);
187212
options.add(durabilityNumColor);
188213
options.add(anchor);
189-
options.add(mainHandItemOnTop);
214+
options.add(mainHandItemPosition);
190215
return options;
191216
}
192217

193218
public AnchorPoint getAnchor() {
194219
return anchor.get();
195220
}
221+
222+
private enum MainHandItemPosition {
223+
BOTTOM,
224+
TOP,
225+
DISABLED,
226+
;
227+
228+
@Override
229+
public String toString() {
230+
return "armorhud.main_hand_item_position."+super.toString().toLowerCase(Locale.ROOT);
231+
}
232+
}
196233
}

1.21.5/src/main/java/io/github/axolotlclient/AxolotlClient.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void onInitializeClient() {
122122

123123
io.github.axolotlclient.AxolotlClientConfig.api.AxolotlClientConfig.getInstance().register(configManager =
124124
new VersionedJsonConfigManager(AxolotlClientCommon.getInstance().getMainConfigFile(),
125-
CONFIG.getConfig(), 2, (oldVersion, newVersion, config, json) -> {
125+
CONFIG.getConfig(), 3, (oldVersion, newVersion, config, json) -> {
126126
if (oldVersion.getMajor() == 1) {
127127
var keystrokes = json.get("hud").getAsJsonObject().get("keystrokehud")
128128
.getAsJsonObject();
@@ -132,6 +132,15 @@ public void onInitializeClient() {
132132
mousemovement.addProperty("mouseMovementIndicatorOuter", keystrokes.get("mouseMovementIndicatorOuter").getAsString());
133133
json.get("hud").getAsJsonObject().add("mousemovementhud", mousemovement);
134134
}
135+
if (oldVersion.getMajor() == 2) {
136+
var armorhud = json.get("hud").getAsJsonObject().get("armorhud").getAsJsonObject();
137+
if (armorhud.has("armorhud.main_hand_item_top")) {
138+
var mainItemTop = armorhud.get("armorhud.main_hand_item_top").getAsBoolean();
139+
if (mainItemTop) {
140+
armorhud.addProperty("armorhud.main_hand_item_position", "armorhud.main_hand_item_position.top");
141+
}
142+
}
143+
}
135144
return json;
136145
}
137146
));

0 commit comments

Comments
 (0)