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

Commit 7e34971

Browse files
committed
some hud tweaks, custom text huds...
1 parent d307c29 commit 7e34971

File tree

19 files changed

+649
-94
lines changed

19 files changed

+649
-94
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import com.google.common.collect.Lists;
2929
import com.mojang.blaze3d.systems.RenderSystem;
3030
import io.github.axolotlclient.AxolotlClientConfig.api.options.Option;
31+
import io.github.axolotlclient.AxolotlClientConfig.api.util.Color;
3132
import io.github.axolotlclient.AxolotlClientConfig.impl.options.BooleanOption;
33+
import io.github.axolotlclient.AxolotlClientConfig.impl.options.ColorOption;
3234
import io.github.axolotlclient.AxolotlClientConfig.impl.options.EnumOption;
3335
import io.github.axolotlclient.modules.hud.gui.component.DynamicallyPositionable;
3436
import io.github.axolotlclient.modules.hud.gui.entry.TextHudEntry;
@@ -66,6 +68,7 @@ public class PotionsHud extends TextHudEntry implements DynamicallyPositionable
6668

6769
private final BooleanOption iconsOnly = new BooleanOption("iconsonly", false);
6870
private final BooleanOption showEffectName = new BooleanOption("showEffectNames", true);
71+
private final ColorOption timerTextColor = new ColorOption("potionshud.timer_text_color", Color.parse("#7F7F7F"));
6972

7073
public PotionsHud() {
7174
super(50, 200, false);
@@ -157,12 +160,12 @@ private void renderPotion(MatrixStack matrices, StatusEffectInstance effect, int
157160
if (showEffectName.get()) {
158161
Text string = new TranslatableText(effect.getTranslationKey()).append(" ").append(Util.toRoman(effect.getAmplifier()));
159162

160-
drawText(matrices, string, (float) (x + 19), (float) (y + 1), 16777215, shadow.get());
163+
drawText(matrices, string, (float) (x + 19), (float) (y + 1), textColor.get().toInt(), shadow.get());
161164
String duration = StatusEffectUtil.durationToString(effect, 1);
162-
drawString(matrices, duration, (float) (x + 19), (float) (y + 1 + 10), textColor.get().toInt(), shadow.get());
165+
drawString(matrices, duration, (float) (x + 19), (float) (y + 1 + 10), timerTextColor.get().toInt(), shadow.get());
163166
} else {
164167
drawString(matrices, StatusEffectUtil.durationToString(effect, 1), x + 19, y + 5,
165-
textColor.get().toInt(), shadow.get());
168+
timerTextColor.get().toInt(), shadow.get());
166169
}
167170
}
168171
}
@@ -181,6 +184,8 @@ public List<Option<?>> getConfigurationOptions() {
181184
options.add(anchor);
182185
options.add(order);
183186
options.add(iconsOnly);
187+
options.add(showEffectName);
188+
options.add(timerTextColor);
184189
return options;
185190
}
186191

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727

2828
import com.mojang.blaze3d.systems.RenderSystem;
2929
import io.github.axolotlclient.AxolotlClientConfig.api.options.Option;
30+
import io.github.axolotlclient.AxolotlClientConfig.api.util.Color;
3031
import io.github.axolotlclient.AxolotlClientConfig.impl.options.BooleanOption;
32+
import io.github.axolotlclient.AxolotlClientConfig.impl.options.ColorOption;
3133
import io.github.axolotlclient.AxolotlClientConfig.impl.options.EnumOption;
3234
import io.github.axolotlclient.modules.hud.gui.component.DynamicallyPositionable;
3335
import io.github.axolotlclient.modules.hud.gui.entry.TextHudEntry;
@@ -62,6 +64,7 @@ public class PotionsHud extends TextHudEntry implements DynamicallyPositionable
6264

6365
private final BooleanOption iconsOnly = new BooleanOption("iconsonly", false);
6466
private final BooleanOption showEffectName = new BooleanOption("showEffectNames", true);
67+
private final ColorOption timerTextColor = new ColorOption("potionshud.timer_text_color", Color.parse("#7F7F7F"));
6568

6669
public PotionsHud() {
6770
super(50, 200, false);
@@ -155,10 +158,10 @@ private void renderPotion(GuiGraphics graphics, StatusEffectInstance effect, int
155158

156159
graphics.drawText(client.textRenderer, string, x + 19, y + 1, textColor.get().toInt(), shadow.get());
157160
Text duration = StatusEffectUtil.durationToString(effect, 1);
158-
graphics.drawText(client.textRenderer, duration, x + 19, y + 1 + 10, 8355711, shadow.get());
161+
graphics.drawText(client.textRenderer, duration, x + 19, y + 1 + 10, timerTextColor.get().toInt(), shadow.get());
159162
} else {
160163
graphics.drawText(client.textRenderer, StatusEffectUtil.durationToString(effect, 1), x + 19, y + 5,
161-
textColor.get().toInt(), shadow.get());
164+
timerTextColor.get().toInt(), shadow.get());
162165
}
163166
}
164167
}
@@ -177,6 +180,8 @@ public List<Option<?>> getConfigurationOptions() {
177180
options.add(anchor);
178181
options.add(order);
179182
options.add(iconsOnly);
183+
options.add(showEffectName);
184+
options.add(timerTextColor);
180185
return options;
181186
}
182187

