diff options
author | Grayray75 <69988482+Grayray75@users.noreply.github.com> | 2023-09-16 22:11:48 +0200 |
---|---|---|
committer | Grayray75 <69988482+Grayray75@users.noreply.github.com> | 2023-09-16 22:11:48 +0200 |
commit | 7ca3ad2eabafce7f07949f6ee9904c9741c2ca2e (patch) | |
tree | dfdce4152e4c86ec4eb5704a63aa356aeb49d38f /src/main/java/me/xmrvizzy | |
parent | 73b458edfacf9711c85893a171e89be6b0ce54a6 (diff) | |
download | Skyblocker-7ca3ad2eabafce7f07949f6ee9904c9741c2ca2e.tar.gz Skyblocker-7ca3ad2eabafce7f07949f6ee9904c9741c2ca2e.tar.bz2 Skyblocker-7ca3ad2eabafce7f07949f6ee9904c9741c2ca2e.zip |
Changes 1
Diffstat (limited to 'src/main/java/me/xmrvizzy')
4 files changed, 42 insertions, 55 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index d6e3f0fe..476af0a8 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -438,10 +438,6 @@ public class SkyblockerConfig implements ConfigData { @ConfigEntry.Gui.CollapsibleObject() public Barn barn = new Barn(); - @ConfigEntry.Category("spidersden") - @ConfigEntry.Gui.CollapsibleObject() - public SpidersDen spidersden = new SpidersDen(); - @ConfigEntry.Category("dungeons") @ConfigEntry.Gui.CollapsibleObject() public Dungeons dungeons = new Dungeons(); @@ -453,6 +449,10 @@ public class SkyblockerConfig implements ConfigData { @ConfigEntry.Category("rift") @ConfigEntry.Gui.CollapsibleObject() public Rift rift = new Rift(); + + @ConfigEntry.Category("spidersden") + @ConfigEntry.Gui.CollapsibleObject() + public SpidersDen spidersDen = new SpidersDen(); } public static class Dungeons { diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java index f1de63e5..be1c1dcd 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java @@ -49,13 +49,13 @@ public class FairySouls { return fairySoulsLoaded.thenRunAsync(runnable); } - public static int getFairySoulsAmount(@Nullable String location) { + public static int getFairySoulsSize(@Nullable String location) { return location == null ? maxSouls : fairySouls.get(location).size(); } public static void init() { loadFairySouls(); - ClientLifecycleEvents.CLIENT_STOPPING.register(FairySouls::saveFairySouls); + ClientLifecycleEvents.CLIENT_STOPPING.register(FairySouls::saveFoundFairySouls); ClientReceiveMessageEvents.GAME.register(FairySouls::onChatMessage); WorldRenderEvents.AFTER_TRANSLUCENT.register(FairySouls::render); ClientCommandRegistrationCallback.EVENT.register(FairySouls::registerCommands); @@ -63,8 +63,7 @@ public class FairySouls { private static void loadFairySouls() { fairySoulsLoaded = NEURepo.runAsyncAfterLoad(() -> { - try { - BufferedReader reader = new BufferedReader(new FileReader(NEURepo.LOCAL_REPO_DIR.resolve("constants").resolve("fairy_souls.json").toFile())); + try (BufferedReader reader = new BufferedReader(new FileReader(NEURepo.LOCAL_REPO_DIR.resolve("constants").resolve("fairy_souls.json").toFile()))) { for (Map.Entry<String, JsonElement> fairySoulJson : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) { if (fairySoulJson.getKey().equals("//") || fairySoulJson.getKey().equals("Max Souls")) { if (fairySoulJson.getKey().equals("Max Souls")) { @@ -78,14 +77,12 @@ public class FairySouls { } fairySouls.put(fairySoulJson.getKey(), fairySoulsForLocation.build()); } - reader.close(); - LOGGER.info("[Skyblocker] Loaded fairy soul locations"); + LOGGER.debug("[Skyblocker] Loaded fairy soul locations"); } catch (IOException e) { LOGGER.error("[Skyblocker] Failed to load fairy soul locations", e); } - try { - BufferedReader reader = new BufferedReader(new FileReader(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json").toFile())); + try (BufferedReader reader = new BufferedReader(new FileReader(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json").toFile()))) { for (Map.Entry<String, JsonElement> foundFairiesForProfileJson : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) { Map<String, Set<BlockPos>> foundFairiesForProfile = new HashMap<>(); for (Map.Entry<String, JsonElement> foundFairiesForLocationJson : foundFairiesForProfileJson.getValue().getAsJsonObject().asMap().entrySet()) { @@ -97,8 +94,7 @@ public class FairySouls { } foundFairies.put(foundFairiesForProfileJson.getKey(), foundFairiesForProfile); } - reader.close(); - LOGGER.info("[Skyblocker] Loaded found fairy souls"); + LOGGER.debug("[Skyblocker] Loaded found fairy souls"); } catch (FileNotFoundException ignored) { } catch (IOException e) { LOGGER.error("[Skyblocker] Failed to load found fairy souls", e); @@ -106,9 +102,8 @@ public class FairySouls { }); } - private static void saveFairySouls(MinecraftClient client) { - try { - BufferedWriter writer = new BufferedWriter(new FileWriter(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json").toFile())); + private static void saveFoundFairySouls(MinecraftClient client) { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json").toFile()))) { JsonObject foundFairiesJson = new JsonObject(); for (Map.Entry<String, Map<String, Set<BlockPos>>> foundFairiesForProfile : foundFairies.entrySet()) { JsonObject foundFairiesForProfileJson = new JsonObject(); @@ -144,13 +139,6 @@ public class FairySouls { })))); } - private static void onChatMessage(Text text, boolean overlay) { - String message = text.getString(); - if (message.equals("You have already found that Fairy Soul!") || message.equals("§d§lSOUL! §fYou found a §dFairy Soul§f!")) { - markClosestFairyFound(); - } - } - private static void render(WorldRenderContext context) { SkyblockerConfig.FairySouls fairySoulsConfig = SkyblockerConfig.get().general.fairySouls; @@ -166,6 +154,13 @@ public class FairySouls { } } + private static void onChatMessage(Text text, boolean overlay) { + String message = text.getString(); + if (message.equals("You have already found that Fairy Soul!") || message.equals("§d§lSOUL! §fYou found a §dFairy Soul§f!")) { + markClosestFairyFound(); + } + } + private static boolean isFairySoulNotFound(BlockPos fairySoulPos) { Map<String, Set<BlockPos>> foundFairiesForProfile = foundFairies.get(Utils.getProfile()); if (foundFairiesForProfile == null) { diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java index f1b886c2..f4ea1ee9 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java @@ -79,23 +79,23 @@ public class Trivia extends ChatPatternListener { answers.put("Which of these is not a dragon in The End?", new String[]{"Zoomer Dragon", "Weak Dragon", "Stonk Dragon", "Holy Dragon", "Boomer Dragon", "Booger Dragon", "Older Dragon", "Elder Dragon", "Stable Dragon", "Professor Dragon"}); FairySouls.runAsyncAfterFairySoulsLoad(() -> { - answers.put("How many total Fairy Souls are there?", getFairySoulsAmountString(null)); - answers.put("How many Fairy Souls are there in Spider's Den?", getFairySoulsAmountString("combat_1")); - answers.put("How many Fairy Souls are there in The End?", getFairySoulsAmountString("combat_3")); - answers.put("How many Fairy Souls are there in The Farming Islands?", getFairySoulsAmountString("farming_1")); - answers.put("How many Fairy Souls are there in Crimson Isle?", getFairySoulsAmountString("crimson_isle")); - answers.put("How many Fairy Souls are there in The Park?", getFairySoulsAmountString("foraging_1")); - answers.put("How many Fairy Souls are there in Jerry's Workshop?", getFairySoulsAmountString("winter")); - answers.put("How many Fairy Souls are there in Hub?", getFairySoulsAmountString("hub")); - answers.put("How many Fairy Souls are there in The Hub?", getFairySoulsAmountString("hub")); - answers.put("How many Fairy Souls are there in Deep Caverns?", getFairySoulsAmountString("mining_2")); - answers.put("How many Fairy Souls are there in Gold Mine?", getFairySoulsAmountString("mining_1")); - answers.put("How many Fairy Souls are there in Dungeon Hub?", getFairySoulsAmountString("dungeon_hub")); + answers.put("How many total Fairy Souls are there?", getFairySoulsSizeString(null)); + answers.put("How many Fairy Souls are there in Spider's Den?", getFairySoulsSizeString("combat_1")); + answers.put("How many Fairy Souls are there in The End?", getFairySoulsSizeString("combat_3")); + answers.put("How many Fairy Souls are there in The Farming Islands?", getFairySoulsSizeString("farming_1")); + answers.put("How many Fairy Souls are there in Crimson Isle?", getFairySoulsSizeString("crimson_isle")); + answers.put("How many Fairy Souls are there in The Park?", getFairySoulsSizeString("foraging_1")); + answers.put("How many Fairy Souls are there in Jerry's Workshop?", getFairySoulsSizeString("winter")); + answers.put("How many Fairy Souls are there in Hub?", getFairySoulsSizeString("hub")); + answers.put("How many Fairy Souls are there in The Hub?", getFairySoulsSizeString("hub")); + answers.put("How many Fairy Souls are there in Deep Caverns?", getFairySoulsSizeString("mining_2")); + answers.put("How many Fairy Souls are there in Gold Mine?", getFairySoulsSizeString("mining_1")); + answers.put("How many Fairy Souls are there in Dungeon Hub?", getFairySoulsSizeString("dungeon_hub")); }); } @NotNull - private static String[] getFairySoulsAmountString(@Nullable String location) { - return new String[]{"%d Fairy Souls".formatted(FairySouls.getFairySoulsAmount(location))}; + private static String[] getFairySoulsSizeString(@Nullable String location) { + return new String[]{"%d Fairy Souls".formatted(FairySouls.getFairySoulsSize(location))}; } } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/spidersden/Relics.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/spidersden/Relics.java index 6f7f1ee6..c09d895f 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/spidersden/Relics.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/spidersden/Relics.java @@ -33,14 +33,13 @@ public class Relics { public static void init() { ClientLifecycleEvents.CLIENT_STARTED.register(Relics::onClientStarted); - ClientLifecycleEvents.CLIENT_STOPPING.register(Relics::onClientStopping); + ClientLifecycleEvents.CLIENT_STOPPING.register(Relics::saveFoundRelics); ClientReceiveMessageEvents.GAME.register(Relics::onChatMessage); WorldRenderEvents.AFTER_TRANSLUCENT.register(Relics::render); } private static void onClientStarted(MinecraftClient client) { - try { - BufferedReader reader = client.getResourceManager().openAsReader(new Identifier(SkyblockerMod.NAMESPACE, "spidersden/relics.json")); + try (BufferedReader reader = client.getResourceManager().openAsReader(new Identifier(SkyblockerMod.NAMESPACE, "spidersden/relics.json"))) { for (Map.Entry<String, JsonElement> json : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) { if (json.getKey().equals("total")) { totalRelics = json.getValue().getAsInt(); @@ -51,14 +50,12 @@ public class Relics { } } } - reader.close(); LOGGER.info("[Skyblocker] Loaded relics locations"); } catch (IOException e) { LOGGER.error("[Skyblocker] Failed to load relics locations", e); } - try { - BufferedReader reader = new BufferedReader(new FileReader(SkyblockerMod.CONFIG_DIR.resolve("found_relics.json").toFile())); + try (BufferedReader reader = new BufferedReader(new FileReader(SkyblockerMod.CONFIG_DIR.resolve("found_relics.json").toFile()))) { for (Map.Entry<String, JsonElement> profileJson : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) { Set<BlockPos> foundRelicsForProfile = new HashSet<>(); for (JsonElement foundRelicsJson : profileJson.getValue().getAsJsonArray().asList()) { @@ -66,17 +63,15 @@ public class Relics { } foundRelics.put(profileJson.getKey(), foundRelicsForProfile); } - reader.close(); - LOGGER.info("[Skyblocker] Loaded found relics"); + LOGGER.debug("[Skyblocker] Loaded found relics"); } catch (FileNotFoundException ignored) { } catch (IOException e) { LOGGER.error("[Skyblocker] Failed to load found relics", e); } } - private static void onClientStopping(MinecraftClient client) { - try { - BufferedWriter writer = new BufferedWriter(new FileWriter(SkyblockerMod.CONFIG_DIR.resolve("found_relics.json").toFile())); + private static void saveFoundRelics(MinecraftClient client) { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(SkyblockerMod.CONFIG_DIR.resolve("found_relics.json").toFile()))) { JsonObject json = new JsonObject(); for (Map.Entry<String, Set<BlockPos>> foundRelicsForProfile : foundRelics.entrySet()) { JsonArray foundRelicsJson = new JsonArray(); @@ -86,8 +81,7 @@ public class Relics { json.add(foundRelicsForProfile.getKey(), foundRelicsJson); } SkyblockerMod.GSON.toJson(json, writer); - writer.close(); - LOGGER.info("[Skyblocker] Saved found relics"); + LOGGER.debug("[Skyblocker] Saved found relics"); } catch (IOException e) { LOGGER.error("[Skyblocker] Failed to write found relics to file", e); } @@ -101,14 +95,12 @@ public class Relics { } private static void render(WorldRenderContext context) { - SkyblockerConfig.Relics config = SkyblockerConfig.get().locations.spidersden.relics; + SkyblockerConfig.Relics config = SkyblockerConfig.get().locations.spidersDen.relics; if (config.enableRelicsHelper && Utils.getLocationRaw().equals("combat_1")) { for (BlockPos fairySoulPos : relics) { boolean isRelicFound = isRelicFound(fairySoulPos); - if (isRelicFound && !config.highlightFoundRelics) { - continue; - } + if (isRelicFound && !config.highlightFoundRelics) continue; float[] colorComponents = isRelicFound ? DyeColor.BROWN.getColorComponents() : DyeColor.YELLOW.getColorComponents(); RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, fairySoulPos, colorComponents, 0.5F); } |