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
|
package com.thatgravyboat.skyblockhud.location;
import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent;
import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent;
import com.thatgravyboat.skyblockhud.overlay.MiningHud;
import com.thatgravyboat.skyblockhud.utils.Utils;
import java.lang.ref.WeakReference;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Arrays;
import java.util.Locale;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class MinesHandler {
public enum Event {
NONE(0, "Unknown", false, false),
TICKET(107, "Raffle", true, true),
GOBLIN(99, "Goblin Raid", true, true),
WIND(0, "Gone With The Wind", false, false),
TOGETHER(171, "Better Together", false, true),
GOURMAND(179, "Mithril Gourmand", true, true);
public int x;
public String displayName;
public boolean needsMax;
public boolean display;
Event(int x, String displayName, boolean needsMax, boolean display) {
this.x = x;
this.displayName = displayName;
this.needsMax = needsMax;
this.display = display;
}
}
public static int mithril;
public static int gemstone;
public static int eventMax;
public static int eventProgress;
public static Event currentEvent;
private static final DecimalFormat NORMAL_FORMATTER = new DecimalFormat("#,###", DecimalFormatSymbols.getInstance(Locale.CANADA));
private static final DecimalFormat SHORT_FORMATTER = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.CANADA));
static {
SHORT_FORMATTER.setRoundingMode(RoundingMode.FLOOR);
}
public static String getMithrilFormatted() {
String output = NORMAL_FORMATTER.format(mithril);
if (output.equals(".0")) output = "0.0"; else if (output.equals(",0")) output = "0,0";
return output;
}
public static String getMithrilShortFormatted() {
return mithril > 999 ? SHORT_FORMATTER.format((double) mithril / 1000) + "k" : String.valueOf(mithril);
}
public static String getGemstoneFormatted() {
String output = NORMAL_FORMATTER.format(gemstone);
if (output.equals(".0")) output = "0.0"; else if (output.equals(",0")) output = "0,0";
return output;
}
public static String getGemstoneShortFormatted() {
return gemstone > 999 ? SHORT_FORMATTER.format((double) gemstone / 1000) + "k" : String.valueOf(gemstone);
}
public static void parseMithril(String line) {
try {
mithril = Integer.parseInt(line.toLowerCase().replace("mithril powder:", "").trim().replaceAll(",", ""));
} catch (Exception ignored) {}
}
public static void parseGemstone(String line) {
try {
gemstone = Integer.parseInt(line.toLowerCase().replace("gemstone powder:", "").trim().replaceAll(",", ""));
} catch (Exception ignored) {}
}
@SubscribeEvent
public void onSidebarLineUpdate(SidebarLineUpdateEvent event) {
if (event.formattedLine.toLowerCase().contains("heat")) {
try {
MiningHud.setHeat(Integer.parseInt(event.formattedLine.toLowerCase().replace("heat:", "").trim().replaceAll(",", "")));
} catch (Exception ignored) {}
}
if (event.formattedLine.toLowerCase().contains("mithril")) {
try {
mithril = Integer.parseInt(event.formattedLine.toLowerCase().replace("mithril:", "").trim().replaceAll(",", ""));
} catch (Exception ignored) {}
}
if (event.formattedLine.toLowerCase().contains("gemstone")) {
try {
gemstone = Integer.parseInt(event.formattedLine.toLowerCase().replace("gemstone:", "").trim().replaceAll(",", ""));
} catch (Exception ignored) {}
}
if (event.formattedLine.toLowerCase().contains("event")) {
if (event.formattedLine.toLowerCase().contains("raffle")) {
MinesHandler.currentEvent = Event.TICKET;
} else if (event.formattedLine.toLowerCase().contains("goblin raid")) {
MinesHandler.currentEvent = Event.GOBLIN;
} else if (event.formattedLine.toLowerCase().contains("mithril gourmand")) {
MinesHandler.currentEvent = Event.GOURMAND;
}
}
if (event.formattedLine.equalsIgnoreCase("wind compass")) {
MinesHandler.currentEvent = Event.WIND;
}
if (event.formattedLine.toLowerCase(Locale.ENGLISH).contains("nearby players")) {
MinesHandler.currentEvent = Event.TOGETHER;
try {
MinesHandler.eventProgress = Integer.parseInt(event.formattedLine.toLowerCase().replace("nearby players:", "").trim().replaceAll(",", ""));
} catch (Exception ignored) {}
}
if (MinesHandler.currentEvent != Event.NONE) {
if (MinesHandler.currentEvent == Event.TICKET) {
if (event.formattedLine.toLowerCase().contains("pool:")) {
try {
eventMax = Integer.parseInt(event.formattedLine.toLowerCase().replace("pool:", "").trim().replaceAll(",", "").split("/")[0].trim().replaceAll(",", ""));
} catch (Exception ignored) {}
} else if (event.formattedLine.toLowerCase().contains("tickets:")) {
try {
eventProgress = Integer.parseInt(event.formattedLine.toLowerCase().replace("tickets:", "").split("\\(")[0].trim().replaceAll(",", ""));
} catch (Exception ignored) {}
}
} else if (MinesHandler.currentEvent == Event.GOBLIN) {
if (event.formattedLine.toLowerCase().contains("remaining:")) {
try {
eventMax = Integer.parseInt(event.formattedLine.toLowerCase().replace("goblins", "").replace("remaining:", "").trim().replaceAll(",", ""));
} catch (Exception ignored) {}
} else if (event.formattedLine.toLowerCase().contains("your kills:") && !event.formattedLine.toLowerCase().contains("(")) {
try {
eventProgress = Integer.parseInt(event.formattedLine.toLowerCase().replace("your kills:", "").trim().replaceAll(",", ""));
} catch (Exception ignored) {}
}
} else if (MinesHandler.currentEvent == Event.GOURMAND) {
if (event.formattedLine.toLowerCase().contains("remaining:")) {
try {
eventMax = Integer.parseInt(event.formattedLine.toLowerCase().replace("tasty mithril", "").replace("remaining:", "").trim().replaceAll(",", ""));
} catch (Exception ignored) {}
} else if (event.formattedLine.toLowerCase().contains("your tasty mithril:") && !event.formattedLine.toLowerCase().contains("(")) {
try {
eventProgress = Integer.parseInt(event.formattedLine.toLowerCase().replace("your tasty mithril:", "").trim().replaceAll(",", ""));
} catch (Exception ignored) {}
}
}
}
}
@SubscribeEvent
public void onSidebarPost(SidebarPostEvent event) {
String arrayString = Arrays.toString(event.arrayScores);
boolean hasEvent = arrayString.toLowerCase().contains("event:");
boolean hasWind = arrayString.toLowerCase().contains("wind compass");
boolean hasNearbyPlayers = arrayString.toLowerCase().contains("nearby players");
if (!hasEvent && !hasWind && !hasNearbyPlayers) {
MinesHandler.currentEvent = Event.NONE;
MinesHandler.eventProgress = 0;
MinesHandler.eventMax = 0;
}
if (!arrayString.toLowerCase().contains("heat:")) {
MiningHud.setHeat(0);
}
}
public static WeakReference<PrehistoricEggProgress> getEggColorAndProgress(ItemStack stack) {
String id = Utils.getItemCustomId(stack);
if (id == null || !id.equals("PREHISTORIC_EGG")) return null;
NBTTagCompound extraAttributes = stack.getTagCompound().getCompoundTag("ExtraAttributes");
if (!extraAttributes.hasKey("blocks_walked")) return null;
PrehistoricEggProgress progress = new PrehistoricEggProgress();
int walked = extraAttributes.getInteger("blocks_walked");
if (walked < 4000) {
progress.currentColor = 0xffffff;
progress.progress = walked / 4000f;
} else if (walked < 10000) {
progress.currentColor = 0x55FF55;
progress.progress = (walked - 4000f) / 6000f;
} else if (walked < 20000) {
progress.currentColor = 0x5555FF;
progress.progress = (walked - 10000f) / 10000f;
} else if (walked < 40000) {
progress.currentColor = 0xAA00AA;
progress.progress = (walked - 20000f) / 20000f;
} else if (walked < 100000) {
progress.currentColor = 0xFFAA00;
progress.progress = (walked - 40000f) / 60000f;
}
return new WeakReference<>(progress);
}
public static class PrehistoricEggProgress {
public float progress;
public int currentColor;
}
}
|