Skip to content

Commit

Permalink
Ignore structure void by default and use a flag to paste it (#2180)
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Sep 19, 2022
1 parent 267bbb3 commit 4267fab
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
Expand Up @@ -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")
Expand All @@ -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"
);

Expand Down
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4267fab

Please sign in to comment.