aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-10-22 22:35:01 -0400
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-10-22 22:35:01 -0400
commita9d8ff4284abe0342970e3a4b6a19c19d944564e (patch)
tree9e2fb762a4785e50e2412d2f5379ab4f210243da /src/main/java/de/hysky/skyblocker/skyblock
parentc1b48b603318cc419f14ed56070a3c71996ffdba (diff)
downloadSkyblocker-a9d8ff4284abe0342970e3a4b6a19c19d944564e.tar.gz
Skyblocker-a9d8ff4284abe0342970e3a4b6a19c19d944564e.tar.bz2
Skyblocker-a9d8ff4284abe0342970e3a4b6a19c19d944564e.zip
Refactor EnigmaSouls and MirrorverseWaypoints
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/rift/EnigmaSouls.java63
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/rift/MirrorverseWaypoints.java5
2 files changed, 33 insertions, 35 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/rift/EnigmaSouls.java b/src/main/java/de/hysky/skyblocker/skyblock/rift/EnigmaSouls.java
index 3a0651ef..744edd4c 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/rift/EnigmaSouls.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/rift/EnigmaSouls.java
@@ -52,66 +52,66 @@ public class EnigmaSouls {
private static final Object2ObjectOpenHashMap<String, ObjectOpenHashSet<BlockPos>> FOUND_SOULS = new Object2ObjectOpenHashMap<>();
private static final float[] GREEN = DyeColor.GREEN.getColorComponents();
private static final float[] RED = DyeColor.RED.getColorComponents();
-
+
private static CompletableFuture<Void> soulsLoaded;
-
+
static void load(MinecraftClient client) {
//Load waypoints
soulsLoaded = CompletableFuture.runAsync(() -> {
try (BufferedReader reader = client.getResourceManager().openAsReader(WAYPOINTS_JSON)) {
JsonObject file = JsonParser.parseReader(reader).getAsJsonObject();
JsonArray waypoints = file.get("waypoints").getAsJsonArray();
-
+
for (int i = 0; i < waypoints.size(); i++) {
JsonObject waypoint = waypoints.get(i).getAsJsonObject();
SOUL_WAYPOINTS[i] = new BlockPos(waypoint.get("x").getAsInt(), waypoint.get("y").getAsInt(), waypoint.get("z").getAsInt());
}
-
+
} catch (IOException e) {
- LOGGER.error("[Skyblocker] There was an error while loading enigma soul waypoints! Exception: {}", e);
+ LOGGER.error("[Skyblocker] There was an error while loading enigma soul waypoints!", e);
}
-
+
//Load found souls
try (BufferedReader reader = Files.newBufferedReader(FOUND_SOULS_FILE)) {
for (Map.Entry<String, JsonElement> profile : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) {
ObjectOpenHashSet<BlockPos> foundSoulsOnProfile = new ObjectOpenHashSet<>();
-
+
for (JsonElement foundSoul : profile.getValue().getAsJsonArray().asList()) {
foundSoulsOnProfile.add(PosUtils.parsePosString(foundSoul.getAsString()));
}
-
+
FOUND_SOULS.put(profile.getKey(), foundSoulsOnProfile);
}
} catch (NoSuchFileException ignored) {
} catch (IOException e) {
- LOGGER.error("[Skyblocker] There was an error while loading found enigma souls! Exception: {}", e);
+ LOGGER.error("[Skyblocker] There was an error while loading found enigma souls!", e);
}
});
}
-
+
static void save(MinecraftClient client) {
JsonObject json = new JsonObject();
-
+
for (Map.Entry<String, ObjectOpenHashSet<BlockPos>> foundSoulsForProfile : FOUND_SOULS.entrySet()) {
JsonArray foundSoulsJson = new JsonArray();
-
+
for (BlockPos foundSoul : foundSoulsForProfile.getValue()) {
foundSoulsJson.add(PosUtils.getPosString(foundSoul));
}
-
+
json.add(foundSoulsForProfile.getKey(), foundSoulsJson);
}
-
+
try (BufferedWriter writer = Files.newBufferedWriter(FOUND_SOULS_FILE)) {
SkyblockerMod.GSON.toJson(json, writer);
} catch (IOException e) {
- LOGGER.error("[Skyblocker] There was an error while saving found enigma souls! Exception: {}", e);
+ LOGGER.error("[Skyblocker] There was an error while saving found enigma souls!", e);
}
}
-
+
static void render(WorldRenderContext wrc) {
SkyblockerConfig.Rift config = SkyblockerConfigManager.get().locations.rift;
-
+
if (Utils.isInTheRift() && config.enigmaSoulWaypoints && soulsLoaded.isDone()) {
for (BlockPos pos : SOUL_WAYPOINTS) {
if (isSoulMissing(pos)) {
@@ -122,15 +122,15 @@ public class EnigmaSouls {
}
}
}
-
+
static void onMessage(Text text, boolean overlay) {
if (Utils.isInTheRift() && !overlay) {
String message = text.getString();
-
+
if (message.equals("You have already found that Enigma Soul!") || Formatting.strip(message).equals("SOUL! You unlocked an Enigma Soul!")) markClosestSoulAsFound();
}
}
-
+
static void registerCommands(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
dispatcher.register(literal(SkyblockerMod.NAMESPACE)
.then(literal("rift")
@@ -138,23 +138,22 @@ public class EnigmaSouls {
.then(literal("markAllFound").executes(context -> {
markAllFound();
context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.rift.enigmaSouls.markAllFound")));
-
+
return Command.SINGLE_SUCCESS;
}))
.then(literal("markAllMissing").executes(context -> {
markAllMissing();
context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.rift.enigmaSouls.markAllMissing")));
-
+
return Command.SINGLE_SUCCESS;
})))));
}
-
- @SuppressWarnings("resource")
+
private static void markClosestSoulAsFound() {
- if (!soulsLoaded.isDone()) return;
-
ClientPlayerEntity player = MinecraftClient.getInstance().player;
-
+
+ if (!soulsLoaded.isDone() || player == null) return;
+
Arrays.stream(SOUL_WAYPOINTS)
.filter(EnigmaSouls::isSoulMissing)
.min(Comparator.comparingDouble(soulPos -> soulPos.getSquaredDistance(player.getPos())))
@@ -164,21 +163,21 @@ public class EnigmaSouls {
FOUND_SOULS.get(Utils.getProfile()).add(soulPos);
});
}
-
+
private static boolean isSoulMissing(BlockPos soulPos) {
ObjectOpenHashSet<BlockPos> foundSoulsOnProfile = FOUND_SOULS.get(Utils.getProfile());
-
+
return foundSoulsOnProfile == null || !foundSoulsOnProfile.contains(soulPos);
}
-
+
private static void markAllFound() {
FOUND_SOULS.computeIfAbsent(Utils.getProfile(), profile -> new ObjectOpenHashSet<>());
FOUND_SOULS.get(Utils.getProfile()).addAll(List.of(SOUL_WAYPOINTS));
}
-
+
private static void markAllMissing() {
ObjectOpenHashSet<BlockPos> foundSoulsOnProfile = FOUND_SOULS.get(Utils.getProfile());
-
+
if (foundSoulsOnProfile != null) foundSoulsOnProfile.clear();
}
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/rift/MirrorverseWaypoints.java b/src/main/java/de/hysky/skyblocker/skyblock/rift/MirrorverseWaypoints.java
index e7c62629..7dda741f 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/rift/MirrorverseWaypoints.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/rift/MirrorverseWaypoints.java
@@ -26,7 +26,7 @@ public class MirrorverseWaypoints {
private static final BlockPos[] UPSIDE_DOWN_WAYPOINTS = new BlockPos[66];
private static final BlockPos[] TURBULATOR_WAYPOINTS = new BlockPos[27];
private static final float[] COLOR_COMPONENTS = DyeColor.RED.getColorComponents();
-
+
private static CompletableFuture<Void> waypointsLoaded;
/**
@@ -62,8 +62,7 @@ public class MirrorverseWaypoints {
TURBULATOR_WAYPOINTS[i] = new BlockPos(point.get("x").getAsInt(), point.get("y").getAsInt(), point.get("z").getAsInt());
}
} catch (IOException e) {
- LOGGER.info("[Skyblocker] Mirrorverse Waypoints failed to load ;(");
- e.printStackTrace();
+ LOGGER.error("[Skyblocker] Mirrorverse Waypoints failed to load ;(", e);
}
});
}