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 ;
@@ -2451,6 +2452,28 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
24512452 return deformRegion (region , transform , expressionString , timeout );
24522453 }
24532454
2455+ /**
2456+ * Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
2457+ * to an expression, and then sets the block to the block given by the resulting values of the variables, if they
2458+ * have changed.
2459+ *
2460+ * @param region the region to deform
2461+ * @param targetTransform the target coordinate system
2462+ * @param expressionString the expression to evaluate for each block
2463+ * @param timeout maximum time for the expression to evaluate for each block. -1 for unlimited.
2464+ * @param sourceExtent the InputExtent to fetch blocks from, for instance a World or a Clipboard
2465+ * @param sourceTransform the source coordinate system
2466+ * @return number of blocks changed
2467+ * @throws ExpressionException thrown on invalid expression input
2468+ * @throws MaxChangedBlocksException thrown if too many blocks are changed
2469+ */
2470+ public int deformRegion (final Region region , final Transform targetTransform , final String expressionString ,
2471+ final int timeout , InputExtent sourceExtent , Transform sourceTransform ) throws ExpressionException , MaxChangedBlocksException {
2472+ final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
2473+ expression .optimize ();
2474+ return deformRegion (region , targetTransform , expression , timeout , sourceExtent , sourceTransform );
2475+ }
2476+
24542477 /**
24552478 * Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
24562479 * to an expression, and then sets the block to the block given by the resulting values of the variables, if they
@@ -2464,11 +2487,10 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
24642487 * @throws ExpressionException thrown on invalid expression input
24652488 * @throws MaxChangedBlocksException thrown if too many blocks are changed
24662489 */
2490+ @ Deprecated
24672491 public int deformRegion (final Region region , final Transform transform , final String expressionString ,
24682492 final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2469- final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
2470- expression .optimize ();
2471- return deformRegion (region , transform , expression , timeout );
2493+ return deformRegion (region , transform , expressionString , timeout , world , transform );
24722494 }
24732495
24742496 /**
@@ -2481,7 +2503,8 @@ public int deformRegion(final Region region, final Transform transform, final St
24812503 @ Deprecated
24822504 public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final Expression expression ,
24832505 final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2484- return deformRegion (region , new SimpleTransform (zero , unit ), expression , timeout );
2506+ final Transform transform = new SimpleTransform (zero , unit );
2507+ return deformRegion (region , transform , expression , timeout , world , transform );
24852508 }
24862509
24872510 /**
@@ -2491,37 +2514,37 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
24912514 * The Expression class is subject to change. Expressions should be provided via the string overload.
24922515 * </p>
24932516 */
2494- public int deformRegion (final Region region , final Transform transform , final Expression expression ,
2495- final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2517+ public int deformRegion (final Region region , final Transform targetTransform , final Expression expression ,
2518+ final int timeout , InputExtent sourceExtent , final Transform sourceTransform ) throws ExpressionException , MaxChangedBlocksException {
24962519 final Variable x = expression .getSlots ().getVariable ("x" )
24972520 .orElseThrow (IllegalStateException ::new );
24982521 final Variable y = expression .getSlots ().getVariable ("y" )
24992522 .orElseThrow (IllegalStateException ::new );
25002523 final Variable z = expression .getSlots ().getVariable ("z" )
25012524 .orElseThrow (IllegalStateException ::new );
25022525
2503- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , transform );
2526+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , targetTransform );
25042527 expression .setEnvironment (environment );
25052528
25062529 final DoubleArrayList <BlockVector3 , BaseBlock > queue = new DoubleArrayList <>(false );
25072530
2508- final Transform transformInverse = transform .inverse ();
2531+ final Transform targetTransformInverse = targetTransform .inverse ();
25092532 for (BlockVector3 targetBlockPosition : region ) {
25102533 final Vector3 targetPosition = targetBlockPosition .toVector3 ();
25112534 environment .setCurrentBlock (targetPosition );
25122535
25132536 // transform from target coordinates
2514- final Vector3 inputPosition = transformInverse .apply (targetPosition );
2537+ final Vector3 inputPosition = targetTransformInverse .apply (targetPosition );
25152538
25162539 // deform
25172540 expression .evaluate (new double []{ inputPosition .x (), inputPosition .y (), inputPosition .z () }, timeout );
25182541 final Vector3 outputPosition = Vector3 .at (x .value (), y .value (), z .value ());
25192542
25202543 // transform to source coordinates, round-nearest
2521- final BlockVector3 sourcePosition = transform .apply (outputPosition ).add (0.5 , 0.5 , 0.5 ).toBlockPoint ();
2544+ final BlockVector3 sourcePosition = sourceTransform .apply (outputPosition ).add (0.5 , 0.5 , 0.5 ).toBlockPoint ();
25222545
2523- // read block from world
2524- final BaseBlock material = world .getFullBlock (sourcePosition );
2546+ // read block from source extent (e.g. world/clipboard)
2547+ final BaseBlock material = sourceExtent .getFullBlock (sourcePosition );
25252548
25262549 // queue operation
25272550 queue .put (targetBlockPosition , material );
0 commit comments