Skip to content

Commit 0ecacc8

Browse files
committed
Determine "visible" instead of "outside" blocks
Previously, the "Remove everything else in the selection" section had an extra recursion step to get from the "outside" blocks to the "visible" blocks.
1 parent a02ca48 commit 0ecacc8

1 file changed

Lines changed: 32 additions & 30 deletions

File tree

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

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,10 +2669,9 @@ public int deformRegion(final Region region, final Transform targetTransform, fi
26692669
public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws MaxChangedBlocksException {
26702670
int affected = 0;
26712671

2672-
// Initialize BFS with selection bounding box
2673-
final Queue<BlockVector3> queue = new ArrayDeque<>();
2674-
final Set<BlockVector3> outside = new HashSet<>();
2672+
final Set<BlockVector3> visible = new HashSet<>();
26752673

2674+
// Initialize BFS with selection bounding box
26762675
final BlockVector3 min = region.getMinimumPoint();
26772676
final BlockVector3 max = region.getMaximumPoint();
26782677

@@ -2685,72 +2684,75 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws
26852684

26862685
for (int x = minX; x <= maxX; ++x) {
26872686
for (int y = minY; y <= maxY; ++y) {
2688-
queue.add(BlockVector3.at(x, y, minZ));
2689-
queue.add(BlockVector3.at(x, y, maxZ));
2687+
visible.add(BlockVector3.at(x, y, minZ));
2688+
visible.add(BlockVector3.at(x, y, maxZ));
26902689
}
26912690
}
26922691

26932692
for (int y = minY; y <= maxY; ++y) {
26942693
for (int z = minZ; z <= maxZ; ++z) {
2695-
queue.add(BlockVector3.at(minX, y, z));
2696-
queue.add(BlockVector3.at(maxX, y, z));
2694+
visible.add(BlockVector3.at(minX, y, z));
2695+
visible.add(BlockVector3.at(maxX, y, z));
26972696
}
26982697
}
26992698

27002699
for (int z = minZ; z <= maxZ; ++z) {
27012700
for (int x = minX; x <= maxX; ++x) {
2702-
queue.add(BlockVector3.at(x, minY, z));
2703-
queue.add(BlockVector3.at(x, maxY, z));
2701+
visible.add(BlockVector3.at(x, minY, z));
2702+
visible.add(BlockVector3.at(x, maxY, z));
27042703
}
27052704
}
27062705

2707-
// Do BFS to find visible blocks
2706+
// Remove movement blockers from visible list
2707+
visible.removeIf(blockVector3 -> getBlock(blockVector3).getBlockType().getMaterial().isMovementBlocker());
2708+
2709+
// Do BFS to find more visible blocks
2710+
final Queue<BlockVector3> queue = new ArrayDeque<>(visible);
27082711
while (!queue.isEmpty()) {
27092712
final BlockVector3 current = queue.poll();
2713+
27102714
final BlockState block = getBlock(current);
27112715
if (block.getBlockType().getMaterial().isMovementBlocker()) {
27122716
continue;
27132717
}
27142718

2715-
if (!outside.add(current)) {
2716-
continue;
2717-
}
2719+
for (BlockVector3 recurseDirection : recurseDirections) {
2720+
final BlockVector3 neighbor = current.add(recurseDirection);
27182721

2719-
if (!region.contains(current)) {
2720-
continue;
2721-
}
2722+
if (!region.contains(neighbor)) {
2723+
continue;
2724+
}
27222725

2723-
for (BlockVector3 recurseDirection : recurseDirections) {
2724-
queue.add(current.add(recurseDirection));
2726+
if (!visible.add(neighbor)) {
2727+
continue;
2728+
}
2729+
2730+
queue.add(neighbor);
27252731
}
27262732
}
27272733

27282734
// Expand by $thickness blocks
2729-
final Set<BlockVector3> newOutside = new HashSet<>();
2735+
final Set<BlockVector3> newVisible = new HashSet<>();
27302736
for (int i = 1; i < thickness; ++i) {
27312737
outer: for (BlockVector3 position : region) {
27322738
for (BlockVector3 recurseDirection : recurseDirections) {
27332739
BlockVector3 neighbor = position.add(recurseDirection);
27342740

2735-
if (outside.contains(neighbor)) {
2736-
newOutside.add(position);
2741+
if (visible.contains(neighbor)) {
2742+
newVisible.add(position);
27372743
continue outer;
27382744
}
27392745
}
27402746
}
27412747

2742-
outside.addAll(newOutside);
2743-
newOutside.clear();
2748+
visible.addAll(newVisible);
2749+
newVisible.clear();
27442750
}
27452751

27462752
// Remove everything else in the selection
2747-
outer: for (BlockVector3 position : region) {
2748-
for (BlockVector3 recurseDirection : recurseDirections) {
2749-
BlockVector3 neighbor = position.add(recurseDirection);
2750-
2751-
if (outside.contains(neighbor)) {
2752-
continue outer;
2753-
}
2753+
for (BlockVector3 position : region) {
2754+
if (visible.contains(position)) {
2755+
continue;
27542756
}
27552757

27562758
if (setBlock(position, pattern.applyBlock(position))) {

0 commit comments

Comments
 (0)