Added new preliminary non-destructive //rotate and //flip implementations.

Blocks themselves are not yet rotated/flip.

//flip now only flips across the player. -p was removed.
This commit is contained in:
sk89q 2014-07-02 02:56:21 -07:00
parent 9e8b2d1875
commit aad7bb47d6
11 changed files with 197 additions and 77 deletions

View File

@ -39,6 +39,7 @@ import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.snapshot.Snapshot; import com.sk89q.worldedit.world.snapshot.Snapshot;
@ -63,7 +64,7 @@ public class LocalSession {
private boolean placeAtPos1 = false; private boolean placeAtPos1 = false;
private LinkedList<EditSession> history = new LinkedList<EditSession>(); private LinkedList<EditSession> history = new LinkedList<EditSession>();
private int historyPointer = 0; private int historyPointer = 0;
private Clipboard clipboard; private ClipboardHolder clipboard;
private boolean toolControl = true; private boolean toolControl = true;
private boolean superPickaxe = false; private boolean superPickaxe = false;
private BlockTool pickaxeMode = new SinglePickaxe(); private BlockTool pickaxeMode = new SinglePickaxe();
@ -327,7 +328,7 @@ public class LocalSession {
* @return clipboard, may be null * @return clipboard, may be null
* @throws EmptyClipboardException * @throws EmptyClipboardException
*/ */
public Clipboard getClipboard() throws EmptyClipboardException { public ClipboardHolder getClipboard() throws EmptyClipboardException {
if (clipboard == null) { if (clipboard == null) {
throw new EmptyClipboardException(); throw new EmptyClipboardException();
} }
@ -339,8 +340,8 @@ public class LocalSession {
* *
* @param clipboard * @param clipboard
*/ */
public void setClipboard(Clipboard clipboard) { public ClipboardHolder replaceClipboard(Clipboard clipboard) {
this.clipboard = clipboard; return this.clipboard = new ClipboardHolder(clipboard);
} }
/** /**

View File

@ -47,6 +47,7 @@ import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.parametric.Optional; import com.sk89q.worldedit.util.command.parametric.Optional;
@ -141,23 +142,17 @@ public class BrushCommands {
) )
@CommandPermissions("worldedit.brush.clipboard") @CommandPermissions("worldedit.brush.clipboard")
public void clipboardBrush(Player player, LocalSession session, EditSession editSession, @Switch('a') boolean ignoreAir) throws WorldEditException { public void clipboardBrush(Player player, LocalSession session, EditSession editSession, @Switch('a') boolean ignoreAir) throws WorldEditException {
ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard();
Clipboard clipboard = session.getClipboard(); Vector size = clipboard.getDimensions();
if (clipboard == null) {
player.printError("Copy something first.");
return;
}
Region region = clipboard.getRegion();
Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint());
worldEdit.checkMaxBrushRadius(size.getBlockX()); worldEdit.checkMaxBrushRadius(size.getBlockX());
worldEdit.checkMaxBrushRadius(size.getBlockY()); worldEdit.checkMaxBrushRadius(size.getBlockY());
worldEdit.checkMaxBrushRadius(size.getBlockZ()); worldEdit.checkMaxBrushRadius(size.getBlockZ());
BrushTool tool = session.getBrushTool(player.getItemInHand()); BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setBrush(new ClipboardBrush(clipboard, ignoreAir), "worldedit.brush.clipboard"); tool.setBrush(new ClipboardBrush(holder, ignoreAir), "worldedit.brush.clipboard");
player.print("Clipboard brush shape equipped."); player.print("Clipboard brush shape equipped.");
} }

View File

@ -20,8 +20,6 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.minecraft.util.commands.Logging;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
@ -38,10 +36,13 @@ import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
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.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.Selection; import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.parametric.Optional; import com.sk89q.worldedit.util.command.parametric.Optional;
@ -82,10 +83,10 @@ public class ClipboardCommands {
@Selection Region region, @Switch('e') boolean copyEntities) throws WorldEditException { @Selection Region region, @Switch('e') boolean copyEntities) throws WorldEditException {
BlockArrayClipboard clipboard = new BlockArrayClipboard(region); BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
clipboard.setOffset(region.getMinimumPoint().subtract(session.getPlacementPosition(player))); clipboard.setOrigin(session.getPlacementPosition(player));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
Operations.completeLegacy(copy); Operations.completeLegacy(copy);
session.setClipboard(clipboard); session.replaceClipboard(clipboard);
player.print(region.getArea() + " block(s) were copied."); player.print(region.getArea() + " block(s) were copied.");
} }
@ -108,11 +109,11 @@ public class ClipboardCommands {
@Selection Region region, @Optional("air") Pattern leavePattern, @Switch('e') boolean copyEntities) throws WorldEditException { @Selection Region region, @Optional("air") Pattern leavePattern, @Switch('e') boolean copyEntities) throws WorldEditException {
BlockArrayClipboard clipboard = new BlockArrayClipboard(region); BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
clipboard.setOffset(region.getMinimumPoint().subtract(session.getPlacementPosition(player))); clipboard.setOrigin(session.getPlacementPosition(player));
ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint()); ForwardExtentCopy copy = new ForwardExtentCopy(editSession, region, clipboard, region.getMinimumPoint());
copy.setSourceFunction(new BlockReplace(editSession, leavePattern)); copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
Operations.completeLegacy(copy); Operations.completeLegacy(copy);
session.setClipboard(clipboard); session.replaceClipboard(clipboard);
player.print(region.getArea() + " block(s) were copied."); player.print(region.getArea() + " block(s) were copied.");
} }
@ -137,16 +138,19 @@ public class ClipboardCommands {
@Switch('a') boolean ignoreAirBlocks, @Switch('o') boolean atOrigin, @Switch('a') boolean ignoreAirBlocks, @Switch('o') boolean atOrigin,
@Switch('s') boolean selectPasted) throws WorldEditException { @Switch('s') boolean selectPasted) throws WorldEditException {
Clipboard clipboard = session.getClipboard(); ClipboardHolder holder = session.getClipboard();
Vector to = atOrigin ? clipboard.getRegion().getMinimumPoint(): session.getPlacementPosition(player).add(clipboard.getOffset()); Clipboard clipboard = holder.getClipboard();
ForwardExtentCopy copy = new ForwardExtentCopy(clipboard, clipboard.getRegion(), editSession, to); Region region = clipboard.getRegion();
Vector to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player);
ForwardExtentCopy copy = new ForwardExtentCopy(clipboard, region, clipboard.getOrigin(), editSession, to);
copy.setTransform(holder.getTransform());
if (ignoreAirBlocks) { if (ignoreAirBlocks) {
copy.setSourceMask(new ExistingBlockMask(clipboard)); copy.setSourceMask(new ExistingBlockMask(clipboard));
} }
Operations.completeLegacy(copy); Operations.completeLegacy(copy);
if (selectPasted) { if (selectPasted) {
Region region = clipboard.getRegion();
Vector max = to.add(region.getMaximumPoint().subtract(region.getMinimumPoint())); Vector max = to.add(region.getMaximumPoint().subtract(region.getMinimumPoint()));
RegionSelector selector = new CuboidRegionSelector(player.getWorld(), to, max); RegionSelector selector = new CuboidRegionSelector(player.getWorld(), to, max);
session.setRegionSelector(player.getWorld(), selector); session.setRegionSelector(player.getWorld(), selector);
@ -154,38 +158,52 @@ public class ClipboardCommands {
selector.explainRegionAdjust(player, session); selector.explainRegionAdjust(player, session);
} }
player.print("The clipboard has been pasted at " + to.add(clipboard.getRegion().getMinimumPoint())); player.print("The clipboard has been pasted at " + to.add(region.getMinimumPoint()));
} }
@Command( @Command(
aliases = { "/rotate" }, aliases = { "/rotate" },
usage = "<angle-in-degrees>", usage = "<y-axis> [<x-axis>] [<z-axis>]",
desc = "Rotate the contents of the clipboard", desc = "Rotate the contents of the clipboard",
min = 1, help = "Non-destructively rotate the contents of the clipboard.\n" +
max = 1 "Angles are provided in degrees and a positive angle will result in a clockwise rotation. " +
"Multiple rotations can be stacked. Interpolation is not performed so angles should be a multiple of 90 degrees.\n"
) )
@CommandPermissions("worldedit.clipboard.rotate") @CommandPermissions("worldedit.clipboard.rotate")
public void rotate(Player player, LocalSession session, EditSession editSession, CommandContext args) throws CommandException { public void rotate(Player player, LocalSession session, Double yRotate, @Optional Double xRotate, @Optional Double zRotate) throws WorldEditException {
// TODO: Update for new clipboard if ((yRotate != null && Math.abs(yRotate % 90) > 0.001) ||
throw new CommandException("Needs to be re-written again"); xRotate != null && Math.abs(xRotate % 90) > 0.001 ||
zRotate != null && Math.abs(zRotate % 90) > 0.001) {
player.printDebug("Note: Interpolation is not yet supported, so angles that are multiples of 90 is recommended.");
}
ClipboardHolder holder = session.getClipboard();
AffineTransform transform = new AffineTransform();
transform = transform.rotateY(Math.toRadians(yRotate != null ? yRotate : 0));
transform = transform.rotateX(Math.toRadians(xRotate != null ? xRotate : 0));
transform = transform.rotateZ(Math.toRadians(zRotate != null ? zRotate : 0));
holder.setTransform(holder.getTransform().combine(transform));
player.print("The clipboard copy has been rotated.");
} }
@Command( @Command(
aliases = { "/flip" }, aliases = { "/flip" },
usage = "[dir]", usage = "[<direction>]",
flags = "p", desc = "Flip the contents of the clipboard",
desc = "Flip the contents of the clipboard.",
help = help =
"Flips the contents of the clipboard.\n" + "Flips the contents of the clipboard across the point from which the copy was made.\n",
"The -p flag flips the selection around the player,\n" +
"instead of the selections center.",
min = 0, min = 0,
max = 1 max = 1
) )
@CommandPermissions("worldedit.clipboard.flip") @CommandPermissions("worldedit.clipboard.flip")
public void flip(Player player, LocalSession session, EditSession editSession, CommandContext args) throws CommandException { public void flip(Player player, LocalSession session, EditSession editSession,
// TODO: Update for new clipboard @Optional(Direction.AIM) @Direction Vector direction) throws WorldEditException {
throw new CommandException("Needs to be re-written again"); ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard();
AffineTransform transform = new AffineTransform();
transform = transform.scale(direction.positive().multiply(-2).add(1, 1, 1));
holder.setTransform(holder.getTransform().combine(transform));
player.print("The clipboard copy has been flipped.");
} }
@Command( @Command(
@ -223,7 +241,7 @@ public class ClipboardCommands {
) )
@CommandPermissions("worldedit.clipboard.clear") @CommandPermissions("worldedit.clipboard.clear")
public void clearClipboard(Player player, LocalSession session, EditSession editSession) throws WorldEditException { public void clearClipboard(Player player, LocalSession session, EditSession editSession) throws WorldEditException {
session.setClipboard(null); session.replaceClipboard(null);
player.print("Clipboard cleared."); player.print("Clipboard cleared.");
} }
} }

View File

@ -45,6 +45,7 @@ import com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector;
import com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector; import com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector; import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
import com.sk89q.worldedit.regions.selector.SphereRegionSelector; import com.sk89q.worldedit.regions.selector.SphereRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.storage.ChunkStore; import com.sk89q.worldedit.world.storage.ChunkStore;
@ -584,13 +585,14 @@ public class SelectionCommands {
public void size(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { public void size(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
if (args.hasFlag('c')) { if (args.hasFlag('c')) {
Clipboard clipboard = session.getClipboard(); ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard();
Region region = clipboard.getRegion(); Region region = clipboard.getRegion();
Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint()); Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint());
Vector offset = clipboard.getOffset(); Vector origin = clipboard.getOrigin();
player.print("Cuboid dimensions (max - min): " + size); player.print("Cuboid dimensions (max - min): " + size);
player.print("Offset: " + offset); player.print("Offset: " + origin);
player.print("Cuboid distance: " + size.distance(Vector.ONE)); player.print("Cuboid distance: " + size.distance(Vector.ONE));
player.print("# of blocks: " + (int) (size.getX() * size.getY() * size.getZ())); player.print("# of blocks: " + (int) (size.getX() * size.getY() * size.getZ()));
return; return;

View File

@ -28,22 +28,25 @@ import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
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.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder;
public class ClipboardBrush implements Brush { public class ClipboardBrush implements Brush {
private Clipboard clipboard; private ClipboardHolder holder;
private boolean noAir; private boolean noAir;
public ClipboardBrush(Clipboard clipboard, boolean noAir) { public ClipboardBrush(ClipboardHolder holder, boolean noAir) {
this.clipboard = clipboard; this.holder = holder;
this.noAir = noAir; this.noAir = noAir;
} }
@Override @Override
public void build(EditSession editSession, Vector pos, Pattern mat, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, Vector pos, Pattern mat, double size) throws MaxChangedBlocksException {
Clipboard clipboard = holder.getClipboard();
Region region = clipboard.getRegion(); Region region = clipboard.getRegion();
Vector centerOffset = region.getCenter().subtract(region.getMinimumPoint()); Vector centerOffset = region.getCenter().subtract(clipboard.getOrigin());
ForwardExtentCopy copy = new ForwardExtentCopy(clipboard, clipboard.getRegion(), editSession, pos.subtract(centerOffset)); ForwardExtentCopy copy = new ForwardExtentCopy(clipboard, region, clipboard.getOrigin(), editSession, pos.subtract(centerOffset));
copy.setTransform(holder.getTransform());
if (noAir) { if (noAir) {
copy.setSourceMask(new ExistingBlockMask(clipboard)); copy.setSourceMask(new ExistingBlockMask(clipboard));
} }

View File

@ -23,10 +23,12 @@ import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.pattern.ClipboardPattern; import com.sk89q.worldedit.function.pattern.ClipboardPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.session.ClipboardHolder;
class HashTagPatternParser extends InputParser<Pattern> { class HashTagPatternParser extends InputParser<Pattern> {
@ -45,7 +47,9 @@ class HashTagPatternParser extends InputParser<Pattern> {
if (session != null) { if (session != null) {
try { try {
return new ClipboardPattern(session.getClipboard()); ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard();
return new ClipboardPattern(clipboard);
} catch (EmptyClipboardException e) { } catch (EmptyClipboardException e) {
throw new InputParseException("To use #clipboard, please first copy something to your clipboard"); throw new InputParseException("To use #clipboard, please first copy something to your clipboard");
} }

View File

@ -42,19 +42,21 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class BlockArrayClipboard implements Clipboard { public class BlockArrayClipboard implements Clipboard {
private final Region region; private final Region region;
private Vector offset = new Vector(); private Vector origin = new Vector();
private final BaseBlock[][][] blocks; private final BaseBlock[][][] blocks;
private final List<ClipboardEntity> entities = new ArrayList<ClipboardEntity>(); private final List<ClipboardEntity> entities = new ArrayList<ClipboardEntity>();
/** /**
* Create a new instance. * Create a new instance.
* <p>
* The origin will be placed at the region's lowest minimum point.
* *
* @param region the bounding region * @param region the bounding region
*/ */
public BlockArrayClipboard(Region region) { public BlockArrayClipboard(Region region) {
checkNotNull(region); checkNotNull(region);
checkNotNull(offset);
this.region = region.clone(); this.region = region.clone();
this.origin = region.getMinimumPoint();
Vector dimensions = getDimensions(); Vector dimensions = getDimensions();
blocks = new BaseBlock[dimensions.getBlockX()][dimensions.getBlockY()][dimensions.getBlockZ()]; blocks = new BaseBlock[dimensions.getBlockX()][dimensions.getBlockY()][dimensions.getBlockZ()];
@ -66,22 +68,17 @@ public class BlockArrayClipboard implements Clipboard {
} }
@Override @Override
public Vector getOffset() { public Vector getOrigin() {
return offset; return origin;
} }
@Override @Override
public void setOffset(Vector offset) { public void setOrigin(Vector origin) {
checkNotNull(offset); this.origin = origin;
this.offset = offset;
} }
/** @Override
* Get the dimensions of the copy, which is at minimum (1, 1, 1). public Vector getDimensions() {
*
* @return the dimensions
*/
private Vector getDimensions() {
return region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); return region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
} }

View File

@ -38,21 +38,24 @@ public interface Clipboard extends Extent {
Region getRegion(); Region getRegion();
/** /**
* Get the offset at which the area was copied from. * Get the dimensions of the copy, which is at minimum (1, 1, 1).
* </p>
* The offset is not utilized by clipboards but it can be used
* to store, for example, the relative location from which the copy
* was made.
* *
* @return the offset * @return the dimensions
*/ */
Vector getOffset(); Vector getDimensions();
/** /**
* Set the offset at which the area was copied from. * Get the origin point from which the copy was made from.
* *
* @param offset the offset * @return the origin
*/ */
void setOffset(Vector offset); Vector getOrigin();
/**
* Set the origin point from which the copy was made from.
*
* @param origin the origin
*/
void setOrigin(Vector origin);
} }

View File

@ -64,7 +64,9 @@ public class ExtentBlockCopy implements RegionFunction {
@Override @Override
public boolean apply(Vector position) throws WorldEditException { public boolean apply(Vector position) throws WorldEditException {
BaseBlock block = source.getBlock(position); BaseBlock block = source.getBlock(position);
return destination.setBlock(transform.apply(position.subtract(from)).add(to), block); Vector orig = position.subtract(from);
Vector transformed = transform.apply(orig);
return destination.setBlock(transformed.add(to), block);
} }
} }

View File

@ -48,6 +48,7 @@ public class ForwardExtentCopy implements Operation {
private final Extent source; private final Extent source;
private final Extent destination; private final Extent destination;
private final Region region; private final Region region;
private final Vector from;
private final Vector to; private final Vector to;
private int repetitions = 1; private int repetitions = 1;
private Mask sourceMask = Masks.alwaysTrue(); private Mask sourceMask = Masks.alwaysTrue();
@ -58,21 +59,38 @@ public class ForwardExtentCopy implements Operation {
private int affected; private int affected;
/** /**
* Create a new copy. * Create a new copy using the region's lowest minimum point as the
* "from" position.
* *
* @param source the source extent * @param source the source extent
* @param region the region to copy * @param region the region to copy
* @param destination the destination extent * @param destination the destination extent
* @param to the destination position, starting from the the lowest X, Y, Z * @param to the destination position
* @see #ForwardExtentCopy(Extent, Region, Vector, Extent, Vector) the main constructor
*/ */
public ForwardExtentCopy(Extent source, Region region, Extent destination, Vector to) { public ForwardExtentCopy(Extent source, Region region, Extent destination, Vector to) {
this(source, region, region.getMinimumPoint(), destination, to);
}
/**
* Create a new copy.
*
* @param source the source extent
* @param region the region to copy
* @param from the source position
* @param destination the destination extent
* @param to the destination position
*/
public ForwardExtentCopy(Extent source, Region region, Vector from, Extent destination, Vector to) {
checkNotNull(source); checkNotNull(source);
checkNotNull(region); checkNotNull(region);
checkNotNull(from);
checkNotNull(destination); checkNotNull(destination);
checkNotNull(to); checkNotNull(to);
this.source = source; this.source = source;
this.destination = destination; this.destination = destination;
this.region = region; this.region = region;
this.from = from;
this.to = to; this.to = to;
} }
@ -182,7 +200,7 @@ public class ForwardExtentCopy implements Operation {
currentTransform = transform; currentTransform = transform;
} }
ExtentBlockCopy copy = new ExtentBlockCopy(source, region.getMinimumPoint(), destination, to, currentTransform); ExtentBlockCopy copy = new ExtentBlockCopy(source, from, destination, to, currentTransform);
RegionMaskingFilter filter = new RegionMaskingFilter(sourceMask, copy); RegionMaskingFilter filter = new RegionMaskingFilter(sourceMask, copy);
RegionFunction function = sourceFunction != null ? new CombinedRegionFunction(filter, sourceFunction) : filter; RegionFunction function = sourceFunction != null ? new CombinedRegionFunction(filter, sourceFunction) : filter;
RegionVisitor visitor = new RegionVisitor(region, function); RegionVisitor visitor = new RegionVisitor(region, function);

View File

@ -0,0 +1,77 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.session;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.transform.Identity;
import com.sk89q.worldedit.math.transform.Transform;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Holds the clipboard and the current transform on the clipboard.
*/
public class ClipboardHolder {
private final Clipboard clipboard;
private Transform transform = new Identity();
/**
* Create a new instance with the given clipboard.
*
* @param clipboard the clipboard
*/
public ClipboardHolder(Clipboard clipboard) {
checkNotNull(clipboard);
this.clipboard = clipboard;
}
/**
* Get the clipboard.
* <p>
* If there is a transformation applied, the returned clipboard will
* not contain its effect.
*
* @return the clipboard
*/
public Clipboard getClipboard() {
return clipboard;
}
/**
* Set the transform.
*
* @param transform the transform
*/
public void setTransform(Transform transform) {
checkNotNull(transform);
this.transform = transform;
}
/**
* Get the transform.
*
* @return the transform
*/
public Transform getTransform() {
return transform;
}
}