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.
Dieser Commit ist enthalten in:
sk89q 2014-07-02 02:56:21 -07:00
Ursprung 9e8b2d1875
Commit aad7bb47d6
11 geänderte Dateien mit 197 neuen und 77 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -47,6 +47,7 @@ import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern;
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.parametric.Optional;
@ -141,23 +142,17 @@ public class BrushCommands {
)
@CommandPermissions("worldedit.brush.clipboard")
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();
if (clipboard == null) {
player.printError("Copy something first.");
return;
}
Region region = clipboard.getRegion();
Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint());
Vector size = clipboard.getDimensions();
worldEdit.checkMaxBrushRadius(size.getBlockX());
worldEdit.checkMaxBrushRadius(size.getBlockY());
worldEdit.checkMaxBrushRadius(size.getBlockZ());
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.");
}

Datei anzeigen

@ -20,8 +20,6 @@
package com.sk89q.worldedit.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.Logging;
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.Operations;
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.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
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.parametric.Optional;
@ -82,10 +83,10 @@ public class ClipboardCommands {
@Selection Region region, @Switch('e') boolean copyEntities) throws WorldEditException {
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());
Operations.completeLegacy(copy);
session.setClipboard(clipboard);
session.replaceClipboard(clipboard);
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 {
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());
copy.setSourceFunction(new BlockReplace(editSession, leavePattern));
Operations.completeLegacy(copy);
session.setClipboard(clipboard);
session.replaceClipboard(clipboard);
player.print(region.getArea() + " block(s) were copied.");
}
@ -137,16 +138,19 @@ public class ClipboardCommands {
@Switch('a') boolean ignoreAirBlocks, @Switch('o') boolean atOrigin,
@Switch('s') boolean selectPasted) throws WorldEditException {
Clipboard clipboard = session.getClipboard();
Vector to = atOrigin ? clipboard.getRegion().getMinimumPoint(): session.getPlacementPosition(player).add(clipboard.getOffset());
ForwardExtentCopy copy = new ForwardExtentCopy(clipboard, clipboard.getRegion(), editSession, to);
ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard();
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) {
copy.setSourceMask(new ExistingBlockMask(clipboard));
}
Operations.completeLegacy(copy);
if (selectPasted) {
Region region = clipboard.getRegion();
Vector max = to.add(region.getMaximumPoint().subtract(region.getMinimumPoint()));
RegionSelector selector = new CuboidRegionSelector(player.getWorld(), to, max);
session.setRegionSelector(player.getWorld(), selector);
@ -154,38 +158,52 @@ public class ClipboardCommands {
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(
aliases = { "/rotate" },
usage = "<angle-in-degrees>",
usage = "<y-axis> [<x-axis>] [<z-axis>]",
desc = "Rotate the contents of the clipboard",
min = 1,
max = 1
help = "Non-destructively rotate the contents of the clipboard.\n" +
"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")
public void rotate(Player player, LocalSession session, EditSession editSession, CommandContext args) throws CommandException {
// TODO: Update for new clipboard
throw new CommandException("Needs to be re-written again");
public void rotate(Player player, LocalSession session, Double yRotate, @Optional Double xRotate, @Optional Double zRotate) throws WorldEditException {
if ((yRotate != null && Math.abs(yRotate % 90) > 0.001) ||
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(
aliases = { "/flip" },
usage = "[dir]",
flags = "p",
desc = "Flip the contents of the clipboard.",
usage = "[<direction>]",
desc = "Flip the contents of the clipboard",
help =
"Flips the contents of the clipboard.\n" +
"The -p flag flips the selection around the player,\n" +
"instead of the selections center.",
"Flips the contents of the clipboard across the point from which the copy was made.\n",
min = 0,
max = 1
)
@CommandPermissions("worldedit.clipboard.flip")
public void flip(Player player, LocalSession session, EditSession editSession, CommandContext args) throws CommandException {
// TODO: Update for new clipboard
throw new CommandException("Needs to be re-written again");
public void flip(Player player, LocalSession session, EditSession editSession,
@Optional(Direction.AIM) @Direction Vector direction) throws WorldEditException {
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(
@ -223,7 +241,7 @@ public class ClipboardCommands {
)
@CommandPermissions("worldedit.clipboard.clear")
public void clearClipboard(Player player, LocalSession session, EditSession editSession) throws WorldEditException {
session.setClipboard(null);
session.replaceClipboard(null);
player.print("Clipboard cleared.");
}
}

Datei anzeigen

@ -45,6 +45,7 @@ import com.sk89q.worldedit.regions.selector.EllipsoidRegionSelector;
import com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
import com.sk89q.worldedit.regions.selector.SphereRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.world.World;
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 {
if (args.hasFlag('c')) {
Clipboard clipboard = session.getClipboard();
ClipboardHolder holder = session.getClipboard();
Clipboard clipboard = holder.getClipboard();
Region region = clipboard.getRegion();
Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint());
Vector offset = clipboard.getOffset();
Vector origin = clipboard.getOrigin();
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("# of blocks: " + (int) (size.getX() * size.getY() * size.getZ()));
return;

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -38,21 +38,24 @@ public interface Clipboard extends Extent {
Region getRegion();
/**
* Get the offset at which the area was copied from.
* </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.
* Get the dimensions of the copy, which is at minimum (1, 1, 1).
*
* @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);
}

Datei anzeigen

@ -64,7 +64,9 @@ public class ExtentBlockCopy implements RegionFunction {
@Override
public boolean apply(Vector position) throws WorldEditException {
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);
}
}

Datei anzeigen

@ -48,6 +48,7 @@ public class ForwardExtentCopy implements Operation {
private final Extent source;
private final Extent destination;
private final Region region;
private final Vector from;
private final Vector to;
private int repetitions = 1;
private Mask sourceMask = Masks.alwaysTrue();
@ -58,21 +59,38 @@ public class ForwardExtentCopy implements Operation {
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 region the region to copy
* @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) {
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(region);
checkNotNull(from);
checkNotNull(destination);
checkNotNull(to);
this.source = source;
this.destination = destination;
this.region = region;
this.from = from;
this.to = to;
}
@ -182,7 +200,7 @@ public class ForwardExtentCopy implements Operation {
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);
RegionFunction function = sourceFunction != null ? new CombinedRegionFunction(filter, sourceFunction) : filter;
RegionVisitor visitor = new RegionVisitor(region, function);

Datei anzeigen

@ -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;
}
}