Use mask for hollow

Closes #1298
Dieser Commit ist enthalten in:
Jesse Boyd 2019-05-13 00:28:48 +10:00
Ursprung 43a6541763
Commit da034f9ac4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
2 geänderte Dateien mit 21 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -100,6 +100,7 @@ import com.sk89q.worldedit.function.mask.MaskUnion;
import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.mask.NoiseFilter2D; import com.sk89q.worldedit.function.mask.NoiseFilter2D;
import com.sk89q.worldedit.function.mask.RegionMask; 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.ChangeSetExecutor;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operation; 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 * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int hollowOutRegion(final Region region, final int thickness, final Pattern pattern) { 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 { try {
final Set outside = new LocalBlockVectorSet(); 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 x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y) { for (int y = minY; y <= maxY; ++y) {
recurseHollow(region, BlockVector3.at(x, y, minZ), outside); recurseHollow(region, BlockVector3.at(x, y, minZ), outside, mask);
recurseHollow(region, BlockVector3.at(x, y, maxZ), outside); recurseHollow(region, BlockVector3.at(x, y, maxZ), outside, mask);
} }
} }
for (int y = minY; y <= maxY; ++y) { for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) { for (int z = minZ; z <= maxZ; ++z) {
recurseHollow(region, BlockVector3.at(minX, y, z), outside); recurseHollow(region, BlockVector3.at(minX, y, z), outside, mask);
recurseHollow(region, BlockVector3.at(maxX, y, z), outside); recurseHollow(region, BlockVector3.at(maxX, y, z), outside, mask);
} }
} }
for (int z = minZ; z <= maxZ; ++z) { for (int z = minZ; z <= maxZ; ++z) {
for (int x = minX; x <= maxX; ++x) { for (int x = minX; x <= maxX; ++x) {
recurseHollow(region, BlockVector3.at(x, minY, z), outside); recurseHollow(region, BlockVector3.at(x, minY, z), outside, mask);
recurseHollow(region, BlockVector3.at(x, maxY, z), outside); recurseHollow(region, BlockVector3.at(x, maxY, z), outside, mask);
} }
} }
@ -3120,15 +3125,14 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
return returnset; return returnset;
} }
private void recurseHollow(Region region, BlockVector3 origin, Set<BlockVector3> outside) { private void recurseHollow(Region region, BlockVector3 origin, Set<BlockVector3> outside, Mask mask) {
final LocalBlockVectorSet queue = new LocalBlockVectorSet(); final LocalBlockVectorSet queue = new LocalBlockVectorSet();
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
Iterator<BlockVector3> iter = queue.iterator(); Iterator<BlockVector3> iter = queue.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
BlockVector3 current = iter.next(); BlockVector3 current = iter.next();
iter.remove(); iter.remove();
final BlockState block = getBlock(current); if (mask.test(current)) {
if (block.getBlockType().getMaterial().isMovementBlocker()) {
continue; continue;
} }

Datei anzeigen

@ -51,6 +51,7 @@ import com.sk89q.worldedit.function.generator.FloraGenerator;
import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.NoiseFilter2D; 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.operation.Operations;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.function.visitor.LayerVisitor; import com.sk89q.worldedit.function.visitor.LayerVisitor;
@ -784,7 +785,10 @@ public class RegionCommands extends MethodCommands {
help = help =
"Hollows out the object contained in this selection.\n" + "Hollows out the object contained in this selection.\n" +
"Optionally fills the hollowed out part with the given block.\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, min = 0,
max = 2 max = 2
) )
@ -794,9 +798,11 @@ public class RegionCommands extends MethodCommands {
@Selection Region region, @Selection Region region,
@Optional("0") @Range(min = 0) int thickness, @Optional("0") @Range(min = 0) int thickness,
@Optional("air") Pattern pattern, @Optional("air") Pattern pattern,
@Switch('m') Mask mask,
CommandContext context) throws WorldEditException { CommandContext context) throws WorldEditException {
Mask finalMask = mask == null ? new SolidBlockMask(editSession) : mask;
player.checkConfirmationRegion(() -> { player.checkConfirmationRegion(() -> {
int affected = editSession.hollowOutRegion(region, thickness, pattern); int affected = editSession.hollowOutRegion(region, thickness, pattern, finalMask);
BBC.VISITOR_BLOCK.send(player, affected); BBC.VISITOR_BLOCK.send(player, affected);
}, getArguments(context), region, context); }, getArguments(context), region, context);
} }