Add clipboard support to //deform

This commit is contained in:
TomyLobo 2024-07-14 09:14:00 +02:00
parent 83e66b2fcf
commit cc32178907
2 changed files with 40 additions and 8 deletions

View File

@ -33,6 +33,7 @@
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.InputExtent;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.GroundFunction;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.RegionMaskingFilter;
@ -52,6 +53,7 @@
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.internal.util.TransformUtil;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.convolution.GaussianKernel;
import com.sk89q.worldedit.math.convolution.HeightMap;
import com.sk89q.worldedit.math.convolution.HeightMapFilter;
@ -502,13 +504,28 @@ public int deform(Actor actor, LocalSession session, EditSession editSession,
@Switch(name = 'o', desc = "Use the placement's coordinate origin")
boolean offsetPlacement,
@Switch(name = 'c', desc = "Use the selection's center as origin")
boolean offsetCenter) throws WorldEditException {
boolean offsetCenter,
@Switch(name = 'l', desc = "Fetch from the clipboard instead of the world")
boolean useClipboard) throws WorldEditException {
final Transform targetTransform = TransformUtil.createTransformForExpressionCommand(actor, session, region, useRawCoords, offsetPlacement, offsetCenter);
final Transform transform = TransformUtil.createTransformForExpressionCommand(actor, session, region, useRawCoords, offsetPlacement, offsetCenter);
final InputExtent inputExtent = editSession.getWorld();
final InputExtent sourceExtent;
final Transform sourceTransform;
if (useClipboard) {
final Clipboard clipboard = session.getClipboard().getClipboard();
sourceExtent = clipboard;
final Vector3 clipboardMin = clipboard.getMinimumPoint().toVector3();
final Vector3 clipboardMax = clipboard.getMaximumPoint().toVector3();
sourceTransform = TransformUtil.createTransformForExpressionCommand(useRawCoords, offsetPlacement, offsetCenter, clipboardMin, clipboardMax, clipboardMin);
} else {
sourceExtent = editSession.getWorld();
sourceTransform = targetTransform;
}
try {
final int affected = editSession.deformRegion(region, transform, String.join(" ", expression), session.getTimeout(), inputExtent, transform);
final int affected = editSession.deformRegion(region, targetTransform, String.join(" ", expression), session.getTimeout(), sourceExtent, sourceTransform);
if (actor instanceof Player) {
((Player) actor).findFreePosition();
}

View File

@ -48,18 +48,33 @@ private TransformUtil() {
* @return A transform from the expression coordinate system to the raw coordinate system
*/
public static Transform createTransformForExpressionCommand(Actor actor, LocalSession session, Region region, boolean useRawCoords, boolean offsetPlacement, boolean offsetCenter) throws IncompleteRegionException {
final Vector3 placement = session.getPlacementPosition(actor).toVector3();
final Vector3 min = region.getMinimumPoint().toVector3();
final Vector3 max = region.getMaximumPoint().toVector3();
return createTransformForExpressionCommand(useRawCoords, offsetPlacement, offsetCenter, min, max, placement);
}
/**
* Creates a {@link Transform} for the //deform command with clipboard support.
*
* @param useRawCoords Use the game's coordinate origin
* @param offsetPlacement Use the placement's coordinate origin
* @param offsetCenter Use the selection's center as origin
* @param min Minimum of the selection/clipboard
* @param max Maximum of the selection/clipboard
* @param placement Placement position
* @return A transform from the expression coordinate system to the world/clipboard coordinate system
*/
public static Transform createTransformForExpressionCommand(boolean useRawCoords, boolean offsetPlacement, boolean offsetCenter, Vector3 min, Vector3 max, Vector3 placement) {
if (useRawCoords) {
return new Identity();
}
if (offsetPlacement) {
final Vector3 placement = session.getPlacementPosition(actor).toVector3();
return new ScaleAndTranslateTransform(placement, Vector3.ONE);
}
final Vector3 min = region.getMinimumPoint().toVector3();
final Vector3 max = region.getMaximumPoint().toVector3();
final Vector3 center = max.add(min).multiply(0.5);
if (offsetCenter) {