Skip to content

Commit

Permalink
Don't rely on class load order
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureAaron committed Oct 23, 2023
1 parent 1e5a48a commit c1b48b6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,60 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;

public class MirrorverseWaypoints {
private static final Logger LOGGER = LoggerFactory.getLogger("skyblocker");
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
private static final Identifier WAYPOINTS_JSON = new Identifier(SkyblockerMod.NAMESPACE, "rift/mirrorverse_waypoints.json");
private static final BlockPos[] LAVA_PATH_WAYPOINTS = new BlockPos[107];
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();

static {
loadWaypoints();
}

private static CompletableFuture<Void> waypointsLoaded;

/**
* Loads the waypoint locations into memory
*/
private static void loadWaypoints() {
try (BufferedReader reader = CLIENT.getResourceManager().openAsReader(WAYPOINTS_JSON)) {
JsonObject file = JsonParser.parseReader(reader).getAsJsonObject();
JsonArray sections = file.get("sections").getAsJsonArray();
static void load(MinecraftClient client) {
waypointsLoaded = CompletableFuture.runAsync(() -> {
try (BufferedReader reader = client.getResourceManager().openAsReader(WAYPOINTS_JSON)) {
JsonObject file = JsonParser.parseReader(reader).getAsJsonObject();
JsonArray sections = file.get("sections").getAsJsonArray();

/// Lava Path
JsonArray lavaPathWaypoints = sections.get(0).getAsJsonObject().get("waypoints").getAsJsonArray();
/// Lava Path
JsonArray lavaPathWaypoints = sections.get(0).getAsJsonObject().get("waypoints").getAsJsonArray();

for (int i = 0; i < lavaPathWaypoints.size(); i++) {
JsonObject point = lavaPathWaypoints.get(i).getAsJsonObject();
LAVA_PATH_WAYPOINTS[i] = new BlockPos(point.get("x").getAsInt(), point.get("y").getAsInt(), point.get("z").getAsInt());
}
for (int i = 0; i < lavaPathWaypoints.size(); i++) {
JsonObject point = lavaPathWaypoints.get(i).getAsJsonObject();
LAVA_PATH_WAYPOINTS[i] = new BlockPos(point.get("x").getAsInt(), point.get("y").getAsInt(), point.get("z").getAsInt());
}

/// Upside Down Parkour
JsonArray upsideDownParkourWaypoints = sections.get(1).getAsJsonObject().get("waypoints").getAsJsonArray();
/// Upside Down Parkour
JsonArray upsideDownParkourWaypoints = sections.get(1).getAsJsonObject().get("waypoints").getAsJsonArray();

for (int i = 0; i < upsideDownParkourWaypoints.size(); i++) {
JsonObject point = upsideDownParkourWaypoints.get(i).getAsJsonObject();
UPSIDE_DOWN_WAYPOINTS[i] = new BlockPos(point.get("x").getAsInt(), point.get("y").getAsInt(), point.get("z").getAsInt());
}
for (int i = 0; i < upsideDownParkourWaypoints.size(); i++) {
JsonObject point = upsideDownParkourWaypoints.get(i).getAsJsonObject();
UPSIDE_DOWN_WAYPOINTS[i] = new BlockPos(point.get("x").getAsInt(), point.get("y").getAsInt(), point.get("z").getAsInt());
}

/// Turbulator Parkour
JsonArray turbulatorParkourWaypoints = sections.get(2).getAsJsonObject().get("waypoints").getAsJsonArray();
/// Turbulator Parkour
JsonArray turbulatorParkourWaypoints = sections.get(2).getAsJsonObject().get("waypoints").getAsJsonArray();

for (int i = 0; i < turbulatorParkourWaypoints.size(); i++) {
JsonObject point = turbulatorParkourWaypoints.get(i).getAsJsonObject();
TURBULATOR_WAYPOINTS[i] = new BlockPos(point.get("x").getAsInt(), point.get("y").getAsInt(), point.get("z").getAsInt());
for (int i = 0; i < turbulatorParkourWaypoints.size(); i++) {
JsonObject point = turbulatorParkourWaypoints.get(i).getAsJsonObject();
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();
}

} catch (IOException e) {
LOGGER.info("[Skyblocker] Mirrorverse Waypoints failed to load ;(");
e.printStackTrace();
}
});
}

protected static void render(WorldRenderContext wrc) {
//I would also check for the mirrorverse location but the scoreboard stuff is not performant at all...
if (Utils.isInTheRift() && SkyblockerConfigManager.get().locations.rift.mirrorverseWaypoints) {
if (Utils.isInTheRift() && SkyblockerConfigManager.get().locations.rift.mirrorverseWaypoints && waypointsLoaded.isDone()) {
for (BlockPos pos : LAVA_PATH_WAYPOINTS) {
RenderHelper.renderFilledIfVisible(wrc, pos, COLOR_COMPONENTS, 0.5f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static void init() {
WorldRenderEvents.AFTER_TRANSLUCENT.register(MirrorverseWaypoints::render);
WorldRenderEvents.AFTER_TRANSLUCENT.register(EffigyWaypoints::render);
WorldRenderEvents.AFTER_TRANSLUCENT.register(EnigmaSouls::render);
ClientLifecycleEvents.CLIENT_STARTED.register(MirrorverseWaypoints::load);
ClientLifecycleEvents.CLIENT_STARTED.register(EnigmaSouls::load);
ClientLifecycleEvents.CLIENT_STOPPING.register(EnigmaSouls::save);
ClientReceiveMessageEvents.GAME.register(EnigmaSouls::onMessage);
Expand Down

0 comments on commit c1b48b6

Please sign in to comment.