aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonMapUtils.java3
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java19
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java34
3 files changed, 34 insertions, 22 deletions
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 259cc3f3..73d4a452 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
@@ -7,7 +7,6 @@ import net.minecraft.block.MapColor;
import net.minecraft.item.map.MapIcon;
import net.minecraft.item.map.MapState;
import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;
import org.jetbrains.annotations.NotNull;
@@ -173,7 +172,7 @@ public class DungeonMapUtils {
@NotNull
public static Vector2ic getPhysicalRoomPos(double x, double z) {
Vector2i physicalPos = new Vector2i(x + 8.5, z + 8.5, RoundingMode.TRUNCATE);
- return physicalPos.sub(MathHelper.floorMod(physicalPos.x(), 32), MathHelper.floorMod(physicalPos.y(), 32)).sub(8, 8);
+ return physicalPos.sub(Math.floorMod(physicalPos.x(), 32), Math.floorMod(physicalPos.y(), 32)).sub(8, 8);
}
public static Vector2ic[] getPhysicalPosFromMap(Vector2ic mapEntrancePos, int mapRoomSize, Vector2ic physicalEntrancePos, Vector2ic... mapPositions) {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java
index 07cb0395..08b84852 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java
@@ -40,6 +40,7 @@ import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
+import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
@@ -242,8 +243,9 @@ public class DungeonSecrets {
}
private static int getRelativePos(FabricClientCommandSource source, BlockPos pos) {
- if (isCurrentRoomMatched()) {
- BlockPos relativePos = DungeonMapUtils.actualToRelative(currentRoom.getDirection(), currentRoom.getPhysicalCornerPos(), pos);
+ Room room = getRoomAtPhysical(pos);
+ if (isRoomMatched(room)) {
+ BlockPos relativePos = currentRoom.actualToRelative(pos);
source.sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.posMessage", currentRoom.getName(), relativePos.getX(), relativePos.getY(), relativePos.getZ())));
} else {
source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.notMatched")));
@@ -446,6 +448,19 @@ public class DungeonSecrets {
}
/**
+ * Gets the room at the given physical position.
+ *
+ * @param pos the physical position
+ * @return the room at the given physical position, or null if there is no room at the given physical position
+ * @see #rooms
+ * @see DungeonMapUtils#getPhysicalRoomPos(Vec3i)
+ */
+ @Nullable
+ private static Room getRoomAtPhysical(Vec3i pos) {
+ return rooms.get(DungeonMapUtils.getPhysicalRoomPos(pos));
+ }
+
+ /**
* Calls {@link #isRoomMatched(Room)} on {@link #currentRoom}.
*
* @return {@code true} if {@link #currentRoom} is not null and {@link #isRoomMatched(Room)}
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 8d8d0757..0d7a444f 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
@@ -23,7 +23,6 @@ import net.minecraft.entity.mob.AmbientEntity;
import net.minecraft.registry.Registries;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.MutableTriple;
import org.apache.commons.lang3.tuple.Triple;
@@ -74,7 +73,6 @@ public class Room {
private Table<Integer, BlockPos, SecretWaypoint> secretWaypoints;
private String name;
private Direction direction;
-
private Vector2ic physicalCornerPos;
public Room(@NotNull Type type, @NotNull Vector2ic... physicalPositions) {
@@ -103,20 +101,6 @@ public class Room {
return name;
}
- /**
- * Not null if {@link #isMatched()}.
- */
- public Direction getDirection() {
- return direction;
- }
-
- /**
- * Not null if {@link #isMatched()}.
- */
- public Vector2ic getPhysicalCornerPos() {
- return physicalCornerPos;
- }
-
@Override
public String toString() {
return "Room{type=" + type + ", shape=" + shape + ", matched=" + matched + ", segments=" + Arrays.toString(segments.toArray()) + "}";
@@ -211,8 +195,8 @@ public class Room {
if (pos.getY() < 66 || pos.getY() > 73) {
return true;
}
- int x = MathHelper.floorMod(pos.getX() - 8, 32);
- int z = MathHelper.floorMod(pos.getZ() - 8, 32);
+ int x = Math.floorMod(pos.getX() - 8, 32);
+ int z = Math.floorMod(pos.getZ() - 8, 32);
return (x < 13 || x > 17 || z > 2 && z < 28) && (z < 13 || z > 17 || x > 2 && x < 28);
}
@@ -352,6 +336,20 @@ public class Room {
}
/**
+ * Fails if !{@link #isMatched()}
+ */
+ protected BlockPos actualToRelative(BlockPos pos) {
+ return DungeonMapUtils.actualToRelative(direction, physicalCornerPos, pos);
+ }
+
+ /**
+ * Fails if !{@link #isMatched()}
+ */
+ protected BlockPos relativeToActual(BlockPos pos) {
+ return DungeonMapUtils.relativeToActual(direction, physicalCornerPos, pos);
+ }
+
+ /**
* Calls {@link SecretWaypoint#render(WorldRenderContext)} on {@link #secretWaypoints all secret waypoints}.
*/
protected void render(WorldRenderContext context) {