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 ;
@@ -2437,6 +2438,28 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
2437
2438
return deformRegion (region , transform , expressionString , timeout );
2438
2439
}
2439
2440
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
+
2440
2463
/**
2441
2464
* Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
2442
2465
* 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
2450
2473
* @throws ExpressionException thrown on invalid expression input
2451
2474
* @throws MaxChangedBlocksException thrown if too many blocks are changed
2452
2475
*/
2476
+ @ Deprecated
2453
2477
public int deformRegion (final Region region , final Transform transform , final String expressionString ,
2454
2478
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 );
2458
2480
}
2459
2481
2460
2482
/**
@@ -2467,7 +2489,8 @@ public int deformRegion(final Region region, final Transform transform, final St
2467
2489
@ Deprecated
2468
2490
public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final Expression expression ,
2469
2491
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 );
2471
2494
}
2472
2495
2473
2496
/**
@@ -2477,33 +2500,33 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
2477
2500
* The Expression class is subject to change. Expressions should be provided via the string overload.
2478
2501
* </p>
2479
2502
*/
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 {
2482
2505
final Variable x = expression .getSlots ().getVariable ("x" )
2483
2506
.orElseThrow (IllegalStateException ::new );
2484
2507
final Variable y = expression .getSlots ().getVariable ("y" )
2485
2508
.orElseThrow (IllegalStateException ::new );
2486
2509
final Variable z = expression .getSlots ().getVariable ("z" )
2487
2510
.orElseThrow (IllegalStateException ::new );
2488
2511
2489
- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , transform );
2512
+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , outputTransform );
2490
2513
expression .setEnvironment (environment );
2491
2514
2492
2515
final DoubleArrayList <BlockVector3 , BaseBlock > queue = new DoubleArrayList <>(false );
2493
2516
2494
- final Transform transformInverse = transform .inverse ();
2517
+ final Transform outputTransformInverse = outputTransform .inverse ();
2495
2518
for (BlockVector3 position : region ) {
2496
2519
// transform
2497
- final Vector3 scaled = transformInverse .apply (position .toVector3 ());
2520
+ final Vector3 scaled = outputTransformInverse .apply (position .toVector3 ());
2498
2521
2499
2522
// deform
2500
2523
expression .evaluate (new double []{ scaled .x (), scaled .y (), scaled .z () }, timeout );
2501
2524
2502
2525
// 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 ();
2504
2527
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 );
2507
2530
2508
2531
// queue operation
2509
2532
queue .put (position , material );
0 commit comments