diff --git a/common/src/main/java/io/github/flemmli97/flan/event/EntityInteractEvents.java b/common/src/main/java/io/github/flemmli97/flan/event/EntityInteractEvents.java index 1cc33b2..c951a52 100644 --- a/common/src/main/java/io/github/flemmli97/flan/event/EntityInteractEvents.java +++ b/common/src/main/java/io/github/flemmli97/flan/event/EntityInteractEvents.java @@ -327,7 +327,8 @@ public class EntityInteractEvents { if (!player.isSpectator()) { BlockPos.MutableBlockPos bPos = rounded.mutable(); if (!currentClaim.canInteract(player, PermissionRegistry.CANSTAY, bPos, true)) { - Vec3 tp = TeleportUtils.getTeleportPos(player, pos, storage, currentClaim.getDimensions(), bPos, (claim, nPos) -> claim.canInteract(player, PermissionRegistry.CANSTAY, nPos, false)); + Claim sub = currentClaim.getSubClaim(bPos); + Vec3 tp = TeleportUtils.getTeleportPos(player, pos, storage, sub != null ? sub.getDimensions() : currentClaim.getDimensions(), true, bPos, (claim, nPos) -> claim.canInteract(player, PermissionRegistry.CANSTAY, nPos, false)); player.teleportToWithTicket(tp.x(), tp.y(), tp.z()); } if (player.getAbilities().flying && !player.isCreative() && !currentClaim.canInteract(player, PermissionRegistry.FLIGHT, rounded, true)) { diff --git a/common/src/main/java/io/github/flemmli97/flan/player/TeleportUtils.java b/common/src/main/java/io/github/flemmli97/flan/player/TeleportUtils.java index fda4503..76eef1d 100644 --- a/common/src/main/java/io/github/flemmli97/flan/player/TeleportUtils.java +++ b/common/src/main/java/io/github/flemmli97/flan/player/TeleportUtils.java @@ -19,9 +19,18 @@ public class TeleportUtils { } public static Vec3 getTeleportPos(ServerPlayer player, Vec3 playerPos, ClaimStorage storage, int[] dim, BlockPos.MutableBlockPos bPos, BiFunction check) { + return getTeleportPos(player, playerPos, storage, dim, false, bPos, check); + } + + public static Vec3 getTeleportPos(ServerPlayer player, Vec3 playerPos, ClaimStorage storage, int[] dim, boolean checkSub, BlockPos.MutableBlockPos bPos, BiFunction check) { Tuple pos = nearestOutside(dim, playerPos); bPos.set(pos.getB().x(), pos.getB().y(), pos.getB().z()); Claim claim = storage.getClaimAt(bPos); + if (checkSub) { + Claim sub = claim != null ? claim.getSubClaim(bPos) : null; + if (sub != null) + claim = sub; + } if (claim == null || check.apply(claim, bPos)) { Vec3 ret = pos.getB(); BlockPos rounded = roundedBlockPos(ret); @@ -47,7 +56,7 @@ public class TeleportUtils { dim[0] = newDim[0]; break; } - return getTeleportPos(player, playerPos, storage, dim, bPos, check); + return getTeleportPos(player, playerPos, storage, dim, checkSub, bPos, check); } private static Tuple nearestOutside(int[] dim, Vec3 from) {