-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathSkyblockAddons.java
More file actions
327 lines (286 loc) · 14.3 KB
/
SkyblockAddons.java
File metadata and controls
327 lines (286 loc) · 14.3 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
package codes.biscuit.skyblockaddons;
import codes.biscuit.skyblockaddons.asm.hooks.FontRendererHook;
import codes.biscuit.skyblockaddons.commands.SkyblockAddonsCommand;
import codes.biscuit.skyblockaddons.config.ConfigValues;
import codes.biscuit.skyblockaddons.config.PersistentValuesManager;
import codes.biscuit.skyblockaddons.core.Feature;
import codes.biscuit.skyblockaddons.core.OnlineData;
import codes.biscuit.skyblockaddons.core.Translations;
import codes.biscuit.skyblockaddons.core.dungeons.DungeonManager;
import codes.biscuit.skyblockaddons.features.EntityOutlines.EntityOutlineRenderer;
import codes.biscuit.skyblockaddons.features.EntityOutlines.FeatureDungeonTeammateOutlines;
import codes.biscuit.skyblockaddons.features.EntityOutlines.FeatureItemOutlines;
import codes.biscuit.skyblockaddons.features.EntityOutlines.FeatureTrackerQuest;
import codes.biscuit.skyblockaddons.features.SkillXpManager;
import codes.biscuit.skyblockaddons.features.discordrpc.DiscordRPCManager;
import codes.biscuit.skyblockaddons.gui.IslandWarpGui;
import codes.biscuit.skyblockaddons.gui.SkyblockAddonsGui;
import codes.biscuit.skyblockaddons.listeners.*;
import codes.biscuit.skyblockaddons.misc.SkyblockKeyBinding;
import codes.biscuit.skyblockaddons.misc.Updater;
import codes.biscuit.skyblockaddons.misc.scheduler.NewScheduler;
import codes.biscuit.skyblockaddons.misc.scheduler.Scheduler;
import codes.biscuit.skyblockaddons.misc.scheduler.SkyblockRunnable;
import codes.biscuit.skyblockaddons.newgui.GuiManager;
import codes.biscuit.skyblockaddons.utils.*;
import codes.biscuit.skyblockaddons.utils.data.DataUtils;
import codes.biscuit.skyblockaddons.utils.gson.GsonInitializableTypeAdapter;
import codes.biscuit.skyblockaddons.utils.gson.PatternAdapter;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.SimpleReloadableResourceManager;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLModDisabledEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Keyboard;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
@Getter
@Mod(modid = "skyblockaddons", name = "SkyblockAddons", version = "@VERSION@", clientSideOnly = true, acceptedMinecraftVersions = "@MOD_ACCEPTED@")
public class SkyblockAddons {
public static final String MOD_ID = "skyblockaddons";
public static final String MOD_NAME = "SkyblockAddons";
public static String VERSION = "@VERSION@";
/**
* This is set by the CI. If the build isn't done on CI, this will be an empty string.
*/
public static final String BUILD_NUMBER = "@BUILD_NUMBER@";
@Getter private static SkyblockAddons instance;
@Getter private static boolean fullyInitialized;
@SuppressWarnings({"rawtypes", "unchecked"})
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.registerTypeAdapter(EnumMap.class, (InstanceCreator<EnumMap>) type -> {
Type[] types = (((ParameterizedType) type).getActualTypeArguments());
return new EnumMap((Class<?>) types[0]);
})
.registerTypeAdapterFactory(new GsonInitializableTypeAdapter())
.registerTypeAdapter(Pattern.class, new PatternAdapter())
.create();
private static final Logger LOGGER = LogManager.getLogger(new SkyblockAddonsMessageFactory(MOD_NAME));
private static final ThreadPoolExecutor THREAD_EXECUTOR = new ThreadPoolExecutor(0, 1, 60L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat(SkyblockAddons.MOD_NAME + " - #%d").build());
private ConfigValues configValues;
private PersistentValuesManager persistentValuesManager;
private final PlayerListener playerListener;
private final GuiScreenListener guiScreenListener;
private final RenderListener renderListener;
private final ResourceManagerReloadListener resourceManagerReloadListener;
private final InventoryUtils inventoryUtils;
private final Utils utils;
private final Updater updater;
@Setter
private OnlineData onlineData;
private final DiscordRPCManager discordRPCManager;
private final Scheduler scheduler;
private final NewScheduler newScheduler;
private final DungeonManager dungeonManager;
private final GuiManager guiManager;
private final SkillXpManager skillXpManager;
private boolean usingLabymod;
private boolean usingOofModv1;
private boolean usingPatcher;
@Setter
private boolean devMode;
private final List<SkyblockKeyBinding> keyBindings = new LinkedList<>();
@Getter
private final Set<Integer> registeredFeatureIDs = new HashSet<>();
public SkyblockAddons() {
instance = this;
playerListener = new PlayerListener();
guiScreenListener = new GuiScreenListener();
renderListener = new RenderListener();
resourceManagerReloadListener = new ResourceManagerReloadListener();
inventoryUtils = new InventoryUtils();
utils = new Utils();
updater = new Updater();
scheduler = new Scheduler();
newScheduler = new NewScheduler();
dungeonManager = new DungeonManager();
discordRPCManager = new DiscordRPCManager();
guiManager = new GuiManager();
skillXpManager = new SkillXpManager();
}
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e) {
configValues = new ConfigValues(e.getSuggestedConfigurationFile());
persistentValuesManager = new PersistentValuesManager(e.getModConfigurationDirectory());
configValues.loadValues();
DataUtils.readLocalAndFetchOnline();
persistentValuesManager.loadValues();
}
@Mod.EventHandler
public void init(FMLInitializationEvent e) {
if (DataUtils.USE_ONLINE_DATA) {
DataUtils.loadOnlineData();
}
MinecraftForge.EVENT_BUS.register(new NetworkListener());
MinecraftForge.EVENT_BUS.register(playerListener);
MinecraftForge.EVENT_BUS.register(guiScreenListener);
MinecraftForge.EVENT_BUS.register(renderListener);
MinecraftForge.EVENT_BUS.register(scheduler);
MinecraftForge.EVENT_BUS.register(newScheduler);
MinecraftForge.EVENT_BUS.register(new FeatureItemOutlines());
MinecraftForge.EVENT_BUS.register(new FeatureDungeonTeammateOutlines());
MinecraftForge.EVENT_BUS.register(new EntityOutlineRenderer());
MinecraftForge.EVENT_BUS.register(new FeatureTrackerQuest());
((SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(resourceManagerReloadListener);
ClientCommandHandler.instance.registerCommand(new SkyblockAddonsCommand());
// Macs do not have a right control key.
int developerModeKey = Minecraft.isRunningOnMac ? Keyboard.KEY_LMENU : Keyboard.KEY_RCONTROL;
Collections.addAll(keyBindings, new SkyblockKeyBinding("open_settings", Keyboard.KEY_NONE, "settings.settings"),
new SkyblockKeyBinding("edit_gui", Keyboard.KEY_NONE, "settings.editLocations"),
new SkyblockKeyBinding("lock_slot", Keyboard.KEY_L, "settings.lockSlot"),
new SkyblockKeyBinding("freeze_backpack", Keyboard.KEY_F, "settings.freezeBackpackPreview"),
new SkyblockKeyBinding("increase_dungeon_map_zoom", Keyboard.KEY_EQUALS, "keyBindings.increaseDungeonMapZoom"),
new SkyblockKeyBinding("decrease_dungeon_map_zoom", Keyboard.KEY_SUBTRACT, "keyBindings.decreaseDungeonMapZoom"),
new SkyblockKeyBinding("copy_NBT", developerModeKey, "keyBindings.developerCopyNBT"));
registerKeyBindings(keyBindings);
setKeyBindingDescriptions();
/*
TODO: De-registering keys isn't standard practice. Should this be changed to have the player manually set it to
KEY_NONE instead?
De-register the devmode key binding since it's not needed until devmode is enabled. I can't just not register it
in the first place since creating a KeyBinding object already adds it to the main key bind list. I need to manually
de-register it so its default key doesn't conflict with other key bindings with the same key.
*/
if (!this.getConfigValues().isEnabled(Feature.DEVELOPER_MODE)) {
getDeveloperCopyNBTKey().deRegister();
}
usingLabymod = utils.isModLoaded("labymod");
usingOofModv1 = utils.isModLoaded("refractionoof", "1.0");
usingPatcher = utils.isModLoaded("patcher");
if (!this.configValues.isEnabled(Feature.NUMBER_SEPARATORS)) {
TextUtils.NUMBER_FORMAT.setGroupingUsed(false);
}
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent e) {
scheduleMagmaBossCheck();
for (Feature feature : Feature.values()) {
if (feature.isGuiFeature()) feature.getSettings().add(EnumUtils.FeatureSetting.GUI_SCALE);
if (feature.isColorFeature()) feature.getSettings().add(EnumUtils.FeatureSetting.COLOR);
if (feature.getGuiFeatureData() != null && feature.getGuiFeatureData().getDrawType() == EnumUtils.DrawType.BAR) {
feature.getSettings().add(EnumUtils.FeatureSetting.GUI_SCALE_X);
feature.getSettings().add(EnumUtils.FeatureSetting.GUI_SCALE_Y);
}
}
if (configValues.isEnabled(Feature.FANCY_WARP_MENU)) {
// Load in these textures so they don't lag the user loading them in later...
for (IslandWarpGui.Island island : IslandWarpGui.Island.values()) {
Minecraft.getMinecraft().getTextureManager().bindTexture(island.getResourceLocation());
}
}
Minecraft.getMinecraft().getTextureManager().bindTexture(SkyblockAddonsGui.LOGO);
Minecraft.getMinecraft().getTextureManager().bindTexture(SkyblockAddonsGui.LOGO_GLOW);
fullyInitialized = true;
FontRendererHook.onModInitialized();
}
@Mod.EventHandler
public void stop(FMLModDisabledEvent e) {
discordRPCManager.stop();
}
private void scheduleMagmaBossCheck() {
// Loop every 5s until the player is in game, where it will pull once.
newScheduler.scheduleRepeatingTask(new SkyblockRunnable() {
@Override
public void run() {
if (Minecraft.getMinecraft() != null && Minecraft.getMinecraft().thePlayer != null) {
utils.fetchMagmaBossEstimate();
cancel();
}
}
}, 20*5, 20*5);
}
public KeyBinding getOpenSettingsKey() {
return keyBindings.get(0).getKeyBinding();
}
public KeyBinding getOpenEditLocationsKey() {
return keyBindings.get(1).getKeyBinding();
}
public KeyBinding getLockSlotKey() {
return keyBindings.get(2).getKeyBinding();
}
public KeyBinding getFreezeBackpackKey() {
return keyBindings.get(3).getKeyBinding();
}
public SkyblockKeyBinding getDeveloperCopyNBTKey() {
return keyBindings.get(6);
}
/**
* Registers the given keybindings to the {@link net.minecraftforge.fml.client.registry.ClientRegistry}.
*
* @param keyBindings the keybindings to register
*/
public void registerKeyBindings(List<SkyblockKeyBinding> keyBindings) {
for (SkyblockKeyBinding keybinding: keyBindings) {
keybinding.register();
}
}
/**
* This method updates keybinding descriptions to their localized name after registering them with a Minecraft-style
* id, which is required for the set key to be saved properly in Minecraft settings.
*/
public void setKeyBindingDescriptions() {
for (SkyblockKeyBinding skyblockKeyBinding : keyBindings) {
skyblockKeyBinding.getKeyBinding().keyDescription =
Translations.getMessage(skyblockKeyBinding.getTranslationKey());
}
}
public static Gson getGson() {
return GSON;
}
/**
* Returns a {@link Logger} with the name of the calling class in the prefix, following the format
* {@code [SkyblockAddons/className]}. Please call this method <b>once</b> in every class that needs a logger.
* Do not call it multiple times in the same class to avoid creating un-needed {@code SkyblockAddonsMessageFactory}
* instances.
*
* @return a {@code Logger} containing the name of the calling class in the prefix.
*/
public static Logger getLogger() {
String fullClassName = new Throwable().getStackTrace()[1].getClassName();
String simpleClassName = fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
return LogManager.getLogger(fullClassName, new SkyblockAddonsMessageFactory(simpleClassName));
}
/**
* Returns the complete SemVer version with pre-release and build number if it is defined.
*
* @return the complete SemVer version string
*/
public static String getVersionFull() {
// Set by CI, is not actually constant
//noinspection ConstantConditions
if (!SkyblockAddons.BUILD_NUMBER.isEmpty()) {
return SkyblockAddons.VERSION + '+' + SkyblockAddons.BUILD_NUMBER;
} else {
return SkyblockAddons.VERSION;
}
}
public static void runAsync(Runnable runnable) {
THREAD_EXECUTOR.execute(runnable);
}
// This replaces the version placeholder if the mod is built using IntelliJ instead of Gradle.
static {
if (VERSION.contains("@")) { // Debug environment...
VERSION = "1.6.0";
}
}
}