From da034f9ac4d126498f388b80f392602eaa94ad50 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 13 May 2019 00:28:48 +1000 Subject: [PATCH] Use mask for hollow Closes #1298 --- .../java/com/sk89q/worldedit/EditSession.java | 22 +++++++++++-------- .../worldedit/command/RegionCommands.java | 10 +++++++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 8fb6178f7..b4390ec65 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -100,6 +100,7 @@ import com.sk89q.worldedit.function.mask.MaskUnion; import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.mask.NoiseFilter2D; import com.sk89q.worldedit.function.mask.RegionMask; +import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.operation.ChangeSetExecutor; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operation; @@ -2856,6 +2857,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public int hollowOutRegion(final Region region, final int thickness, final Pattern pattern) { + return hollowOutRegion(region, thickness, pattern, new SolidBlockMask(this)); + } + + public int hollowOutRegion(final Region region, final int thickness, final Pattern pattern, Mask mask) { try { final Set outside = new LocalBlockVectorSet(); @@ -2871,22 +2876,22 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, for (int x = minX; x <= maxX; ++x) { for (int y = minY; y <= maxY; ++y) { - recurseHollow(region, BlockVector3.at(x, y, minZ), outside); - recurseHollow(region, BlockVector3.at(x, y, maxZ), outside); + recurseHollow(region, BlockVector3.at(x, y, minZ), outside, mask); + recurseHollow(region, BlockVector3.at(x, y, maxZ), outside, mask); } } for (int y = minY; y <= maxY; ++y) { for (int z = minZ; z <= maxZ; ++z) { - recurseHollow(region, BlockVector3.at(minX, y, z), outside); - recurseHollow(region, BlockVector3.at(maxX, y, z), outside); + recurseHollow(region, BlockVector3.at(minX, y, z), outside, mask); + recurseHollow(region, BlockVector3.at(maxX, y, z), outside, mask); } } for (int z = minZ; z <= maxZ; ++z) { for (int x = minX; x <= maxX; ++x) { - recurseHollow(region, BlockVector3.at(x, minY, z), outside); - recurseHollow(region, BlockVector3.at(x, maxY, z), outside); + recurseHollow(region, BlockVector3.at(x, minY, z), outside, mask); + recurseHollow(region, BlockVector3.at(x, maxY, z), outside, mask); } } @@ -3120,15 +3125,14 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return returnset; } - private void recurseHollow(Region region, BlockVector3 origin, Set outside) { + private void recurseHollow(Region region, BlockVector3 origin, Set outside, Mask mask) { final LocalBlockVectorSet queue = new LocalBlockVectorSet(); while (!queue.isEmpty()) { Iterator iter = queue.iterator(); while (iter.hasNext()) { BlockVector3 current = iter.next(); iter.remove(); - final BlockState block = getBlock(current); - if (block.getBlockType().getMaterial().isMovementBlocker()) { + if (mask.test(current)) { continue; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 9b9939ede..43fdf40df 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -51,6 +51,7 @@ import com.sk89q.worldedit.function.generator.FloraGenerator; import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.NoiseFilter2D; +import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.LayerVisitor; @@ -784,7 +785,10 @@ public class RegionCommands extends MethodCommands { help = "Hollows out the object contained in this selection.\n" + "Optionally fills the hollowed out part with the given block.\n" + - "Thickness is measured in manhattan distance.", + "Thickness is measured in manhattan distance.\n" + + "Flags:\n" + + " -m Mask, uses a mask to hollow", + min = 0, max = 2 ) @@ -794,9 +798,11 @@ public class RegionCommands extends MethodCommands { @Selection Region region, @Optional("0") @Range(min = 0) int thickness, @Optional("air") Pattern pattern, + @Switch('m') Mask mask, CommandContext context) throws WorldEditException { + Mask finalMask = mask == null ? new SolidBlockMask(editSession) : mask; player.checkConfirmationRegion(() -> { - int affected = editSession.hollowOutRegion(region, thickness, pattern); + int affected = editSession.hollowOutRegion(region, thickness, pattern, finalMask); BBC.VISITOR_BLOCK.send(player, affected); }, getArguments(context), region, context); }