1.21.4/src/main/java/io/github/axolotlclient/modules/hud/HudManager.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222

2323
package io.github.axolotlclient.modules.hud;
2424

25+
import java.io.IOException;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
2528
import java.util.*;
2629
import java.util.stream.Collectors;
2730

2831
import com.mojang.blaze3d.platform.InputConstants;
2932
import io.github.axolotlclient.AxolotlClient;
33+
import io.github.axolotlclient.AxolotlClientConfig.api.options.Option;
3034
import io.github.axolotlclient.AxolotlClientConfig.api.options.OptionCategory;
3135
import io.github.axolotlclient.modules.AbstractModule;
3236
import io.github.axolotlclient.modules.hud.gui.AbstractHudEntry;
@@ -42,7 +46,11 @@
4246
import io.github.axolotlclient.modules.hud.gui.hud.vanilla.ScoreboardHud;
4347
import io.github.axolotlclient.modules.hud.util.Rectangle;
4448
import io.github.axolotlclient.modules.hypixel.bedwars.BedwarsMod;
49+
import io.github.axolotlclient.util.GsonHelper;
4550
import io.github.axolotlclient.util.keybinds.KeyBinds;
51+
import io.github.axolotlclient.util.options.GenericOption;
52+
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
53+
import net.fabricmc.loader.api.FabricLoader;
4654
import net.minecraft.client.DeltaTracker;
4755
import net.minecraft.client.KeyMapping;
4856
import net.minecraft.client.Minecraft;
@@ -59,6 +67,7 @@
5967

