Skip to content

Commit bf5e4b3

Browse files
committed
Add flag to //hollow for blocks to consider for shell detection
1 parent 119669e commit bf5e4b3

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
@@ -2703,12 +2703,12 @@ private Direction[] getBlockedDirections(BlockVector3 position) {
27032703
*
27042704
* @return number of blocks affected
27052705
* @throws MaxChangedBlocksException thrown if too many blocks are changed
2706-
* @deprecated Use {@link EditSession#hollowOutRegion(Region, int, Pattern, boolean, Collection, boolean)} instead.
2706+
* @deprecated Use {@link EditSession#hollowOutRegion(Region, int, Pattern, boolean, Collection, boolean, Mask)} instead.
27072707
*/
2708-
@InlineMe(replacement = "this.hollowOutRegion(region, thickness, pattern, true, null, false)")
2708+
@InlineMe(replacement = "this.hollowOutRegion(region, thickness, pattern, true, null, false, Masks.alwaysTrue())", imports = "com.sk89q.worldedit.function.mask.Masks")
27092709
@Deprecated
27102710
public final int hollowOutRegion(Region region, int thickness, Pattern pattern) throws MaxChangedBlocksException {
2711-
return hollowOutRegion(region, thickness, pattern, true, null, false);
2711+
return hollowOutRegion(region, thickness, pattern, true, null, false, Masks.alwaysTrue());
27122712
}
27132713

27142714
/**
@@ -2721,10 +2721,11 @@ public final int hollowOutRegion(Region region, int thickness, Pattern pattern)
27212721
* @param openSides Open up faces touching the bounding box. This matches the legacy behaviour.
27222722
* @param startingPositions Positions to consider as 'outside'. If null, use the selection bounding box
27232723
* @param useBlockGeometry Consider block geometry for visibility calculation
2724+
* @param includeMask Mask of blocks eligible for shell detection
27242725
* @return number of blocks affected
27252726
* @throws MaxChangedBlocksException thrown if too many blocks are changed
27262727
*/
2727-
public int hollowOutRegion(Region region, int thickness, Pattern pattern, boolean openSides, Collection<BlockVector3> startingPositions, boolean useBlockGeometry) throws MaxChangedBlocksException {
2728+
public int hollowOutRegion(Region region, int thickness, Pattern pattern, boolean openSides, Collection<BlockVector3> startingPositions, boolean useBlockGeometry, Mask includeMask) throws MaxChangedBlocksException {
27282729
if (startingPositions == null) {
27292730
// If no startingPositions are specified, use the selection bounding box
27302731
startingPositions = new ArrayList<>();
@@ -2779,7 +2780,9 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern, boolea
27792780
final BlockVector3 current = queue.poll();
27802781

27812782
Direction[] blockedDirections;
2782-
if (useBlockGeometry) {
2783+
if (!includeMask.test(current)) {
2784+
blockedDirections = NO_DIRECTIONS;
2785+
} else if (useBlockGeometry) {
27832786
// Get blocked directions for this block
27842787
blockedDirections = getBlockedDirections(current);
27852788

@@ -2823,11 +2826,13 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern, boolea
28232826
continue;
28242827
}
28252828

2826-
// Check if we can actually enter the block from here
2827-
Direction oppositeDirection = Direction.findClosest(direction.toVector().multiply(-1), Direction.Flag.ALL);
2828-
for (Direction blockedDirection : getBlockedDirections(neighbor)) {
2829-
if (blockedDirection == oppositeDirection) {
2830-
continue outer; // skip this direction
2829+
if (includeMask.test(neighbor)) {
2830+
// Check if we can actually enter the block from here
2831+
Direction oppositeDirection = Direction.findClosest(direction.toVector().multiply(-1), Direction.Flag.ALL);
2832+
for (Direction blockedDirection : getBlockedDirections(neighbor)) {
2833+
if (blockedDirection == oppositeDirection) {
2834+
continue outer; // skip this direction
2835+
}
28312836
}
28322837
}
28332838

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;
@@ -561,7 +562,9 @@ public int hollow(Actor actor, EditSession editSession, LocalSession session,
561562
@Switch(name = 'p', desc = "Consider placement position as 'outside' instead of the selection bounding box. Overrides -o.")
562563
boolean usePlacementPosition,
563564
@Switch(name = 'g', desc = "Consider block geometry for visibility calculation")
564-
boolean useBlockGeometry) throws WorldEditException {
565+
boolean useBlockGeometry,
566+
@ArgFlag(name = 'm', desc = "Set the mask of blocks eligible for shell detection")
567+
Mask includeMask) throws WorldEditException {
565568
checkCommandArgument(thickness >= 1, "Thickness must be >= 1");
566569

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

0 commit comments

Comments
 (0)