Skip to content

Commit cc32178

Browse files
committed
Add clipboard support to //deform
1 parent 83e66b2 commit cc32178

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.RegionMaskingFilter;
@@ -52,6 +53,7 @@
5253
import com.sk89q.worldedit.internal.expression.ExpressionException;
5354
import com.sk89q.worldedit.internal.util.TransformUtil;
5455
import com.sk89q.worldedit.math.BlockVector3;
56+
import com.sk89q.worldedit.math.Vector3;
5557
import com.sk89q.worldedit.math.convolution.GaussianKernel;
5658
import com.sk89q.worldedit.math.convolution.HeightMap;
5759
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
@@ -502,13 +504,28 @@ public int deform(Actor actor, LocalSession session, EditSession editSession,
502504
@Switch(name = 'o', desc = "Use the placement's coordinate origin")
503505
boolean offsetPlacement,
504506
@Switch(name = 'c', desc = "Use the selection's center as origin")
505-
boolean offsetCenter) throws WorldEditException {
507+
boolean offsetCenter,
508+
@Switch(name = 'l', desc = "Fetch from the clipboard instead of the world")
509+
boolean useClipboard) throws WorldEditException {
510+
final Transform targetTransform = TransformUtil.createTransformForExpressionCommand(actor, session, region, useRawCoords, offsetPlacement, offsetCenter);
506511

507-
final Transform transform = TransformUtil.createTransformForExpressionCommand(actor, session, region, useRawCoords, offsetPlacement, offsetCenter);
508-
final InputExtent inputExtent = editSession.getWorld();
512+
final InputExtent sourceExtent;
513+
final Transform sourceTransform;
514+
if (useClipboard) {
515+
final Clipboard clipboard = session.getClipboard().getClipboard();
516+
sourceExtent = clipboard;
517+
518+
final Vector3 clipboardMin = clipboard.getMinimumPoint().toVector3();
519+
final Vector3 clipboardMax = clipboard.getMaximumPoint().toVector3();
520+
521+
sourceTransform = TransformUtil.createTransformForExpressionCommand(useRawCoords, offsetPlacement, offsetCenter, clipboardMin, clipboardMax, clipboardMin);
522+
} else {
523+
sourceExtent = editSession.getWorld();
524+
sourceTransform = targetTransform;
525+
}
509526

510527
try {
511-
final int affected = editSession.deformRegion(region, transform, String.join(" ", expression), session.getTimeout(), inputExtent, transform);
528+
final int affected = editSession.deformRegion(region, targetTransform, String.join(" ", expression), session.getTimeout(), sourceExtent, sourceTransform);
512529
if (actor instanceof Player) {
513530
((Player) actor).findFreePosition();
514531
}

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 ScaleAndTranslateTransform(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)