diff options
author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-08-02 13:12:29 +0800 |
---|---|---|
committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-08-06 19:02:36 +0800 |
commit | 43400f0a1bd0d4b2b0dd944d7a82019e37206c90 (patch) | |
tree | 06993bc66b8f269a7a88f6b9887555ddae3b0314 /src | |
parent | 87fca6d525c70c5e95122a3610916ad5f48cc4b8 (diff) | |
download | Skyblocker-43400f0a1bd0d4b2b0dd944d7a82019e37206c90.tar.gz Skyblocker-43400f0a1bd0d4b2b0dd944d7a82019e37206c90.tar.bz2 Skyblocker-43400f0a1bd0d4b2b0dd944d7a82019e37206c90.zip |
Refactor Trivia to use FairySouls
Diffstat (limited to 'src')
3 files changed, 39 insertions, 27 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java b/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java index bd414acb..1fd42f37 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java +++ b/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java @@ -73,6 +73,7 @@ public class SkyblockerMod implements ClientModInitializer { WikiLookup.init(); ItemRegistry.init(); NEURepo.init(); + FairySouls.init(); BackpackPreview.init(); QuickNav.init(); DwarvenHud.init(); @@ -81,7 +82,6 @@ public class SkyblockerMod implements ClientModInitializer { DiscordRPCManager.init(); LividColor.init(); FishingHelper.init(); - FairySouls.init(); TabHud.init(); DungeonMap.init(); TheRift.init(); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java index ccffdcca..dd8f20e7 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,14 @@ 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) { + 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/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))}; } } |