diff options
author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-08-18 14:49:23 +0800 |
---|---|---|
committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2023-08-30 22:49:55 -0400 |
commit | 9c1cf95c32400a440309806fd954981e2f861018 (patch) | |
tree | db70346a001931d5be239e93213950452463e40f /src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets | |
parent | 6567b0d3819b3e2bbc0b272cbfc2858acc96fb50 (diff) | |
download | Skyblocker-9c1cf95c32400a440309806fd954981e2f861018.tar.gz Skyblocker-9c1cf95c32400a440309806fd954981e2f861018.tar.bz2 Skyblocker-9c1cf95c32400a440309806fd954981e2f861018.zip |
Fix dungeon start
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java | 54 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java | 36 |
2 files changed, 56 insertions, 34 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java index 310e0501..0043fc77 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java @@ -1,6 +1,7 @@ package me.xmrvizzy.skyblocker.skyblock.dungeon.secrets; import com.google.gson.JsonObject; +import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.IntSortedSet; import net.minecraft.block.MapColor; import net.minecraft.item.map.MapIcon; @@ -51,20 +52,49 @@ public class DungeonMapUtils { } @Nullable - public static Vector2ic getMapEntrancePos(MapState map) { - Vector2i mapPos = getMapPlayerPos(map); - DungeonSecrets.LOGGER.info("[Skyblocker] Trying to get dungeon map entrance pos from map player pos at {}", mapPos); // TODO remove - if (!isEntranceColor(map, mapPos)) { - return null; + public static Pair<Vector2ic, Integer> getMapEntrancePosAndRoomSize(@NotNull MapState map) { + Vector2ic mapPos = getMapPlayerPos(map); + Queue<Vector2ic> posToCheck = new ArrayDeque<>(); + Set<Vector2ic> checked = new HashSet<>(); + posToCheck.add(mapPos); + checked.add(mapPos); + while ((mapPos = posToCheck.poll()) != null) { + if (isEntranceColor(map, mapPos)) { + Pair<Vector2ic, Integer> mapEntranceAndRoomSizePos = getMapEntrancePosAndRoomSizeAt(map, mapPos); + if (mapEntranceAndRoomSizePos.right() > 0) { + return mapEntranceAndRoomSizePos; + } + } + Vector2ic pos = new Vector2i(mapPos).sub(10, 0); + if (checked.add(pos)) { + posToCheck.add(pos); + } + pos = new Vector2i(mapPos).sub(0, 10); + if (checked.add(pos)) { + posToCheck.add(pos); + } + pos = new Vector2i(mapPos).add(10, 0); + if (checked.add(pos)) { + posToCheck.add(pos); + } + pos = new Vector2i(mapPos).add(0, 10); + if (checked.add(pos)) { + posToCheck.add(pos); + } } - // noinspection StatementWithEmptyBody, DataFlowIssue + return null; + } + + private static Pair<Vector2ic, Integer> getMapEntrancePosAndRoomSizeAt(MapState map, Vector2ic mapPosImmutable) { + Vector2i mapPos = new Vector2i(mapPosImmutable); + // noinspection StatementWithEmptyBody while (isEntranceColor(map, mapPos.sub(1, 0))) { } mapPos.add(1, 0); //noinspection StatementWithEmptyBody while (isEntranceColor(map, mapPos.sub(0, 1))) { } - return mapPos.add(0, 1); + return Pair.of(mapPos.add(0, 1), getMapRoomSize(map, mapPos)); } public static int getMapRoomSize(MapState map, Vector2ic mapEntrancePos) { @@ -72,7 +102,7 @@ public class DungeonMapUtils { //noinspection StatementWithEmptyBody while (isEntranceColor(map, mapEntrancePos.x() + ++i, mapEntrancePos.y())) { } - return i; + return i > 5 ? i : 0; } /** @@ -111,14 +141,6 @@ public class DungeonMapUtils { return new Vector2i(physicalPos).sub(physicalEntrancePos).div(32).mul(mapRoomSize + 4).add(mapEntrancePos); } - @Nullable - public static Vector2ic getPhysicalEntrancePos(MapState map, @NotNull Vec3d playerPos) { - if (isEntranceColor(map, getMapPlayerPos(map))) { - return getPhysicalRoomPos(playerPos); - } - return null; - } - /** * @see #getPhysicalRoomPos(double, double) */ 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 5f3e9258..db1db452 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 @@ -3,6 +3,7 @@ package me.xmrvizzy.skyblocker.skyblock.dungeon.secrets; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.objects.Object2ByteMap; import it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap; import me.xmrvizzy.skyblocker.SkyblockerMod; @@ -188,9 +189,10 @@ public class DungeonSecrets { * <p></p> * When entering a new dungeon, this method: * <ul> + * <li> Gets the physical northwest corner position of the entrance room and saves it in {@link #physicalEntrancePos}. </li> + * <li> Do nothing until the dungeon map exists. </li> * <li> Gets the upper left corner of entrance room on the map and saves it in {@link #mapEntrancePos}. </li> * <li> Gets the size of a room on the map in pixels and saves it in {@link #mapRoomSize}. </li> - * <li> Gets the physical northwest corner position of the entrance room and saves it in {@link #physicalEntrancePos}. </li> * <li> Creates a new {@link Room} with {@link Room.Type} {@link Room.Type.ENTRANCE ENTRANCE} and sets {@link #currentRoom}. </li> * </ul> * When processing an existing dungeon, this method: @@ -222,6 +224,11 @@ public class DungeonSecrets { if (player == null || client.world == null) { return; } + if (physicalEntrancePos == null) { + Vec3d playerPos = player.getPos(); + physicalEntrancePos = DungeonMapUtils.getPhysicalRoomPos(playerPos); + currentRoom = newRoom(Room.Type.ENTRANCE, physicalEntrancePos); + } ItemStack stack = player.getInventory().main.get(8); if (!stack.isOf(Items.FILLED_MAP)) { return; @@ -230,31 +237,24 @@ public class DungeonSecrets { if (map == null) { return; } - if (mapEntrancePos == null && (mapEntrancePos = DungeonMapUtils.getMapEntrancePos(map)) == null) { - return; - } - if (mapRoomSize == 0 && (mapRoomSize = DungeonMapUtils.getMapRoomSize(map, mapEntrancePos)) == 0) { - return; - } - if (physicalEntrancePos == null) { - physicalEntrancePos = DungeonMapUtils.getPhysicalEntrancePos(map, player.getPos()); - if (physicalEntrancePos == null) { - player.sendMessage(Text.translatable("skyblocker.dungeons.secrets.physicalEntranceNotFound")); + if (mapEntrancePos == null || mapRoomSize == 0) { + Pair<Vector2ic, Integer> mapEntrancePosAndSize = DungeonMapUtils.getMapEntrancePosAndRoomSize(map); + if (mapEntrancePosAndSize == null) { return; - } else { - currentRoom = newRoom(Room.Type.ENTRANCE, physicalEntrancePos); - LOGGER.info("[Skyblocker] Started dungeon with map room size {}, map entrance pos {}, player pos {}, and physical entrance pos {}", mapRoomSize, mapEntrancePos, client.player.getPos(), physicalEntrancePos); } + mapEntrancePos = mapEntrancePosAndSize.left(); + mapRoomSize = mapEntrancePosAndSize.right(); + LOGGER.info("[Skyblocker] Started dungeon with map room size {}, map entrance pos {}, player pos {}, and physical entrance pos {}", mapRoomSize, mapEntrancePos, client.player.getPos(), physicalEntrancePos); } Vector2ic physicalPos = DungeonMapUtils.getPhysicalRoomPos(client.player.getPos()); Vector2ic mapPos = DungeonMapUtils.getMapPosFromPhysical(physicalEntrancePos, mapEntrancePos, mapRoomSize, physicalPos); - Room.Type type = DungeonMapUtils.getRoomType(map, mapPos); - if (type == null) { - return; - } Room room = rooms.get(physicalPos); if (room == null) { + Room.Type type = DungeonMapUtils.getRoomType(map, mapPos); + if (type == null || type == Room.Type.UNKNOWN) { + return; + } 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))); |