diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index c236992cf8..816902f8ff 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -403,7 +403,9 @@ default IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) { if (tx >= min.x() && bx <= max.x() && tz >= min.z() && bz <= max.z()) { // contains some boolean processExtra = false; - for (int layer = getMinimumY() >> 4; layer <= getMaximumY() >> 4; layer++) { + final int minLayer = Math.max(getMinimumY(), chunk.getMinY()) >> 4; + final int maxLayer = Math.min(getMaximumY(), chunk.getMaxY()) >> 4; + for (int layer = minLayer; layer <= maxLayer; layer++) { if (!set.hasSection(layer)) { continue; } @@ -457,7 +459,9 @@ default IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set, boolean if (tx >= min.x() && bx <= max.x() && tz >= min.z() && bz <= max.z()) { // contains some boolean processExtra = false; - for (int layer = getMinimumY() >> 4; layer <= getMaximumY() >> 4; layer++) { + final int minLayer = Math.max(getMinimumY(), chunk.getMinY()) >> 4; + final int maxLayer = Math.min(getMaximumY(), chunk.getMaxY()) >> 4; + for (int layer = minLayer; layer <= maxLayer; layer++) { int by = layer << 4; int ty = by + 15; if (containsEntireCuboid(bx, tx, by, ty, bz, tz)) {