diff --git a/bukkit/src/main/java/net/william278/huskhomes/util/BukkitSafetyResolver.java b/bukkit/src/main/java/net/william278/huskhomes/util/BukkitSafetyResolver.java index 8c70b78d..92be1b76 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/util/BukkitSafetyResolver.java +++ b/bukkit/src/main/java/net/william278/huskhomes/util/BukkitSafetyResolver.java @@ -46,7 +46,11 @@ public interface BukkitSafetyResolver extends SafetyResolver { // Search nearby blocks for a safe location return PaperLib.getChunkAtAsync(bukkitLocation) .thenApply(Chunk::getChunkSnapshot) - .thenApply(snapshot -> findSafeLocationNear(location, snapshot)); + .thenApply(snapshot -> findSafeLocationNear( + location, + snapshot, + bukkitLocation.getWorld().getMinHeight() + )); } /** @@ -54,9 +58,10 @@ public interface BukkitSafetyResolver extends SafetyResolver { * * @param location The location to search around * @param snapshot The chunk snapshot to search + * @param minY The minimum Y value of the world * @return An optional safe location, within 4 blocks of the given location */ - private Optional findSafeLocationNear(@NotNull Location location, @NotNull ChunkSnapshot snapshot) { + private Optional findSafeLocationNear(@NotNull Location location, @NotNull ChunkSnapshot snapshot, int minY) { final int chunkX = ((int) location.getX()) & 0xF; final int chunkZ = ((int) location.getZ()) & 0xF; @@ -67,12 +72,12 @@ public interface BukkitSafetyResolver extends SafetyResolver { if (x < 0 || x >= 16 || z < 0 || z >= 16) { continue; } - final int y = snapshot.getHighestBlockYAt(x, z); + final int y = Math.max((minY + 1), snapshot.getHighestBlockYAt(x, z)); final Material blockType = snapshot.getBlockType(chunkX, y, chunkZ); if (isBlockSafe(blockType.getKey().toString())) { return Optional.of(Location.at( (location.getX() + dX) + 0.5d, - y + 1.25d, + y + 1, (location.getZ() + dZ) + 0.5d, location.getWorld() )); diff --git a/fabric/src/main/java/net/william278/huskhomes/util/FabricSafetyResolver.java b/fabric/src/main/java/net/william278/huskhomes/util/FabricSafetyResolver.java index 13d6a4ed..64293a6c 100644 --- a/fabric/src/main/java/net/william278/huskhomes/util/FabricSafetyResolver.java +++ b/fabric/src/main/java/net/william278/huskhomes/util/FabricSafetyResolver.java @@ -65,7 +65,7 @@ public interface FabricSafetyResolver extends SafetyResolver { * @param location The location to search around * @return An optional safe location, within 4 blocks of the given location */ - private Optional findSafeLocationNear(Location location, ServerWorld world) { + private Optional findSafeLocationNear(@NotNull Location location, @NotNull ServerWorld world) { final BlockPos.Mutable blockPos = new BlockPos.Mutable(location.getX(), location.getY(), location.getZ()); for (int x = -SEARCH_RADIUS; x <= SEARCH_RADIUS; x++) { for (int z = -SEARCH_RADIUS; z <= SEARCH_RADIUS; z++) {