2828import com .sk89q .worldedit .extension .platform .Watchdog ;
2929import com .sk89q .worldedit .extent .ChangeSetExtent ;
3030import com .sk89q .worldedit .extent .Extent ;
31+ import com .sk89q .worldedit .extent .InputExtent ;
3132import com .sk89q .worldedit .extent .MaskingExtent ;
3233import com .sk89q .worldedit .extent .NullExtent ;
3334import com .sk89q .worldedit .extent .TracingExtent ;
@@ -2437,6 +2438,28 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
24372438 return deformRegion (region , transform , expressionString , timeout );
24382439 }
24392440
2441+ /**
2442+ * Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
2443+ * to an expression, and then sets the block to the block given by the resulting values of the variables, if they
2444+ * have changed.
2445+ *
2446+ * @param region the region to deform
2447+ * @param outputTransform the output coordinate system
2448+ * @param expressionString the expression to evaluate for each block
2449+ * @param timeout maximum time for the expression to evaluate for each block. -1 for unlimited.
2450+ * @param inputExtent the InputExtent to fetch blocks from, for instance a World or a Clipboard
2451+ * @param inputTransform the input coordinate system
2452+ * @return number of blocks changed
2453+ * @throws ExpressionException thrown on invalid expression input
2454+ * @throws MaxChangedBlocksException thrown if too many blocks are changed
2455+ */
2456+ public int deformRegion (final Region region , final Transform outputTransform , final String expressionString ,
2457+ final int timeout , InputExtent inputExtent , Transform inputTransform ) throws ExpressionException , MaxChangedBlocksException {
2458+ final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
2459+ expression .optimize ();
2460+ return deformRegion (region , outputTransform , expression , timeout , inputExtent , inputTransform );
2461+ }
2462+
24402463 /**
24412464 * Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
24422465 * to an expression, and then sets the block to the block given by the resulting values of the variables, if they
@@ -2450,11 +2473,10 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
24502473 * @throws ExpressionException thrown on invalid expression input
24512474 * @throws MaxChangedBlocksException thrown if too many blocks are changed
24522475 */
2476+ @ Deprecated
24532477 public int deformRegion (final Region region , final Transform transform , final String expressionString ,
24542478 final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2455- final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
2456- expression .optimize ();
2457- return deformRegion (region , transform , expression , timeout );
2479+ return deformRegion (region , transform , expressionString , timeout , world , transform );
24582480 }
24592481
24602482 /**
@@ -2467,7 +2489,8 @@ public int deformRegion(final Region region, final Transform transform, final St
24672489 @ Deprecated
24682490 public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final Expression expression ,
24692491 final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2470- return deformRegion (region , new SimpleTransform (zero , unit ), expression , timeout );
2492+ final Transform transform = new SimpleTransform (zero , unit );
2493+ return deformRegion (region , transform , expression , timeout , world , transform );
24712494 }
24722495
24732496 /**
@@ -2477,33 +2500,33 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
24772500 * The Expression class is subject to change. Expressions should be provided via the string overload.
24782501 * </p>
24792502 */
2480- public int deformRegion (final Region region , final Transform transform , final Expression expression ,
2481- final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2503+ public int deformRegion (final Region region , final Transform outputTransform , final Expression expression ,
2504+ final int timeout , InputExtent inputExtent , final Transform inputTransform ) throws ExpressionException , MaxChangedBlocksException {
24822505 final Variable x = expression .getSlots ().getVariable ("x" )
24832506 .orElseThrow (IllegalStateException ::new );
24842507 final Variable y = expression .getSlots ().getVariable ("y" )
24852508 .orElseThrow (IllegalStateException ::new );
24862509 final Variable z = expression .getSlots ().getVariable ("z" )
24872510 .orElseThrow (IllegalStateException ::new );
24882511
2489- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , transform );
2512+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , outputTransform );
24902513 expression .setEnvironment (environment );
24912514
24922515 final DoubleArrayList <BlockVector3 , BaseBlock > queue = new DoubleArrayList <>(false );
24932516
2494- final Transform transformInverse = transform .inverse ();
2517+ final Transform outputTransformInverse = outputTransform .inverse ();
24952518 for (BlockVector3 position : region ) {
24962519 // transform
2497- final Vector3 scaled = transformInverse .apply (position .toVector3 ());
2520+ final Vector3 scaled = outputTransformInverse .apply (position .toVector3 ());
24982521
24992522 // deform
25002523 expression .evaluate (new double []{ scaled .x (), scaled .y (), scaled .z () }, timeout );
25012524
25022525 // untransform, round-nearest
2503- final BlockVector3 sourcePosition = transform .apply (Vector3 .at (x .value (), y .value (), z .value ())).add (0.5 , 0.5 , 0.5 ).toBlockPoint ();
2526+ final BlockVector3 sourcePosition = inputTransform .apply (Vector3 .at (x .value (), y .value (), z .value ())).add (0.5 , 0.5 , 0.5 ).toBlockPoint ();
25042527
2505- // read block from world
2506- final BaseBlock material = world .getFullBlock (sourcePosition );
2528+ // read block from world/clipboard
2529+ final BaseBlock material = inputExtent .getFullBlock (sourcePosition );
25072530
25082531 // queue operation
25092532 queue .put (position , material );
0 commit comments