diff options
author | Yasin <LifeIsAParadox@users.noreply.github.com> | 2023-08-07 16:19:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-07 16:19:21 +0200 |
commit | 84ea4626690c30177d7f13b7789eb375dea9c705 (patch) | |
tree | ac16d378fed65e50430c7d9aed98641160006cf4 /src/main/java/me/xmrvizzy/skyblocker/skyblock | |
parent | 528dd7d73c16dfab5b65a761b2888c5b5591c2c5 (diff) | |
parent | 0d0bd433af7f1250af27dd989b45aa7e5cab5223 (diff) | |
download | Skyblocker-84ea4626690c30177d7f13b7789eb375dea9c705.tar.gz Skyblocker-84ea4626690c30177d7f13b7789eb375dea9c705.tar.bz2 Skyblocker-84ea4626690c30177d7f13b7789eb375dea9c705.zip |
Merge pull request #229 from kevinthegreat1/random-refactors
Random refactors
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock')
5 files changed, 48 insertions, 31 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java index ccffdcca..2bdfa401 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java @@ -20,6 +20,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.DyeColor; import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,6 +36,18 @@ public class FairySouls { private static final Map<String, Set<BlockPos>> fairySouls = new HashMap<>(); private static final Map<String, Map<String, Set<BlockPos>>> foundFairies = new HashMap<>(); + public static CompletableFuture<Void> runAsyncAfterFairySoulsLoad(Runnable runnable) { + if (fairySoulsLoaded == null) { + LOGGER.error("Fairy Souls have not being initialized yet! Please ensure the Fairy Souls module is initialized before modules calling this method in SkyblockerMod#onInitializeClient. This error can be safely ignore in a test environment."); + return CompletableFuture.completedFuture(null); + } + return fairySoulsLoaded.thenRunAsync(runnable); + } + + public static int getFairySoulsSize(@Nullable String location) { + return location == null ? fairySouls.values().stream().mapToInt(Set::size).sum() : fairySouls.get(location).size(); + } + public static void init() { fairySoulsLoaded = NEURepo.runAsyncAfterLoad(() -> { try { diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonMap.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonMap.java index 29a6e687..040c8aed 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonMap.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonMap.java @@ -1,7 +1,7 @@ package me.xmrvizzy.skyblocker.skyblock.dungeon; -import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.Scheduler; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.minecraft.client.MinecraftClient; @@ -56,6 +56,6 @@ public class DungeonMap { ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") .then(ClientCommandManager.literal("hud") .then(ClientCommandManager.literal("dungeonmap") - .executes(context -> SkyblockerMod.getInstance().scheduler.queueOpenScreen(DungeonMapConfigScreen::new)))))); + .executes(Scheduler.queueOpenScreenCommand(DungeonMapConfigScreen::new)))))); } }
\ No newline at end of file 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 f7598af5..9c7452ac 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Trivia.java @@ -1,19 +1,18 @@ package me.xmrvizzy.skyblocker.skyblock.dungeon; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; - import me.xmrvizzy.skyblocker.chat.ChatFilterResult; import me.xmrvizzy.skyblocker.chat.ChatPatternListener; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.skyblock.FairySouls; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.*; +import java.util.regex.Matcher; public class Trivia extends ChatPatternListener { private static final Map<String, String[]> answers; @@ -38,8 +37,7 @@ public class Trivia extends ChatPatternListener { MinecraftClient.getInstance().player.sendMessage(Text.of(" " + Formatting.GOLD + matcher.group(2) + Formatting.RED + " " + riddle), false); return player != null; } - } else - updateSolutions(matcher.group(0)); + } else updateSolutions(matcher.group(0)); return false; } @@ -56,7 +54,7 @@ public class Trivia extends ChatPatternListener { } static { - answers = new HashMap<>(); + answers = Collections.synchronizedMap(new HashMap<>()); answers.put("What is the status of The Watcher?", new String[]{"Stalker"}); answers.put("What is the status of Bonzo?", new String[]{"New Necromancer"}); answers.put("What is the status of Scarf?", new String[]{"Apprentice Necromancer"}); @@ -69,18 +67,6 @@ public class Trivia extends ChatPatternListener { answers.put("What is the status of Storm?", new String[]{"The Wither Lords"}); answers.put("What is the status of Necron?", new String[]{"The Wither Lords"}); answers.put("What is the status of Maxor, Storm, Goldor and Necron?", new String[]{"The Wither Lords"}); - answers.put("How many total Fairy Souls are there?", new String[]{"242 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Spider's Den?", new String[]{"19 Fairy Souls"}); - answers.put("How many Fairy Souls are there in The End?", new String[]{"12 Fairy Souls"}); - answers.put("How many Fairy Souls are there in The Farming Islands?", new String[]{"20 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Crimson Isle?", new String[]{"29 Fairy Souls"}); - answers.put("How many Fairy Souls are there in The Park?", new String[]{"11 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Jerry's Workshop?", new String[]{"5 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Hub?", new String[]{"79 Fairy Souls"}); - answers.put("How many Fairy Souls are there in The Hub?", new String[]{"79 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Deep Caverns?", new String[]{"21 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Gold Mine?", new String[]{"12 Fairy Souls"}); - answers.put("How many Fairy Souls are there in Dungeon Hub?", new String[]{"7 Fairy Souls"}); answers.put("Which brother is on the Spider's Den?", new String[]{"Rick"}); answers.put("What is the name of Rick's brother?", new String[]{"Pat"}); answers.put("What is the name of the Painter in the Hub?", new String[]{"Marco"}); @@ -88,10 +74,27 @@ public class Trivia extends ChatPatternListener { answers.put("What is the name of the lady of the Nether?", new String[]{"Elle"}); answers.put("Which villager in the Village gives you a Rogue Sword?", new String[]{"Jamie"}); answers.put("How many unique minions are there?", new String[]{"59 Minions"}); - answers.put("Which of these enemies does not spawn in the Spider's Den?", new String[]{"Zombie Spider", "Cave Spider", "Wither Skeleton", - "Dashing Spooder", "Broodfather", "Night Spider"}); + answers.put("Which of these enemies does not spawn in the Spider's Den?", new String[]{"Zombie Spider", "Cave Spider", "Wither Skeleton", "Dashing Spooder", "Broodfather", "Night Spider"}); answers.put("Which of these monsters only spawns at night?", new String[]{"Zombie Villager", "Ghast"}); - 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"}); + 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?", 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[] getFairySoulsSizeString(@Nullable String location) { + return new String[]{"%d Fairy Souls".formatted(FairySouls.getFairySoulsSize(location))}; } } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java index 7316577e..a52f288c 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java @@ -1,8 +1,8 @@ package me.xmrvizzy.skyblocker.skyblock.dwarven; -import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.skyblock.tabhud.widget.CommsWidget; +import me.xmrvizzy.skyblocker.utils.Scheduler; 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; @@ -45,7 +45,7 @@ public class DwarvenHud { ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") .then(ClientCommandManager.literal("hud") .then(ClientCommandManager.literal("dwarven") - .executes(context -> SkyblockerMod.getInstance().scheduler.queueOpenScreen(DwarvenHudConfigScreen::new)))))); + .executes(Scheduler.queueOpenScreenCommand(DwarvenHudConfigScreen::new)))))); HudRenderCallback.EVENT.register((context, tickDelta) -> { if (!SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.enabled diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/shortcut/Shortcuts.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/shortcut/Shortcuts.java index 44077b3e..36ff98c9 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/shortcut/Shortcuts.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/shortcut/Shortcuts.java @@ -7,6 +7,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.Scheduler; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; @@ -179,7 +180,7 @@ public class Shortcuts { } return Command.SINGLE_SUCCESS; // Queue the screen or else the screen will be immediately closed after executing this command - })).then(literal("shortcuts").executes(context -> SkyblockerMod.getInstance().scheduler.queueOpenScreen(ShortcutsConfigScreen::new)))); + })).then(literal("shortcuts").executes(Scheduler.queueOpenScreenCommand(ShortcutsConfigScreen::new)))); } private static String modifyCommand(String command) { |