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 ;
95
96
import com .sk89q .worldedit .math .interpolation .Node ;
96
97
import com .sk89q .worldedit .math .noise .RandomNoise ;
97
98
import com .sk89q .worldedit .math .transform .AffineTransform ;
99
+ import com .sk89q .worldedit .math .transform .SimpleTransform ;
100
+ import com .sk89q .worldedit .math .transform .Transform ;
98
101
import com .sk89q .worldedit .regions .CuboidRegion ;
99
102
import com .sk89q .worldedit .regions .CylinderRegion ;
100
103
import com .sk89q .worldedit .regions .EllipsoidRegion ;
@@ -2247,7 +2250,7 @@ public int makeShape(final Region region, final Vector3 zero, final Vector3 unit
2247
2250
final Variable dataVariable = expression .getSlots ().getVariable ("data" )
2248
2251
.orElseThrow (IllegalStateException ::new );
2249
2252
2250
- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , unit , zero );
2253
+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , new SimpleTransform ( zero , unit ) );
2251
2254
expression .setEnvironment (environment );
2252
2255
2253
2256
final int [] timedOut = {0 };
@@ -2314,7 +2317,8 @@ protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial)
2314
2317
*/
2315
2318
public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final String expressionString )
2316
2319
throws ExpressionException , MaxChangedBlocksException {
2317
- return deformRegion (region , zero , unit , expressionString , WorldEdit .getInstance ().getConfiguration ().calculationTimeout );
2320
+ final Transform transform = new SimpleTransform (zero , unit );
2321
+ return deformRegion (region , transform , expressionString , WorldEdit .getInstance ().getConfiguration ().calculationTimeout , world , transform );
2318
2322
}
2319
2323
2320
2324
/**
@@ -2333,11 +2337,33 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
2333
2337
* @throws ExpressionException thrown on invalid expression input
2334
2338
* @throws MaxChangedBlocksException thrown if too many blocks are changed
2335
2339
*/
2340
+ @ Deprecated
2336
2341
public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final String expressionString ,
2337
2342
final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2343
+ final Transform transform = new SimpleTransform (zero , unit );
2344
+ return deformRegion (region , transform , expressionString , timeout , world , transform );
2345
+ }
2346
+
2347
+ /**
2348
+ * Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
2349
+ * to an expression, and then sets the block to the block given by the resulting values of the variables, if they
2350
+ * have changed.
2351
+ *
2352
+ * @param region the region to deform
2353
+ * @param outputTransform the output coordinate system
2354
+ * @param expressionString the expression to evaluate for each block
2355
+ * @param timeout maximum time for the expression to evaluate for each block. -1 for unlimited.
2356
+ * @param inputExtent the InputExtent to fetch blocks from, for instance a World or a Clipboard
2357
+ * @param inputTransform the input coordinate system
2358
+ * @return number of blocks changed
2359
+ * @throws ExpressionException thrown on invalid expression input
2360
+ * @throws MaxChangedBlocksException thrown if too many blocks are changed
2361
+ */
2362
+ public int deformRegion (final Region region , final Transform outputTransform , final String expressionString ,
2363
+ final int timeout , final InputExtent inputExtent , final Transform inputTransform ) throws ExpressionException , MaxChangedBlocksException {
2338
2364
final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
2339
2365
expression .optimize ();
2340
- return deformRegion (region , zero , unit , expression , timeout );
2366
+ return deformRegion (region , outputTransform , expression , timeout , inputExtent , inputTransform );
2341
2367
}
2342
2368
2343
2369
/**
@@ -2347,32 +2373,47 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
2347
2373
* The Expression class is subject to change. Expressions should be provided via the string overload.
2348
2374
* </p>
2349
2375
*/
2376
+ @ Deprecated
2350
2377
public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final Expression expression ,
2351
2378
final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2379
+ final Transform transform = new SimpleTransform (zero , unit );
2380
+ return deformRegion (region , transform , expression , timeout , world , transform );
2381
+ }
2382
+
2383
+ /**
2384
+ * Internal version of {@link EditSession#deformRegion(Region, Vector3, Vector3, String, int)}.
2385
+ *
2386
+ * <p>
2387
+ * The Expression class is subject to change. Expressions should be provided via the string overload.
2388
+ * </p>
2389
+ */
2390
+ public int deformRegion (final Region region , final Transform outputTransform , final Expression expression ,
2391
+ final int timeout , InputExtent inputExtent , final Transform inputTransform ) throws ExpressionException , MaxChangedBlocksException {
2352
2392
final Variable x = expression .getSlots ().getVariable ("x" )
2353
2393
.orElseThrow (IllegalStateException ::new );
2354
2394
final Variable y = expression .getSlots ().getVariable ("y" )
2355
2395
.orElseThrow (IllegalStateException ::new );
2356
2396
final Variable z = expression .getSlots ().getVariable ("z" )
2357
2397
.orElseThrow (IllegalStateException ::new );
2358
2398
2359
- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , unit , zero );
2399
+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , outputTransform );
2360
2400
expression .setEnvironment (environment );
2361
2401
2362
2402
final DoubleArrayList <BlockVector3 , BaseBlock > queue = new DoubleArrayList <>(false );
2363
2403
2404
+ final Transform outputTransformInverse = outputTransform .inverse ();
2364
2405
for (BlockVector3 position : region ) {
2365
2406
// transform
2366
- final Vector3 scaled = position .toVector3 (). subtract ( zero ). divide ( unit );
2407
+ final Vector3 scaled = outputTransformInverse . apply ( position .toVector3 ());
2367
2408
2368
2409
// deform
2369
2410
expression .evaluate (new double []{scaled .getX (), scaled .getY (), scaled .getZ ()}, timeout );
2370
2411
2371
2412
// untransform, round-nearest
2372
- final BlockVector3 sourcePosition = environment . toWorld ( x .getValue (), y .getValue (), z .getValue ());
2413
+ final BlockVector3 sourcePosition = inputTransform . apply ( Vector3 . at ( x .getValue (), y .getValue (), z .getValue ())). add ( 0.5 , 0.5 , 0.5 ). toBlockPoint ( );
2373
2414
2374
- // read block from world
2375
- final BaseBlock material = world .getFullBlock (sourcePosition );
2415
+ // read block from world/clipboard
2416
+ final BaseBlock material = inputExtent .getFullBlock (sourcePosition );
2376
2417
2377
2418
// queue operation
2378
2419
queue .put (position , material );
0 commit comments