aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-07-31 12:17:20 +0800
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-08-30 22:49:53 -0400
commit7257ed162b44bcbe49241d4177e25981bdb32092 (patch)
treefb279060c71f8dea5790ca680cea89493b905470 /src
parentdc6efd3ae6f62f24d6f243df284b84110d8a2bb5 (diff)
downloadSkyblocker-7257ed162b44bcbe49241d4177e25981bdb32092.tar.gz
Skyblocker-7257ed162b44bcbe49241d4177e25981bdb32092.tar.bz2
Skyblocker-7257ed162b44bcbe49241d4177e25981bdb32092.zip
Add secrets resetting
Diffstat (limited to 'src')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java2
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java39
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/Room.java2
-rw-r--r--src/main/resources/assets/skyblocker/lang/en_us.json4
4 files changed, 35 insertions, 12 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java
index c7b84b25..8da4bb41 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java
@@ -408,7 +408,7 @@ public class SkyblockerConfig implements ConfigData {
public static class Dungeons {
public boolean secretWaypoints = true;
- public boolean noLoadSecretWaypoints = false;
+ public boolean noInitSecretWaypoints = false;
@ConfigEntry.Gui.Tooltip()
public boolean croesusHelper = true;
public boolean enableMap = true;
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java
index 94529726..7c0a0afb 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java
@@ -16,6 +16,7 @@ import net.minecraft.item.Items;
import net.minecraft.item.map.MapState;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector2ic;
import org.slf4j.Logger;
@@ -79,6 +80,7 @@ public class DungeonSecrets {
/**
* The map position of the top left corner of the entrance room.
*/
+ @Nullable
private static Vector2ic mapEntrancePos;
/**
* The size of a room on the map.
@@ -87,7 +89,9 @@ public class DungeonSecrets {
/**
* The physical position of the northwest corner of the entrance room.
*/
+ @Nullable
private static Vector2ic physicalEntrancePos;
+ @NotNull
private static final Map<Vector2ic, Room> rooms = new HashMap<>();
private static Room currentRoom;
@@ -108,7 +112,7 @@ public class DungeonSecrets {
* Use {@link #isRoomsLoaded()} to check for completion of loading.
*/
public static void init() {
- if (SkyblockerConfig.get().locations.dungeons.noLoadSecretWaypoints) {
+ if (SkyblockerConfig.get().locations.dungeons.noInitSecretWaypoints) {
return;
}
CompletableFuture.runAsync(DungeonSecrets::load);
@@ -186,7 +190,13 @@ public class DungeonSecrets {
private static void update() {
long startTime = System.currentTimeMillis();
- if (!SkyblockerConfig.get().locations.dungeons.secretWaypoints || !Utils.isInDungeons()) {
+ if (!SkyblockerConfig.get().locations.dungeons.secretWaypoints) {
+ return;
+ }
+ if (!Utils.isInDungeons()) {
+ if (mapEntrancePos != null) {
+ reset();
+ }
return;
}
MinecraftClient client = MinecraftClient.getInstance();
@@ -229,8 +239,7 @@ public class DungeonSecrets {
if (room == null) {
switch (type) {
case ENTRANCE, PUZZLE, TRAP, MINIBOSS, FAIRY, BLOOD -> room = newRoom(type, physicalPos);
- case ROOM ->
- room = newRoom(type, DungeonMapUtils.getPhysicalPosFromMap(mapEntrancePos, mapRoomSize, physicalEntrancePos, DungeonMapUtils.getRoomSegments(map, mapPos, mapRoomSize, type.color)));
+ case ROOM -> room = newRoom(type, DungeonMapUtils.getPhysicalPosFromMap(mapEntrancePos, mapRoomSize, physicalEntrancePos, DungeonMapUtils.getRoomSegments(map, mapPos, mapRoomSize, type.color)));
}
}
if (room != null && currentRoom != room) {
@@ -248,12 +257,18 @@ public class DungeonSecrets {
* @param type the type of room to create
* @param physicalPositions the physical positions of the room
*/
+ @Nullable
private static Room newRoom(Room.Type type, Vector2ic... physicalPositions) {
- Room newRoom = new Room(type, physicalPositions);
- for (Vector2ic physicalPos : physicalPositions) {
- rooms.put(physicalPos, newRoom);
+ try {
+ Room newRoom = new Room(type, physicalPositions);
+ for (Vector2ic physicalPos : physicalPositions) {
+ rooms.put(physicalPos, newRoom);
+ }
+ return newRoom;
+ } catch (IllegalArgumentException e) {
+ LOGGER.error("[Skyblocker] Failed to create room", e);
}
- return newRoom;
+ return null;
}
private static void render(WorldRenderContext context) {
@@ -261,4 +276,12 @@ public class DungeonSecrets {
currentRoom.render(context);
}
}
+
+ private static void reset() {
+ mapEntrancePos = null;
+ mapRoomSize = 0;
+ physicalEntrancePos = null;
+ rooms.clear();
+ currentRoom = null;
+ }
}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/Room.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/Room.java
index 84510997..0eae2793 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/Room.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/Room.java
@@ -97,7 +97,7 @@ public class Room {
} else if (segmentsX.size() == 1 && segmentsY.size() > 1) {
yield new Direction[]{Direction.NE, Direction.SW};
}
- throw new IllegalStateException("Shape " + shape.shape + " does not match segments: " + Arrays.toString(segments.toArray()));
+ throw new IllegalArgumentException("Shape " + shape.shape + " does not match segments: " + Arrays.toString(segments.toArray()));
}
case L_SHAPE -> {
if (!segments.contains(new Vector2i(segmentsX.firstInt(), segmentsY.firstInt()))) {
diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json
index 90dfa3b9..842c4591 100644
--- a/src/main/resources/assets/skyblocker/lang/en_us.json
+++ b/src/main/resources/assets/skyblocker/lang/en_us.json
@@ -199,8 +199,8 @@
"text.autoconfig.skyblocker.option.locations.barn.solveTreasureHunter": "Solve Treasure Hunter",
"text.autoconfig.skyblocker.option.locations.dungeons": "Dungeons",
"text.autoconfig.skyblocker.option.locations.dungeons.secretWaypoints": "Dungeon Secret Waypoints",
- "text.autoconfig.skyblocker.option.locations.dungeons.noLoadSecretWaypoints": "Not Load Secret Waypoints",
- "text.autoconfig.skyblocker.option.locations.dungeons.noLoadSecretWaypoints.@Tooltip": "This option can save around 20 MB of ram if enabled, but Secret Waypoint will require a restart after turning off this option to work.",
+ "text.autoconfig.skyblocker.option.locations.dungeons.noInitSecretWaypoints": "Do Not Initialize Secret Waypoints",
+ "text.autoconfig.skyblocker.option.locations.dungeons.noInitSecretWaypoints.@Tooltip": "This option can save around 20 MB of ram if enabled, but Secret Waypoint will require a restart after turning off this option to work.",
"text.autoconfig.skyblocker.option.locations.dungeons.croesusHelper": "Croesus Helper",
"text.autoconfig.skyblocker.option.locations.dungeons.croesusHelper.@Tooltip": "Gray out chests that have already been opened.",
"text.autoconfig.skyblocker.option.locations.dungeons.enableMap": "Enable Map",