1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
package de.hysky.skyblocker.skyblock.dwarven;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.tabhud.util.Colors;
import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudCommsWidget;
import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudPowderWidget;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class DwarvenHud {
public static final MinecraftClient client = MinecraftClient.getInstance();
public static List<Commission> commissionList = new ArrayList<>();
public static int mithrilPowder = 0;
public static int gemStonePowder = 0;
public static final List<Pattern> COMMISSIONS = Stream.of(
"(?:Titanium|Mithril|Hard Stone) Miner",
"(?:Ice Walker|Golden Goblin|(?<!Golden )Goblin|Goblin Raid|Automaton|Sludge|Team Treasurite Member|Yog|Boss Corleone|Thyst) Slayer",
"(?:Lava Springs|Cliffside Veins|Rampart's Quarry|Upper Mines|Royal Mines) Mithril",
"(?:Lava Springs|Cliffside Veins|Rampart's Quarry|Upper Mines|Royal Mines) Titanium",
"Goblin Raid",
"(?:Powder Ghast|Star Sentry) Puncher",
"(?<!Lucky )Raffle",
"Lucky Raffle",
"2x Mithril Powder Collector",
"(?:Ruby|Amber|Sapphire|Jade|Amethyst|Topaz) Gemstone Collector",
"(?:Amber|Sapphire|Jade|Amethyst|Topaz) Crystal Hunter",
"Chest Looter").map(s -> Pattern.compile("^.*(" + s + "): (\\d+\\.?\\d*%|DONE)"))
.collect(Collectors.toList());
public static void init() {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker")
.then(ClientCommandManager.literal("hud")
.then(ClientCommandManager.literal("dwarven")
.executes(Scheduler.queueOpenScreenCommand(DwarvenHudConfigScreen::new))))));
HudRenderCallback.EVENT.register((context, tickDelta) -> {
if ((!SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions && !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder)
|| client.options.playerListKey.isPressed()
|| client.player == null
|| commissionList.isEmpty()) {
return;
}
render(HudCommsWidget.INSTANCE,HudPowderWidget.INSTANCE, context,
SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsX,
SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.commissionsY,
SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX,
SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderY,
commissionList,mithrilPowder,gemStonePowder);
});
}
public static Pair<IntIntPair,IntIntPair> getDimForConfig(List<Commission> commissions) { //todo add powder
return switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) {
case SIMPLE -> {
HudCommsWidget.INSTANCE_CFG.updateData(commissions, false);
yield Pair.of(
IntIntPair.of(
HudCommsWidget.INSTANCE_CFG.getWidth(),
HudCommsWidget.INSTANCE_CFG.getHeight()),
IntIntPair.of(
HudPowderWidget.INSTANCE_CFG.getWidth(),
HudPowderWidget.INSTANCE_CFG.getHeight())
);
}
case FANCY -> {
HudCommsWidget.INSTANCE_CFG.updateData(commissions, true);
yield Pair.of(
IntIntPair.of(
HudCommsWidget.INSTANCE_CFG.getWidth(),
HudCommsWidget.INSTANCE_CFG.getHeight()),
IntIntPair.of(
HudPowderWidget.INSTANCE_CFG.getWidth(),
HudPowderWidget.INSTANCE_CFG.getHeight())
);
}
default -> Pair.of(
IntIntPair.of(
200,
20 * commissions.size()),
IntIntPair.of(
200,
40)
);
};
}
public static void render(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions,int mithril, int gemStone) {
switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) {
case SIMPLE -> renderSimple(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions,mithril,gemStone);
case FANCY -> renderFancy(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions,mithril,gemStone);
case CLASSIC -> renderClassic(context, comHudX, comHudY,powderHudX,powderHudY, commissions);
}
}
public static void renderClassic(DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions) {
if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground) {
context.fill(comHudX, comHudY, comHudX + 200, comHudY + (20 * commissions.size()), 0x64000000);
context.fill(powderHudX, powderHudY, powderHudX + 200, powderHudY + 40, 0x64000000);
}
if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) {
int y = 0;
for (Commission commission : commissions) {
float percentage;
if (!commission.progression().contains("DONE")) {
percentage = Float.parseFloat(commission.progression().substring(0, commission.progression().length() - 1));
} else {
percentage = 100f;
}
context
.drawTextWithShadow(client.textRenderer,
Text.literal(commission.commission + ": ")
.styled(style -> style.withColor(Formatting.AQUA))
.append(Text.literal(commission.progression)
.styled(style -> style.withColor(Colors.hypixelProgressColor(percentage)))),
comHudX + 5, comHudY + y + 5, 0xFFFFFFFF);
y += 20;
}
}
if(SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) {
//render mithril powder then gemstone
context
.drawTextWithShadow(client.textRenderer,
Text.literal("Mithril: " + mithrilPowder)
.styled(style -> style.withColor(Formatting.AQUA)),
powderHudX + 5, powderHudY + 5, 0xFFFFFFFF);
context
.drawTextWithShadow(client.textRenderer,
Text.literal("Gemstone: " + gemStonePowder)
.styled(style -> style.withColor(Formatting.DARK_PURPLE)),
powderHudX + 5, powderHudY + 25, 0xFFFFFFFF);
}
}
public static void renderSimple(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions,int mithril, int gemStone) {
if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) {
hcw.updateData(commissions, false);
hcw.update();
hcw.setX(comHudX);
hcw.setY(comHudY);
hcw.render(context,
SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground);
}
if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) {
hpw.update();
hpw.setX(powderHudX);
hpw.setY(powderHudY);
hpw.render(context,
SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground);
}
}
public static void renderFancy(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions,int mithril, int gemStone) {
if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) {
hcw.updateData(commissions, true);
hcw.update();
hcw.setX(comHudX);
hcw.setY(comHudY);
hcw.render(context,
SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground);
}
if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) {
hpw.update();
hpw.setX(powderHudX);
hpw.setY(powderHudY);
hpw.render(context,
SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground);
}
}
public static void update() {
commissionList = new ArrayList<>();
if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions)
return;
client.getNetworkHandler().getPlayerList().forEach(playerListEntry -> {
if (playerListEntry.getDisplayName() != null) {
for (Pattern pattern : COMMISSIONS) {
Matcher matcher = pattern.matcher(playerListEntry.getDisplayName().getString());
if (matcher.find()) {
commissionList.add(new Commission(matcher.group(1), matcher.group(2)));
}
}
}
});
}
// steamroller tactics to get visibility from outside classes (HudCommsWidget)
public record Commission(String commission, String progression) {
}
}
|