28
28
import com .sk89q .worldedit .extension .platform .Watchdog ;
29
29
import com .sk89q .worldedit .extent .ChangeSetExtent ;
30
30
import com .sk89q .worldedit .extent .Extent ;
31
+ import com .sk89q .worldedit .extent .InputExtent ;
31
32
import com .sk89q .worldedit .extent .MaskingExtent ;
32
33
import com .sk89q .worldedit .extent .NullExtent ;
33
34
import com .sk89q .worldedit .extent .TracingExtent ;
@@ -2451,6 +2452,28 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
2451
2452
return deformRegion (region , transform , expressionString , timeout );
2452
2453
}
2453
2454
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
+
2454
2477
/**
2455
2478
* Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
2456
2479
* 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
2464
2487
* @throws ExpressionException thrown on invalid expression input
2465
2488
* @throws MaxChangedBlocksException thrown if too many blocks are changed
2466
2489
*/
2490
+ @ Deprecated
2467
2491
public int deformRegion (final Region region , final Transform transform , final String expressionString ,
2468
2492
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 );
2472
2494
}
2473
2495
2474
2496
/**
@@ -2481,7 +2503,8 @@ public int deformRegion(final Region region, final Transform transform, final St
2481
2503
@ Deprecated
2482
2504
public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final Expression expression ,
2483
2505
final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2484
- return deformRegion (region , new ScaleAndTranslateTransform (zero , unit ), expression , timeout );
2506
+ final Transform transform = new ScaleAndTranslateTransform (zero , unit );
2507
+ return deformRegion (region , transform , expression , timeout , world , transform );
2485
2508
}
2486
2509
2487
2510
/**
@@ -2491,37 +2514,37 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
2491
2514
* The Expression class is subject to change. Expressions should be provided via the string overload.
2492
2515
* </p>
2493
2516
*/
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 {
2496
2519
final Variable x = expression .getSlots ().getVariable ("x" )
2497
2520
.orElseThrow (IllegalStateException ::new );
2498
2521
final Variable y = expression .getSlots ().getVariable ("y" )
2499
2522
.orElseThrow (IllegalStateException ::new );
2500
2523
final Variable z = expression .getSlots ().getVariable ("z" )
2501
2524
.orElseThrow (IllegalStateException ::new );
2502
2525
2503
- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , transform );
2526
+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , targetTransform );
2504
2527
expression .setEnvironment (environment );
2505
2528
2506
2529
final DoubleArrayList <BlockVector3 , BaseBlock > queue = new DoubleArrayList <>(false );
2507
2530
2508
- final Transform transformInverse = transform .inverse ();
2531
+ final Transform targetTransformInverse = targetTransform .inverse ();
2509
2532
for (BlockVector3 targetBlockPosition : region ) {
2510
2533
final Vector3 targetPosition = targetBlockPosition .toVector3 ();
2511
2534
environment .setCurrentBlock (targetPosition );
2512
2535
2513
2536
// transform from target coordinates
2514
- final Vector3 inputPosition = transformInverse .apply (targetPosition );
2537
+ final Vector3 inputPosition = targetTransformInverse .apply (targetPosition );
2515
2538
2516
2539
// deform
2517
2540
expression .evaluate (new double []{ inputPosition .x (), inputPosition .y (), inputPosition .z () }, timeout );
2518
2541
final Vector3 outputPosition = Vector3 .at (x .value (), y .value (), z .value ());
2519
2542
2520
2543
// 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 ();
2522
2545
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 );
2525
2548
2526
2549
// queue operation
2527
2550
queue .put (targetBlockPosition , material );
0 commit comments