Skip to content

Commit 9b9275a

Browse files
committed
Add clipboard support to //deform
1 parent e54d84d commit 9b9275a

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.sk89q.worldedit.extent.Extent;
3434
import com.sk89q.worldedit.extent.InputExtent;
3535
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
36+
import com.sk89q.worldedit.extent.clipboard.Clipboard;
3637
import com.sk89q.worldedit.function.GroundFunction;
3738
import com.sk89q.worldedit.function.RegionFunction;
3839
import com.sk89q.worldedit.function.block.BlockReplace;
@@ -50,6 +51,7 @@
5051
import com.sk89q.worldedit.internal.expression.ExpressionException;
5152
import com.sk89q.worldedit.internal.util.TransformUtil;
5253
import com.sk89q.worldedit.math.BlockVector3;
54+
import com.sk89q.worldedit.math.Vector3;
5355
import com.sk89q.worldedit.math.convolution.GaussianKernel;
5456
import com.sk89q.worldedit.math.convolution.HeightMap;
5557
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
@@ -499,13 +501,28 @@ public int deform(Actor actor, LocalSession session, EditSession editSession,
499501
@Switch(name = 'o', desc = "Use the placement's coordinate origin")
500502
boolean offsetPlacement,
501503
@Switch(name = 'c', desc = "Use the selection's center as origin")
502-
boolean offsetCenter) throws WorldEditException {
504+
boolean offsetCenter,
505+
@Switch(name = 'l', desc = "Fetch from the clipboard instead of the world")
506+
boolean useClipboard) throws WorldEditException {
507+
final Transform outputTransform = TransformUtil.createTransformForExpressionCommand(actor, session, region, useRawCoords, offsetPlacement, offsetCenter);
503508

504-
final Transform transform = TransformUtil.createTransformForExpressionCommand(actor, session, region, useRawCoords, offsetPlacement, offsetCenter);
505-
final InputExtent inputExtent = editSession.getWorld();
509+
final InputExtent inputExtent;
510+
final Transform inputTransform;
511+
if (useClipboard) {
512+
final Clipboard clipboard = session.getClipboard().getClipboard();
513+
inputExtent = clipboard;
514+
515+
final Vector3 clipboardMin = clipboard.getMinimumPoint().toVector3();
516+
final Vector3 clipboardMax = clipboard.getMaximumPoint().toVector3();
517+
518+
inputTransform = TransformUtil.createTransformForExpressionCommand(useRawCoords, offsetPlacement, offsetCenter, clipboardMin, clipboardMax, clipboardMin);
519+
} else {
520+
inputExtent = editSession.getWorld();
521+
inputTransform = outputTransform;
522+
}
506523

507524
try {
508-
final int affected = editSession.deformRegion(region, transform, String.join(" ", expression), session.getTimeout(), inputExtent, transform);
525+
final int affected = editSession.deformRegion(region, outputTransform, String.join(" ", expression), session.getTimeout(), inputExtent, inputTransform);
509526
if (actor instanceof Player) {
510527
((Player) actor).findFreePosition();
511528
}

worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/TransformUtil.java

+19-4
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,33 @@ private TransformUtil() {
4848
* @return A transform from the expression coordinate system to the raw coordinate system
4949
*/
5050
public static Transform createTransformForExpressionCommand(Actor actor, LocalSession session, Region region, boolean useRawCoords, boolean offsetPlacement, boolean offsetCenter) throws IncompleteRegionException {
51+
final Vector3 placement = session.getPlacementPosition(actor).toVector3();
52+
final Vector3 min = region.getMinimumPoint().toVector3();
53+
final Vector3 max = region.getMaximumPoint().toVector3();
54+
55+
return createTransformForExpressionCommand(useRawCoords, offsetPlacement, offsetCenter, min, max, placement);
56+
}
57+
58+
/**
59+
* Creates a {@link Transform} for the //deform command with clipboard support.
60+
*
61+
* @param useRawCoords Use the game's coordinate origin
62+
* @param offsetPlacement Use the placement's coordinate origin
63+
* @param offsetCenter Use the selection's center as origin
64+
* @param min Minimum of the selection/clipboard
65+
* @param max Maximum of the selection/clipboard
66+
* @param placement Placement position
67+
* @return A transform from the expression coordinate system to the world/clipboard coordinate system
68+
*/
69+
public static Transform createTransformForExpressionCommand(boolean useRawCoords, boolean offsetPlacement, boolean offsetCenter, Vector3 min, Vector3 max, Vector3 placement) {
5170
if (useRawCoords) {
5271
return new Identity();
5372
}
5473

5574
if (offsetPlacement) {
56-
final Vector3 placement = session.getPlacementPosition(actor).toVector3();
57-
5875
return new SimpleTransform(placement, Vector3.ONE);
5976
}
6077

61-
final Vector3 min = region.getMinimumPoint().toVector3();
62-
final Vector3 max = region.getMaximumPoint().toVector3();
6378
final Vector3 center = max.add(min).multiply(0.5);
6479

6580
if (offsetCenter) {

0 commit comments

Comments
 (0)