From bd787c213029185ad07b5b9a281ab289b0b102cb Mon Sep 17 00:00:00 2001 From: daroche <94007359+GatienDoesStuff@users.noreply.github.com> Date: Tue, 6 Aug 2024 20:31:14 +0200 Subject: Apply suggestions. Also threw in an extra comment regarding map colors, and fixed `doorPos` being `doorpos`. --- .../skyblock/dungeon/secrets/DungeonManager.java | 34 ++++++++---------- .../skyblock/dungeon/secrets/DungeonMapUtils.java | 42 ++++++++++------------ .../skyblocker/skyblock/dungeon/secrets/Room.java | 3 +- 3 files changed, 33 insertions(+), 46 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonManager.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonManager.java index 69b64f4e..fbe99909 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonManager.java @@ -94,6 +94,8 @@ public class DungeonManager { private static final Pattern KEY_FOUND = Pattern.compile("^RIGHT CLICK on (?:the BLOOD DOOR|a WITHER door) to open it. This key can only be used to open 1 door!$"); private static final Pattern WITHER_DOOR_OPENED = Pattern.compile("^\\w+ opened a WITHER door!$"); private static final String BLOOD_DOOR_OPENED = "The BLOOD DOOR has been opened!"; + protected static final float[] RED_COLOR_COMPONENTS = {1, 0, 0}; + protected static final float[] GREEN_COLOR_COMPONENTS = {0, 1, 0}; /** * Maps the block identifier string to a custom numeric block id used in dungeon rooms data. * @@ -159,8 +161,6 @@ public class DungeonManager { @Nullable private static Box bloodRushDoorBox; private static boolean bloodOpened; - protected static final float[] RED_COLOR_COMPONENTS = {1, 0, 0}; - protected static final float[] GREEN_COLOR_COMPONENTS = {0, 1, 0}; private static boolean hasKey; public static boolean isRoomsLoaded() { @@ -561,7 +561,7 @@ public class DungeonManager { LOGGER.info("[Skyblocker Dungeon Secrets] Started dungeon with map room size {}, map entrance pos {}, player pos {}, and physical entrance pos {}", mapRoomSize, mapEntrancePos, client.player.getPos(), physicalEntrancePos); } - getBloodRushDoorPos(); + getBloodRushDoorPos(map); Vector2ic physicalPos = DungeonMapUtils.getPhysicalRoomPos(client.player.getPos()); Vector2ic mapPos = DungeonMapUtils.getMapPosFromPhysical(physicalEntrancePos, mapEntrancePos, mapRoomSize, physicalPos); @@ -573,8 +573,7 @@ public class DungeonManager { } 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) { @@ -784,24 +783,19 @@ public class DungeonManager { * * @implNote Relies on the minimap to check for doors */ - private static void getBloodRushDoorPos() { - MinecraftClient client = MinecraftClient.getInstance(); - if (client.player == null || client.world == null) { - return; - } - - MapState map = FilledMapItem.getMapState(DungeonMap.getMapIdComponent(client.player.getInventory().main.get(8)), client.world); - if (map == null || mapEntrancePos == null || mapRoomSize == 0) { - LOGGER.error("[Skyblocker Dungeon Secrets] Failed to get map state."); + private static void getBloodRushDoorPos(@NotNull MapState map) { + if (mapEntrancePos == null || mapRoomSize == 0) { + LOGGER.error("[Skyblocker Dungeon Secrets] Dungeon map info missing with map entrance pos {} and map room size {}", mapEntrancePos, mapRoomSize); return; } Vector2i nWMostRoom = getMapPosForNWMostRoom(mapEntrancePos, mapRoomSize); - for (int x = nWMostRoom.x + mapRoomSize / 2; x < 127; x += mapRoomSize + 4) { - for (int y = nWMostRoom.y + mapRoomSize; y < 127; y += mapRoomSize + 4) { + for (int x = nWMostRoom.x + mapRoomSize / 2; x < 128; x += mapRoomSize + 4) { + for (int y = nWMostRoom.y + mapRoomSize; y < 128; y += mapRoomSize + 4) { byte color = getColor(map, x, y); + // 119 is the black found on wither doors on the map, 18 is the blood door red if (color == 119 || color == 18) { Vector2ic doorPos = getPhysicalPosFromMap(mapEntrancePos, mapRoomSize, physicalEntrancePos, new Vector2i(x - mapRoomSize / 2, y - mapRoomSize)); bloodRushDoorBox = new Box(doorPos.x() + 14, 69, doorPos.y() + 30, doorPos.x() + 17, 73, doorPos.y() + 33); @@ -811,13 +805,13 @@ public class DungeonManager { } } - for (int x = nWMostRoom.x + mapRoomSize; x < 127; x += mapRoomSize + 4) { - for (int y = nWMostRoom.y + mapRoomSize / 2; y < 127; y += mapRoomSize + 4) { + for (int x = nWMostRoom.x + mapRoomSize; x < 128; x += mapRoomSize + 4) { + for (int y = nWMostRoom.y + mapRoomSize / 2; y < 128; y += mapRoomSize + 4) { byte color = getColor(map, x, y); if (color == 119 || color == 18) { - Vector2ic doorpos = getPhysicalPosFromMap(mapEntrancePos, mapRoomSize, physicalEntrancePos, new Vector2i(x - mapRoomSize, y - mapRoomSize / 2)); - bloodRushDoorBox = new Box(doorpos.x() + 30, 69, doorpos.y() + 14, doorpos.x() + 33, 73, doorpos.y() + 17); + Vector2ic doorPos = getPhysicalPosFromMap(mapEntrancePos, mapRoomSize, physicalEntrancePos, new Vector2i(x - mapRoomSize, y - mapRoomSize / 2)); + bloodRushDoorBox = new Box(doorPos.x() + 30, 69, doorPos.y() + 14, doorPos.x() + 33, 73, doorPos.y() + 17); return; } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java index 5b84cd7a..ca63d971 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java @@ -144,6 +144,18 @@ public class DungeonMapUtils { return new Vector2i(physicalPos).sub(physicalEntrancePos).div(32).mul(mapRoomSize + 4).add(mapEntrancePos); } + /** + * Gets the map pos for the room that could be the furthest north-west on the map + * (doesn't mean the room has to exist, it's just the furthest possible room) + * + * @param mapEntrancePos The map pos of the entrance room + * @param mapRoomSize The size of a room on the map + * @return The map pos for the room that could be the furthest north-east on the map + */ + public static Vector2i getMapPosForNWMostRoom(Vector2ic mapEntrancePos, int mapRoomSize) { + return new Vector2i(Math.floorMod(mapEntrancePos.x(), (mapRoomSize + 4)), Math.floorMod(mapEntrancePos.y(), (mapRoomSize + 4))); + } + /** * @see #getPhysicalRoomPos(double, double) */ @@ -176,18 +188,6 @@ public class DungeonMapUtils { return physicalPos.sub(Math.floorMod(physicalPos.x(), 32), Math.floorMod(physicalPos.y(), 32)).sub(8, 8); } - /** - * Gets the map pos for the room that could be the furthest north-west on the map - * (doesn't mean the room has to exist, it's just the furthest possible room) - * - * @param mapEntrancePos The map pos of the entrance room - * @param mapRoomSize The size of a room on the map - * @return The map pos for the room that could be the furthest north-east on the map - */ - public static Vector2i getMapPosForNWMostRoom(Vector2ic mapEntrancePos, int mapRoomSize) { - return new Vector2i(Math.floorMod(mapEntrancePos.x(), (mapRoomSize + 4)), Math.floorMod(mapEntrancePos.y(), (mapRoomSize + 4))); - } - public static Vector2ic[] getPhysicalPosFromMap(Vector2ic mapEntrancePos, int mapRoomSize, Vector2ic physicalEntrancePos, Vector2ic... mapPositions) { for (int i = 0; i < mapPositions.length; i++) { mapPositions[i] = getPhysicalPosFromMap(mapEntrancePos, mapRoomSize, physicalEntrancePos, mapPositions[i]); @@ -220,12 +220,9 @@ public class DungeonMapUtils { public static BlockPos actualToRelative(Room.Direction direction, Vector2ic physicalCornerPos, BlockPos pos) { return switch (direction) { case NW -> new BlockPos(pos.getX() - physicalCornerPos.x(), pos.getY(), pos.getZ() - physicalCornerPos.y()); - case NE -> - new BlockPos(pos.getZ() - physicalCornerPos.y(), pos.getY(), -pos.getX() + physicalCornerPos.x()); - case SW -> - new BlockPos(-pos.getZ() + physicalCornerPos.y(), pos.getY(), pos.getX() - physicalCornerPos.x()); - case SE -> - new BlockPos(-pos.getX() + physicalCornerPos.x(), pos.getY(), -pos.getZ() + physicalCornerPos.y()); + case NE -> new BlockPos(pos.getZ() - physicalCornerPos.y(), pos.getY(), -pos.getX() + physicalCornerPos.x()); + case SW -> new BlockPos(-pos.getZ() + physicalCornerPos.y(), pos.getY(), pos.getX() - physicalCornerPos.x()); + case SE -> new BlockPos(-pos.getX() + physicalCornerPos.x(), pos.getY(), -pos.getZ() + physicalCornerPos.y()); }; } @@ -236,12 +233,9 @@ public class DungeonMapUtils { public static BlockPos relativeToActual(Room.Direction direction, Vector2ic physicalCornerPos, BlockPos pos) { return switch (direction) { case NW -> new BlockPos(pos.getX() + physicalCornerPos.x(), pos.getY(), pos.getZ() + physicalCornerPos.y()); - case NE -> - new BlockPos(-pos.getZ() + physicalCornerPos.x(), pos.getY(), pos.getX() + physicalCornerPos.y()); - case SW -> - new BlockPos(pos.getZ() + physicalCornerPos.x(), pos.getY(), -pos.getX() + physicalCornerPos.y()); - case SE -> - new BlockPos(-pos.getX() + physicalCornerPos.x(), pos.getY(), -pos.getZ() + physicalCornerPos.y()); + case NE -> new BlockPos(-pos.getZ() + physicalCornerPos.x(), pos.getY(), pos.getX() + physicalCornerPos.y()); + case SW -> new BlockPos(pos.getZ() + physicalCornerPos.x(), pos.getY(), -pos.getX() + physicalCornerPos.y()); + case SE -> new BlockPos(-pos.getX() + physicalCornerPos.x(), pos.getY(), -pos.getZ() + physicalCornerPos.y()); }; } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java index 10ce5ca7..1f4f9ed6 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java @@ -145,8 +145,7 @@ public class Room implements Tickable, Renderable { case 2 -> Shape.ONE_BY_TWO; case 3 -> segmentsX.size() == 2 && segmentsY.size() == 2 ? Shape.L_SHAPE : Shape.ONE_BY_THREE; case 4 -> segmentsX.size() == 2 && segmentsY.size() == 2 ? Shape.TWO_BY_TWO : Shape.ONE_BY_FOUR; - default -> - throw new IllegalArgumentException("There are no matching room shapes with this set of physical positions: " + Arrays.toString(segments.toArray())); + default -> throw new IllegalArgumentException("There are no matching room shapes with this set of physical positions: " + Arrays.toString(segments.toArray())); }; }; } -- cgit