Skip to content

Commit 30c0b98

Browse files
committed
Add flag to /hollow for blocks to ignore
1 parent 366a318 commit 30c0b98

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,12 +2709,12 @@ private Direction[] getBlockedDirections(BlockVector3 position) {
27092709
*
27102710
* @return number of blocks affected
27112711
* @throws MaxChangedBlocksException thrown if too many blocks are changed
2712-
* @deprecated Use {@link EditSession#hollowOutRegion(Region, int, Pattern, boolean, Collection, boolean)} instead.
2712+
* @deprecated Use {@link EditSession#hollowOutRegion(Region, int, Pattern, boolean, Collection, boolean, Mask)} instead.
27132713
*/
2714-
@InlineMe(replacement = "this.hollowOutRegion(region, thickness, pattern, true, null, false)")
2714+
@InlineMe(replacement = "this.hollowOutRegion(region, thickness, pattern, true, null, false, Masks.alwaysTrue())", imports = "com.sk89q.worldedit.function.mask.Masks")
27152715
@Deprecated
27162716
public final int hollowOutRegion(Region region, int thickness, Pattern pattern) throws MaxChangedBlocksException {
2717-
return hollowOutRegion(region, thickness, pattern, true, null, false);
2717+
return hollowOutRegion(region, thickness, pattern, true, null, false, Masks.alwaysTrue());
27182718
}
27192719

27202720
/**
@@ -2727,10 +2727,11 @@ public final int hollowOutRegion(Region region, int thickness, Pattern pattern)
27272727
* @param openSides Open up faces touching the bounding box. This matches the legacy behaviour.
27282728
* @param startingPositions Positions to consider as 'outside'. If null, use the selection bounding box
27292729
* @param useBlockGeometry Consider block geometry for visibility calculation
2730+
* @param includeMask Mask of blocks eligible for shell detection
27302731
* @return number of blocks affected
27312732
* @throws MaxChangedBlocksException thrown if too many blocks are changed
27322733
*/
2733-
public int hollowOutRegion(Region region, int thickness, Pattern pattern, boolean openSides, Collection<BlockVector3> startingPositions, boolean useBlockGeometry) throws MaxChangedBlocksException {
2734+
public int hollowOutRegion(Region region, int thickness, Pattern pattern, boolean openSides, Collection<BlockVector3> startingPositions, boolean useBlockGeometry, Mask includeMask) throws MaxChangedBlocksException {
27342735
if (startingPositions == null) {
27352736
// If no startingPositions are specified, use the selection bounding box
27362737
startingPositions = new ArrayList<>();
@@ -2785,7 +2786,9 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern, boolea
27852786
final BlockVector3 current = queue.poll();
27862787

27872788
Direction[] blockedDirections;
2788-
if (useBlockGeometry) {
2789+
if (!includeMask.test(current)) {
2790+
blockedDirections = NO_DIRECTIONS;
2791+
} else if (useBlockGeometry) {
27892792
// Get blocked directions for this block
27902793
blockedDirections = getBlockedDirections(current);
27912794

@@ -2829,11 +2832,13 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern, boolea
28292832
continue;
28302833
}
28312834

2832-
// Check if we can actually enter the block from here
2833-
Direction oppositeDirection = Direction.findClosest(direction.toVector().multiply(-1), Direction.Flag.ALL);
2834-
for (Direction blockedDirection : getBlockedDirections(neighbor)) {
2835-
if (blockedDirection == oppositeDirection) {
2836-
continue outer; // skip this direction
2835+
if (includeMask.test(neighbor)) {
2836+
// Check if we can actually enter the block from here
2837+
Direction oppositeDirection = Direction.findClosest(direction.toVector().multiply(-1), Direction.Flag.ALL);
2838+
for (Direction blockedDirection : getBlockedDirections(neighbor)) {
2839+
if (blockedDirection == oppositeDirection) {
2840+
continue outer; // skip this direction
2841+
}
28372842
}
28382843
}
28392844

worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
4444
import com.sk89q.worldedit.function.mask.Mask;
4545
import com.sk89q.worldedit.function.mask.MaskIntersection;
46+
import com.sk89q.worldedit.function.mask.Masks;
4647
import com.sk89q.worldedit.function.mask.NoiseFilter2D;
4748
import com.sk89q.worldedit.function.operation.Operations;
4849
import com.sk89q.worldedit.function.pattern.Pattern;
@@ -562,7 +563,9 @@ public int hollow(Actor actor, EditSession editSession, LocalSession session,
562563
@Switch(name = 'p', desc = "Consider placement position as 'outside' instead of the selection bounding box. Overrides -o.")
563564
boolean usePlacementPosition,
564565
@Switch(name = 'g', desc = "Consider block geometry for visibility calculation")
565-
boolean useBlockGeometry) throws WorldEditException {
566+
boolean useBlockGeometry,
567+
@ArgFlag(name = 'm', desc = "Set the mask of blocks eligible for shell detection")
568+
Mask includeMask) throws WorldEditException {
566569
checkCommandArgument(thickness >= 1, "Thickness must be >= 1");
567570

568571
final Collection<BlockVector3> startingPositions;
@@ -580,7 +583,10 @@ public int hollow(Actor actor, EditSession editSession, LocalSession session,
580583
} else {
581584
startingPositions = null;
582585
}
583-
int affected = editSession.hollowOutRegion(region, thickness, pattern, openSides, startingPositions, useBlockGeometry);
586+
if (includeMask == null) {
587+
includeMask = Masks.alwaysTrue();
588+
}
589+
int affected = editSession.hollowOutRegion(region, thickness, pattern, openSides, startingPositions, useBlockGeometry, includeMask);
584590
actor.printInfo(TranslatableComponent.of("worldedit.hollow.changed", TextComponent.of(affected)));
585591
return affected;
586592
}

0 commit comments

Comments
 (0)