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 ;
@@ -2495,6 +2496,28 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
24952496 return deformRegion (region , transform , expressionString , timeout );
24962497 }
24972498
2499+ /**
2500+ * Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
2501+ * to an expression, and then sets the block to the block given by the resulting values of the variables, if they
2502+ * have changed.
2503+ *
2504+ * @param region the region to deform
2505+ * @param targetTransform the target coordinate system
2506+ * @param expressionString the expression to evaluate for each block
2507+ * @param timeout maximum time for the expression to evaluate for each block. -1 for unlimited.
2508+ * @param sourceExtent the InputExtent to fetch blocks from, for instance a World or a Clipboard
2509+ * @param sourceTransform the source coordinate system
2510+ * @return number of blocks changed
2511+ * @throws ExpressionException thrown on invalid expression input
2512+ * @throws MaxChangedBlocksException thrown if too many blocks are changed
2513+ */
2514+ public int deformRegion (final Region region , final Transform targetTransform , final String expressionString ,
2515+ final int timeout , InputExtent sourceExtent , Transform sourceTransform ) throws ExpressionException , MaxChangedBlocksException {
2516+ final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
2517+ expression .optimize ();
2518+ return deformRegion (region , targetTransform , expression , timeout , sourceExtent , sourceTransform );
2519+ }
2520+
24982521 /**
24992522 * Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
25002523 * to an expression, and then sets the block to the block given by the resulting values of the variables, if they
@@ -2508,11 +2531,10 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
25082531 * @throws ExpressionException thrown on invalid expression input
25092532 * @throws MaxChangedBlocksException thrown if too many blocks are changed
25102533 */
2534+ @ Deprecated
25112535 public int deformRegion (final Region region , final Transform transform , final String expressionString ,
25122536 final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2513- final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
2514- expression .optimize ();
2515- return deformRegion (region , transform , expression , timeout );
2537+ return deformRegion (region , transform , expressionString , timeout , world , transform );
25162538 }
25172539
25182540 /**
@@ -2525,7 +2547,8 @@ public int deformRegion(final Region region, final Transform transform, final St
25252547 @ Deprecated
25262548 public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final Expression expression ,
25272549 final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2528- return deformRegion (region , new ScaleAndTranslateTransform (zero , unit ), expression , timeout );
2550+ final Transform transform = new ScaleAndTranslateTransform (zero , unit );
2551+ return deformRegion (region , transform , expression , timeout , world , transform );
25292552 }
25302553
25312554 /**
@@ -2535,37 +2558,37 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
25352558 * The Expression class is subject to change. Expressions should be provided via the string overload.
25362559 * </p>
25372560 */
2538- public int deformRegion (final Region region , final Transform transform , final Expression expression ,
2539- final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2561+ public int deformRegion (final Region region , final Transform targetTransform , final Expression expression ,
2562+ final int timeout , InputExtent sourceExtent , final Transform sourceTransform ) throws ExpressionException , MaxChangedBlocksException {
25402563 final Variable x = expression .getSlots ().getVariable ("x" )
25412564 .orElseThrow (IllegalStateException ::new );
25422565 final Variable y = expression .getSlots ().getVariable ("y" )
25432566 .orElseThrow (IllegalStateException ::new );
25442567 final Variable z = expression .getSlots ().getVariable ("z" )
25452568 .orElseThrow (IllegalStateException ::new );
25462569
2547- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , transform );
2570+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , targetTransform );
25482571 expression .setEnvironment (environment );
25492572
25502573 final DoubleArrayList <BlockVector3 , BaseBlock > queue = new DoubleArrayList <>(false );
25512574
2552- final Transform transformInverse = transform .inverse ();
2575+ final Transform targetTransformInverse = targetTransform .inverse ();
25532576 for (BlockVector3 targetBlockPosition : region ) {
25542577 final Vector3 targetPosition = targetBlockPosition .toVector3 ();
25552578 environment .setCurrentBlock (targetPosition );
25562579
25572580 // transform from target coordinates
2558- final Vector3 inputPosition = transformInverse .apply (targetPosition );
2581+ final Vector3 inputPosition = targetTransformInverse .apply (targetPosition );
25592582
25602583 // deform
25612584 expression .evaluate (new double []{ inputPosition .x (), inputPosition .y (), inputPosition .z () }, timeout );
25622585 final Vector3 outputPosition = Vector3 .at (x .value (), y .value (), z .value ());
25632586
25642587 // transform to source coordinates, round-nearest
2565- final BlockVector3 sourcePosition = transform .apply (outputPosition ).add (0.5 , 0.5 , 0.5 ).toBlockPoint ();
2588+ final BlockVector3 sourcePosition = sourceTransform .apply (outputPosition ).add (0.5 , 0.5 , 0.5 ).toBlockPoint ();
25662589
2567- // read block from world
2568- final BaseBlock material = world .getFullBlock (sourcePosition );
2590+ // read block from source extent (e.g. world/clipboard)
2591+ final BaseBlock material = sourceExtent .getFullBlock (sourcePosition );
25692592
25702593 // queue operation
25712594 queue .put (targetBlockPosition , material );
0 commit comments