diff options
author | msg-programs <msgdoesstuff@gmail.com> | 2023-08-14 18:18:00 +0200 |
---|---|---|
committer | msg-programs <msgdoesstuff@gmail.com> | 2023-08-14 18:18:00 +0200 |
commit | cfef2d401c80d58871c7d5c236946777d1915d00 (patch) | |
tree | 52f7eea8f0fb18bcc3327e098838fff07f61b8a1 /src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java | |
parent | 54133f9aa5d4b5134943d3e8d2916100ae7e1f3a (diff) | |
parent | ada74ef6b54168a1793c76bf3dd1c2c9d379c604 (diff) | |
download | Skyblocker-cfef2d401c80d58871c7d5c236946777d1915d00.tar.gz Skyblocker-cfef2d401c80d58871c7d5c236946777d1915d00.tar.bz2 Skyblocker-cfef2d401c80d58871c7d5c236946777d1915d00.zip |
Merge branch 'master' of https://github.com/SkyblockerMod/Skyblocker into json-tabhud
# Conflicts:
# src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java
Pull new upstream things into branch
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java | 17 |
1 files changed, 17 insertions, 0 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..b7c4ff2f 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; @@ -32,15 +33,31 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.lit public class FairySouls { private static final Logger LOGGER = LoggerFactory.getLogger(FairySouls.class); private static CompletableFuture<Void> fairySoulsLoaded; + private static int maxSouls = 0; 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 ? maxSouls : fairySouls.get(location).size(); + } + public static void init() { fairySoulsLoaded = NEURepo.runAsyncAfterLoad(() -> { 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")) { + maxSouls = fairySoulJson.getValue().getAsInt(); + } continue; } ImmutableSet.Builder<BlockPos> fairySoulsForLocation = ImmutableSet.builder(); |