Ignore structure void by default and use a flag to paste it (#2180)

This commit is contained in:
Maddy Miller 2022-09-20 09:29:55 +10:00 committed by GitHub
parent 267bbb307f
commit 4267fabd3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 12 deletions

View File

@ -222,6 +222,8 @@ public void splatterBrush(Player player, LocalSession session,
public void clipboardBrush(Player player, LocalSession session,
@Switch(name = 'a', desc = "Don't paste air from the clipboard")
boolean ignoreAir,
@Switch(name = 'v', desc = "Include structure void blocks")
boolean pasteStructureVoid,
@Switch(name = 'o', desc = "Paste starting at the target location, instead of centering on it")
boolean usingOrigin,
@Switch(name = 'e', desc = "Paste entities if available")
@ -243,9 +245,9 @@ public void clipboardBrush(Player player, LocalSession session,
worldEdit.checkMaxBrushRadius(size.getBlockY() / 2D - 1);
worldEdit.checkMaxBrushRadius(size.getBlockZ() / 2D - 1);
BrushTool tool = session.forceBrush(
session.forceBrush(
player.getItemInHand(HandSide.MAIN_HAND).getType(),
new ClipboardBrush(newHolder, ignoreAir, usingOrigin, pasteEntities, pasteBiomes, sourceMask),
new ClipboardBrush(newHolder, ignoreAir, !pasteStructureVoid, usingOrigin, pasteEntities, pasteBiomes, sourceMask),
"worldedit.brush.clipboard"
);

View File

@ -151,6 +151,8 @@ public void cut(Actor actor, LocalSession session, EditSession editSession,
public void paste(Actor actor, World world, LocalSession session, EditSession editSession,
@Switch(name = 'a', desc = "Skip air blocks")
boolean ignoreAirBlocks,
@Switch(name = 'v', desc = "Include structure void blocks")
boolean pasteStructureVoid,
@Switch(name = 'o', desc = "Paste at the original position")
boolean atOrigin,
@Switch(name = 's', desc = "Select the region after pasting")
@ -176,6 +178,7 @@ public void paste(Actor actor, World world, LocalSession session, EditSession ed
.createPaste(editSession)
.to(to)
.ignoreAirBlocks(ignoreAirBlocks)
.ignoreStructureVoidBlocks(!pasteStructureVoid)
.copyBiomes(pasteBiomes)
.copyEntities(pasteEntities)
.maskSource(sourceMask)

View File

@ -34,24 +34,27 @@ public class ClipboardBrush implements Brush {
private final ClipboardHolder holder;
private final boolean ignoreAirBlocks;
private final boolean ignoreStructureVoidBlocks;
private final boolean usingOrigin;
private final boolean pasteEntities;
private final boolean pasteBiomes;
private final Mask sourceMask;
public ClipboardBrush(ClipboardHolder holder, boolean ignoreAirBlocks, boolean usingOrigin) {
this.holder = holder;
this.ignoreAirBlocks = ignoreAirBlocks;
this.usingOrigin = usingOrigin;
this.pasteBiomes = false;
this.pasteEntities = false;
this.sourceMask = null;
this(holder, ignoreAirBlocks, usingOrigin, false, false, null);
}
@Deprecated
public ClipboardBrush(ClipboardHolder holder, boolean ignoreAirBlocks, boolean usingOrigin, boolean pasteEntities,
boolean pasteBiomes, Mask sourceMask) {
this(holder, ignoreAirBlocks, false, usingOrigin, pasteEntities, pasteBiomes, sourceMask);
}
public ClipboardBrush(ClipboardHolder holder, boolean ignoreAirBlocks, boolean ignoreStructureVoidBlocks,
boolean usingOrigin, boolean pasteEntities, boolean pasteBiomes, Mask sourceMask) {
this.holder = holder;
this.ignoreAirBlocks = ignoreAirBlocks;
this.ignoreStructureVoidBlocks = ignoreStructureVoidBlocks;
this.usingOrigin = usingOrigin;
this.pasteEntities = pasteEntities;
this.pasteBiomes = pasteBiomes;
@ -68,6 +71,7 @@ public void build(EditSession editSession, BlockVector3 position, Pattern patter
.createPaste(editSession)
.to(usingOrigin ? position : position.subtract(centerOffset))
.ignoreAirBlocks(ignoreAirBlocks)
.ignoreStructureVoidBlocks(ignoreStructureVoidBlocks)
.copyEntities(pasteEntities)
.copyBiomes(pasteBiomes)
.maskSource(sourceMask)

View File

@ -22,6 +22,7 @@
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.MaskIntersection;
@ -30,6 +31,7 @@
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.world.block.BlockTypes;
import static com.google.common.base.Preconditions.checkNotNull;
@ -46,6 +48,7 @@ public class PasteBuilder {
private BlockVector3 to = BlockVector3.ZERO;
private boolean ignoreAirBlocks;
private boolean ignoreStructureVoidBlocks; // TODO Make true in WE8
private boolean copyEntities = true; // default because it used to be this way
private boolean copyBiomes;
@ -101,6 +104,23 @@ public PasteBuilder ignoreAirBlocks(boolean ignoreAirBlocks) {
return this;
}
/**
* Set whether structure void blocks in the source are skipped over when pasting.
*
* <p>
* This currently defaults to false. In the next major version this will default to true, to better align to how
* Minecraft intends these blocks to function. It's recommended to set this if the value of this matters for you,
* even if it currently matches the default.
* </p>
*
* @param ignoreStructureVoidBlocks value to set it to
* @return This builder instance
*/
public PasteBuilder ignoreStructureVoidBlocks(boolean ignoreStructureVoidBlocks) {
this.ignoreStructureVoidBlocks = ignoreStructureVoidBlocks;
return this;
}
/**
* Set whether the copy should include source entities.
* Note that this is true by default for legacy reasons.
@ -133,12 +153,19 @@ public Operation build() {
BlockTransformExtent extent = new BlockTransformExtent(clipboard, transform);
ForwardExtentCopy copy = new ForwardExtentCopy(extent, clipboard.getRegion(), clipboard.getOrigin(), targetExtent, to);
copy.setTransform(transform);
Mask combinedMask = sourceMask;
if (ignoreAirBlocks) {
copy.setSourceMask(sourceMask == Masks.alwaysTrue() ? new ExistingBlockMask(clipboard)
: new MaskIntersection(sourceMask, new ExistingBlockMask(clipboard)));
} else {
copy.setSourceMask(sourceMask);
combinedMask = combinedMask == Masks.alwaysTrue() ? new ExistingBlockMask(clipboard)
: new MaskIntersection(combinedMask, new ExistingBlockMask(clipboard));
}
if (ignoreStructureVoidBlocks) {
Mask structureVoidMask = Masks.negate(new BlockTypeMask(clipboard, BlockTypes.STRUCTURE_VOID));
combinedMask = combinedMask == Masks.alwaysTrue() ? structureVoidMask
: new MaskIntersection(combinedMask, structureVoidMask);
}
copy.setSourceMask(combinedMask);
copy.setCopyingEntities(copyEntities);
copy.setCopyingBiomes(copyBiomes && clipboard.hasBiomes());
return copy;