Skip to content

Commit 35e70a5

Browse files
committed
Also consider the geometry of the entered block
Previously, the algorithm could enter a top slab through the top side and leave through all other sides.
1 parent c4551e5 commit 35e70a5

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,9 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern, boolea
27732773
// The set of blocks that were seen
27742774
final Set<BlockVector3> visible = new HashSet<>(startingPositions);
27752775

2776+
// The set of blocks that were not only seen, but entered
2777+
final Set<BlockVector3> entered = new HashSet<>(startingPositions);
2778+
27762779
// Do BFS to find more visible blocks
27772780
final Queue<BlockVector3> queue = new ArrayDeque<>(startingPositions);
27782781
while (!queue.isEmpty()) {
@@ -2814,9 +2817,30 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern, boolea
28142817
continue;
28152818
}
28162819

2817-
// Mark the block as visible, abort if it already was
2818-
if (!visible.add(neighbor)) {
2819-
continue;
2820+
if (useBlockGeometry) {
2821+
// Mark neighbor as visible
2822+
visible.add(neighbor);
2823+
2824+
// If the neighbor was already entered, we can skip the expensive blocked calculation
2825+
if (entered.contains(neighbor)) {
2826+
continue;
2827+
}
2828+
2829+
// Check if we can actually enter the block from here
2830+
Direction oppositeDirection = Direction.findClosest(direction.toVector().multiply(-1), Direction.Flag.ALL);
2831+
for (Direction blockedDirection : getBlockedDirections(neighbor)) {
2832+
if (blockedDirection == oppositeDirection) {
2833+
continue outer; // skip this direction
2834+
}
2835+
}
2836+
2837+
// Mark neighbor as entered
2838+
entered.add(neighbor);
2839+
} else {
2840+
// Mark the block as visible, abort if it already was
2841+
if (!visible.add(neighbor)) {
2842+
continue;
2843+
}
28202844
}
28212845

28222846
// And queue it

0 commit comments

Comments
 (0)