6068
public class HudManager extends AbstractModule {
6169

70+
private final static Path CUSTOM_MODULE_SAVE_PATH = FabricLoader.getInstance().getConfigDir().resolve("axolotlclient").resolve("custom_hud.json");
6271
private final static HudManager INSTANCE = new HudManager();
6372
private final OptionCategory hudCategory = OptionCategory.create("hud");
6473
private final Map<ResourceLocation, HudEntry> entries;
@@ -107,12 +116,74 @@ public void init() {
107116
add(new PlayerHud());
108117
entries.put(BedwarsMod.getInstance().getUpgradesOverlay().getId(), BedwarsMod.getInstance().getUpgradesOverlay());
109118

119+
loadCustomEntries();
120+
110121
entries.values().forEach(HudEntry::init);
111122

112123
((ReachHud) get(ReachHud.ID)).getEnabled().setForceOff(true, "feature.broken");
113124
((ComboHud) get(ComboHud.ID)).getEnabled().setForceOff(true, "feature.broken");
114125

115126
refreshAllBounds();
127+
128+
hudCategory.add(new GenericOption("hud.custom_entry", "hud.custom_entry.add", () -> {
129+
CustomHudEntry entry = new CustomHudEntry();
130+
entry.setEnabled(true);
131+
entry.init();
132+
entry.onBoundsUpdate();
133+
entry.getAllOptions().includeInParentTree(false);
134+
add(entry);
135+
client.screen.resize(client, client.screen.width, client.screen.height);
136+
saveCustomEntries();
137+
}));
138+
ClientLifecycleEvents.CLIENT_STOPPING.register(client -> saveCustomEntries());
139+
}
140+
141+
@SuppressWarnings("unchecked")
142+
private void loadCustomEntries() {
143+
try {
144+
if (Files.exists(CUSTOM_MODULE_SAVE_PATH)) {
145+
var obj = (Map<String, Object>) GsonHelper.read(Files.readString(CUSTOM_MODULE_SAVE_PATH));
146+
obj.forEach((s, o) -> {
147+
CustomHudEntry entry = new CustomHudEntry();
148+
var values = (Map<String, Object>)o;
149+
entry.getAllOptions().getOptions().forEach(opt -> {
150+
if (values.containsKey(opt.getName())) {
151+
opt.fromSerializedValue((String) values.get(opt.getName()));
152+
}
153+
});
154+
entry.getCategory().includeInParentTree(false);
155+
add(entry);
156+
});
157+
}
158+
} catch (IOException e) {
159+
160+
}
161+
}
162+
163+
public void saveCustomEntries() {
164+
try {
165+
Files.createDirectories(CUSTOM_MODULE_SAVE_PATH.getParent());
166+
var writer = Files.newBufferedWriter(CUSTOM_MODULE_SAVE_PATH);
167+
var json = GsonHelper.GSON.newJsonWriter(writer);
168+
json.beginObject();
169+
for (Map.Entry<ResourceLocation, HudEntry> entry : entries.entrySet()) {
170+
ResourceLocation resourceLocation = entry.getKey();
171+
HudEntry hudEntry = entry.getValue();
172+
if (hudEntry instanceof CustomHudEntry hud) {
173+
json.name(resourceLocation.toString());
174+
json.beginObject();
175+
for (Option<?> opt : hud.getCategory().getOptions()) {
176+
json.name(opt.getName());
177+
json.value(opt.toSerializedValue());
178+
}
179+
json.endObject();
180+
}
181+
}
182+
json.endObject();
183+
json.close();
184+
} catch (IOException e) {
185+
186+
}
116187
}
117188

118189
public void tick() {
@@ -143,6 +214,10 @@ public HudEntry get(ResourceLocation identifier) {
143214
return entries.get(identifier);
144215
}
145216

217+
public void removeEntry(ResourceLocation identifier) {
218+
hudCategory.getSubCategories().remove(entries.remove(identifier).getCategory());
219+
}
220+
146221
public void render(GuiGraphics graphics, DeltaTracker delta) {
147222
Profiler.get().push("Hud Modules");
148223
if (!(client.screen instanceof HudEditScreen)) {

1.21.4/src/main/java/io/github/axolotlclient/modules/hud/gui/AbstractHudEntry.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public abstract class AbstractHudEntry extends DrawUtil implements HudEntry {
7373
public AbstractHudEntry(int width, int height) {
7474
this.width = width;
7575
this.height = height;
76+
truePosition = new DrawPosition(0, 0);
77+
renderPosition = new DrawPosition(0, 0);
78+
renderBounds = new Rectangle(0, 0, 1, 1);
79+
trueBounds = new Rectangle(0, 0, 1, 1);
7680
}
7781

7882
public static float intToFloat(int current, int max, int offset) {

1.21.4/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/KeystrokeHud.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
package io.github.axolotlclient.modules.hud.gui.hud;
2424

2525
import java.io.IOException;
26-
import java.util.ArrayList;
27-
import java.util.List;
28-
import java.util.Map;
29-
import java.util.Optional;
26+
import java.util.*;
3027

3128
import com.mojang.blaze3d.platform.InputConstants;
3229
import io.github.axolotlclient.AxolotlClientConfig.api.options.Option;
@@ -35,6 +32,7 @@
3532
import io.github.axolotlclient.AxolotlClientConfig.impl.options.ColorOption;
3633
import io.github.axolotlclient.AxolotlClientConfig.impl.options.GraphicsOption;
3734
import io.github.axolotlclient.modules.hud.gui.entry.TextHudEntry;
35+
import io.github.axolotlclient.modules.hud.gui.keystrokes.KeystrokeKeyScreen;
3836
import io.github.axolotlclient.modules.hud.util.DrawPosition;
3937
import io.github.axolotlclient.modules.hud.util.DrawUtil;
4038
import io.github.axolotlclient.modules.hud.util.Rectangle;
@@ -153,6 +151,7 @@ public void setKeystrokes() {
153151
}
154152
keystrokes = new ArrayList<>();
155153
setDefaultKeystrokes();
154+
keystrokesOption.load();
156155
KeyMapping.releaseAll();
157156
KeyMapping.setAll();
158157

@@ -279,6 +278,7 @@ public List<Option<?>> getConfigurationOptions() {
279278
options.add(outline);
280279
options.add(outlineColor);
281280
options.add(pressedOutlineColor);
281+
options.add(keystrokesOption);
282282
return options;
283283
}
284284

@@ -354,8 +354,10 @@ public Color getOutlineColor() {
354354
}
355355

356356
public Map<String, Object> serialize() {
357-
return Map.of("key", key.saveString(),
358-
"bounds", Map.of("x", bounds.x(), "y", bounds.y(), "width", bounds.width(), "height", bounds.height()));
357+
Map<String, Object> map = new HashMap<>();
358+
map.put("key", key.saveString());
359+
map.put("bounds", Map.of("x", bounds.x(), "y", bounds.y(), "width", bounds.width(), "height", bounds.height()));
360+
return map;
359361
}
360362
}
361363

@@ -376,7 +378,7 @@ private Keystroke deserializeKey(Map<String, ?> json) {
376378
}
377379

378380
private static Rectangle getRectangle(Map<String, ?> json) {
379-
return new Rectangle((int) json.get("x"), (int) json.get("y"), (int) json.get("width"), (int) json.get("height"));
381+
return new Rectangle((int)(long) json.get("x"), (int)(long) json.get("y"), (int)(long) json.get("width"), (int)(long) json.get("height"));
380382
}
381383

382384
public class KeyOptionKeystroke extends Keystroke {
@@ -406,6 +408,10 @@ public Map<String, Object> serialize() {
406408
}
407409
}
408410

411+
public CustomKeystroke newStroke() {
412+
return new CustomKeystroke(new Rectangle(0, 0, 0, 0), new DrawPosition(0, 0), null);
413+
}
414+
409415
public class CustomKeystroke extends Keystroke {
410416

411417
public CustomKeystroke(Rectangle bounds, DrawPosition offset, KeyMapping key) {
@@ -431,9 +437,10 @@ public Map<String, Object> serialize() {
431437

432438
public class KeystrokesGenericOption extends GenericOption {
433439

440+
private String serializedKeystrokes;
434441
public KeystrokesGenericOption(String name, String label) {
435442
super(name, label, () -> {
436-
443+
client.submit(() -> client.setScreen(new KeystrokeKeyScreen(KeystrokeHud.this, client.screen)));
437444
});
438445
}
439446

@@ -443,17 +450,30 @@ public String toSerializedValue() {
443450
}
444451

445452
@SuppressWarnings("unchecked")
446-
@Override
447-
public void fromSerializedValue(String s) {
453+
public void load() {
454+
if (serializedKeystrokes == null || serializedKeystrokes.isEmpty()) {
455+
return;
456+
}
448457
keystrokes.clear();
449458
try {
450-
List<?> entries = (List<?>) GsonHelper.read(s);
459+
List<?> entries = (List<?>) GsonHelper.read(serializedKeystrokes);
451460
entries.stream().map(e -> (Map<String, Object>) e)
452461
.map(KeystrokeHud.this::deserializeKey)
453462
.forEach(keystrokes::add);
454463
} catch (IOException e) {
455-
464+
e.printStackTrace();
456465
}
457466
}
467+
468+
@Override
469+
public void fromSerializedValue(String s) {
470+
serializedKeystrokes = s;
471+
472+
}
473+
474+
@Override
475+
public String getWidgetIdentifier() {
476+
return "generic-keystrokes";
477+
}
458478
}
459479
}

1.21.4/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/PotionsHud.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import java.util.List;
2727

2828
import io.github.axolotlclient.AxolotlClientConfig.api.options.Option;
29+
import io.github.axolotlclient.AxolotlClientConfig.api.util.Color;
2930
import io.github.axolotlclient.AxolotlClientConfig.impl.options.BooleanOption;
31+
import io.github.axolotlclient.AxolotlClientConfig.impl.options.ColorOption;
3032
import io.github.axolotlclient.AxolotlClientConfig.impl.options.EnumOption;
3133
import io.github.axolotlclient.modules.hud.gui.component.DynamicallyPositionable;
3234
import io.github.axolotlclient.modules.hud.gui.entry.TextHudEntry;
@@ -63,6 +65,7 @@ public class PotionsHud extends TextHudEntry implements DynamicallyPositionable
6365

6466
private final BooleanOption iconsOnly = new BooleanOption("iconsonly", false);
6567
private final BooleanOption showEffectName = new BooleanOption("showEffectNames", true);
68+
private final ColorOption timerTextColor = new ColorOption("potionshud.timer_text_color", Color.parse("#7F7F7F"));
6669

6770
public PotionsHud() {
6871
super(50, 200, false);
@@ -156,10 +159,10 @@ private void renderPotion(GuiGraphics graphics, MobEffectInstance effect, int x,
156159

157160
graphics.drawString(client.font, string, x + 19, y + 1, textColor.get().toInt(), shadow.get());
158161
Component duration = MobEffectUtil.formatDuration(effect, 1, tickrate);
159-
graphics.drawString(client.font, duration, x + 19, y + 1 + 10, 8355711, shadow.get());
162+
graphics.drawString(client.font, duration, x + 19, y + 1 + 10, timerTextColor.get().toInt(), shadow.get());
160163
} else {
161164
graphics.drawString(client.font, MobEffectUtil.formatDuration(effect, 1, tickrate), x + 19, y + 5,
162-
textColor.get().toInt(), shadow.get()
165+
timerTextColor.get().toInt(), shadow.get()
163166
);
164167
}
165168
}
@@ -179,6 +182,8 @@ public List<Option<?>> getConfigurationOptions() {
179182
options.add(anchor);
180183
options.add(order);
181184
options.add(iconsOnly);
185+
options.add(showEffectName);
186+
options.add(timerTextColor);
182187
return options;
183188
}
184189

0 commit comments

Comments
 (0)