94
94
import com .sk89q .worldedit .math .interpolation .Node ;
95
95
import com .sk89q .worldedit .math .noise .RandomNoise ;
96
96
import com .sk89q .worldedit .math .transform .AffineTransform ;
97
+ import com .sk89q .worldedit .math .transform .SimpleTransform ;
98
+ import com .sk89q .worldedit .math .transform .Transform ;
97
99
import com .sk89q .worldedit .regions .CuboidRegion ;
98
100
import com .sk89q .worldedit .regions .CylinderRegion ;
99
101
import com .sk89q .worldedit .regions .EllipsoidRegion ;
@@ -2267,6 +2269,7 @@ public List<Countable<BlockState>> getBlockDistribution(Region region, boolean s
2267
2269
* @throws ExpressionException if there is a problem with the expression
2268
2270
* @throws MaxChangedBlocksException if the maximum block change limit is exceeded
2269
2271
*/
2272
+ @ Deprecated
2270
2273
public int makeShape (final Region region , final Vector3 zero , final Vector3 unit ,
2271
2274
final Pattern pattern , final String expressionString , final boolean hollow )
2272
2275
throws ExpressionException , MaxChangedBlocksException {
@@ -2287,12 +2290,32 @@ public int makeShape(final Region region, final Vector3 zero, final Vector3 unit
2287
2290
* @throws ExpressionException if there is a problem with the expression
2288
2291
* @throws MaxChangedBlocksException if the maximum block change limit is exceeded
2289
2292
*/
2293
+ @ Deprecated
2290
2294
public int makeShape (final Region region , final Vector3 zero , final Vector3 unit ,
2291
2295
final Pattern pattern , final String expressionString , final boolean hollow , final int timeout )
2292
2296
throws ExpressionException , MaxChangedBlocksException {
2297
+ return makeShape (region , new SimpleTransform (zero , unit ), pattern , expressionString , hollow , timeout );
2298
+ }
2299
+
2300
+ /**
2301
+ * Generate a shape for the given expression.
2302
+ *
2303
+ * @param region the region to generate the shape in
2304
+ * @param transform the transformation for x/y/z variables
2305
+ * @param pattern the default material to make the shape from
2306
+ * @param expressionString the expression defining the shape
2307
+ * @param hollow whether the shape should be hollow
2308
+ * @param timeout the time, in milliseconds, to wait for each expression evaluation before halting it. -1 to disable
2309
+ * @return number of blocks changed
2310
+ * @throws ExpressionException if there is a problem with the expression
2311
+ * @throws MaxChangedBlocksException if the maximum block change limit is exceeded
2312
+ */
2313
+ public int makeShape (final Region region ,
2314
+ Transform transform , final Pattern pattern , final String expressionString , final boolean hollow , final int timeout )
2315
+ throws ExpressionException , MaxChangedBlocksException {
2293
2316
final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" , "type" , "data" );
2294
2317
expression .optimize ();
2295
- return makeShape (region , zero , unit , pattern , expression , hollow , timeout );
2318
+ return makeShape (region , transform , pattern , expression , hollow , timeout );
2296
2319
}
2297
2320
2298
2321
/**
@@ -2302,7 +2325,7 @@ public int makeShape(final Region region, final Vector3 zero, final Vector3 unit
2302
2325
* The Expression class is subject to change. Expressions should be provided via the string overload.
2303
2326
* </p>
2304
2327
*/
2305
- public int makeShape (final Region region , final Vector3 zero , final Vector3 unit ,
2328
+ public int makeShape (final Region region , Transform transform ,
2306
2329
final Pattern pattern , final Expression expression , final boolean hollow , final int timeout )
2307
2330
throws ExpressionException , MaxChangedBlocksException {
2308
2331
@@ -2318,16 +2341,17 @@ public int makeShape(final Region region, final Vector3 zero, final Vector3 unit
2318
2341
final Variable dataVariable = expression .getSlots ().getVariable ("data" )
2319
2342
.orElseThrow (IllegalStateException ::new );
2320
2343
2321
- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , unit , zero );
2344
+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , transform );
2322
2345
expression .setEnvironment (environment );
2323
2346
2324
2347
final int [] timedOut = {0 };
2348
+ final Transform transformInverse = transform .inverse ();
2325
2349
final ArbitraryShape shape = new ArbitraryShape (region ) {
2326
2350
@ Override
2327
2351
protected BaseBlock getMaterial (int x , int y , int z , BaseBlock defaultMaterial ) {
2328
2352
final Vector3 current = Vector3 .at (x , y , z );
2329
2353
environment .setCurrentBlock (current );
2330
- final Vector3 scaled = current . subtract ( zero ). divide ( unit );
2354
+ final Vector3 scaled = transformInverse . apply ( current );
2331
2355
2332
2356
try {
2333
2357
int [] legacy = LegacyMapper .getInstance ().getLegacyFromBlock (defaultMaterial .toImmutableState ());
@@ -2384,9 +2408,10 @@ protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial)
2384
2408
* @throws ExpressionException thrown on invalid expression input
2385
2409
* @throws MaxChangedBlocksException thrown if too many blocks are changed
2386
2410
*/
2411
+ @ Deprecated
2387
2412
public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final String expressionString )
2388
2413
throws ExpressionException , MaxChangedBlocksException {
2389
- return deformRegion (region , zero , unit , expressionString , WorldEdit .getInstance ().getConfiguration ().calculationTimeout );
2414
+ return deformRegion (region , new SimpleTransform ( zero , unit ) , expressionString , WorldEdit .getInstance ().getConfiguration ().calculationTimeout );
2390
2415
}
2391
2416
2392
2417
/**
@@ -2405,11 +2430,31 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
2405
2430
* @throws ExpressionException thrown on invalid expression input
2406
2431
* @throws MaxChangedBlocksException thrown if too many blocks are changed
2407
2432
*/
2433
+ @ Deprecated
2408
2434
public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final String expressionString ,
2409
2435
final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2436
+ final Transform transform = new SimpleTransform (zero , unit );
2437
+ return deformRegion (region , transform , expressionString , timeout );
2438
+ }
2439
+
2440
+ /**
2441
+ * Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
2442
+ * to an expression, and then sets the block to the block given by the resulting values of the variables, if they
2443
+ * have changed.
2444
+ *
2445
+ * @param region the region to deform
2446
+ * @param transform the coordinate system
2447
+ * @param expressionString the expression to evaluate for each block
2448
+ * @param timeout maximum time for the expression to evaluate for each block. -1 for unlimited.
2449
+ * @return number of blocks changed
2450
+ * @throws ExpressionException thrown on invalid expression input
2451
+ * @throws MaxChangedBlocksException thrown if too many blocks are changed
2452
+ */
2453
+ public int deformRegion (final Region region , final Transform transform , final String expressionString ,
2454
+ final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2410
2455
final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
2411
2456
expression .optimize ();
2412
- return deformRegion (region , zero , unit , expression , timeout );
2457
+ return deformRegion (region , transform , expression , timeout );
2413
2458
}
2414
2459
2415
2460
/**
@@ -2419,29 +2464,43 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
2419
2464
* The Expression class is subject to change. Expressions should be provided via the string overload.
2420
2465
* </p>
2421
2466
*/
2467
+ @ Deprecated
2422
2468
public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final Expression expression ,
2423
2469
final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2470
+ return deformRegion (region , new SimpleTransform (zero , unit ), expression , timeout );
2471
+ }
2472
+
2473
+ /**
2474
+ * Internal version of {@link EditSession#deformRegion(Region, Vector3, Vector3, String, int)}.
2475
+ *
2476
+ * <p>
2477
+ * The Expression class is subject to change. Expressions should be provided via the string overload.
2478
+ * </p>
2479
+ */
2480
+ public int deformRegion (final Region region , final Transform transform , final Expression expression ,
2481
+ final int timeout ) throws ExpressionException , MaxChangedBlocksException {
2424
2482
final Variable x = expression .getSlots ().getVariable ("x" )
2425
2483
.orElseThrow (IllegalStateException ::new );
2426
2484
final Variable y = expression .getSlots ().getVariable ("y" )
2427
2485
.orElseThrow (IllegalStateException ::new );
2428
2486
final Variable z = expression .getSlots ().getVariable ("z" )
2429
2487
.orElseThrow (IllegalStateException ::new );
2430
2488
2431
- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , unit , zero );
2489
+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , transform );
2432
2490
expression .setEnvironment (environment );
2433
2491
2434
2492
final DoubleArrayList <BlockVector3 , BaseBlock > queue = new DoubleArrayList <>(false );
2435
2493
2494
+ final Transform transformInverse = transform .inverse ();
2436
2495
for (BlockVector3 position : region ) {
2437
2496
// transform
2438
- final Vector3 scaled = position .toVector3 (). subtract ( zero ). divide ( unit );
2497
+ final Vector3 scaled = transformInverse . apply ( position .toVector3 ());
2439
2498
2440
2499
// deform
2441
2500
expression .evaluate (new double []{ scaled .x (), scaled .y (), scaled .z () }, timeout );
2442
2501
2443
2502
// untransform, round-nearest
2444
- final BlockVector3 sourcePosition = environment . toWorld ( x .value (), y .value (), z .value ());
2503
+ final BlockVector3 sourcePosition = transform . apply ( Vector3 . at ( x .value (), y .value (), z .value ())). add ( 0.5 , 0.5 , 0.5 ). toBlockPoint ( );
2445
2504
2446
2505
// read block from world
2447
2506
final BaseBlock material = world .getFullBlock (sourcePosition );
@@ -2749,28 +2808,36 @@ private void recurseHollow(Region region, BlockVector3 origin, Set<BlockVector3>
2749
2808
}
2750
2809
}
2751
2810
2811
+ @ Deprecated
2752
2812
public int makeBiomeShape (final Region region , final Vector3 zero , final Vector3 unit , final BiomeType biomeType ,
2753
2813
final String expressionString , final boolean hollow ) throws ExpressionException {
2754
2814
return makeBiomeShape (region , zero , unit , biomeType , expressionString , hollow , WorldEdit .getInstance ().getConfiguration ().calculationTimeout );
2755
2815
}
2756
2816
2817
+ @ Deprecated
2757
2818
public int makeBiomeShape (final Region region , final Vector3 zero , final Vector3 unit , final BiomeType biomeType ,
2758
2819
final String expressionString , final boolean hollow , final int timeout ) throws ExpressionException {
2820
+ return makeBiomeShape (region , new SimpleTransform (zero , unit ), biomeType , expressionString , hollow , timeout );
2821
+ }
2822
+
2823
+ public int makeBiomeShape (final Region region , Transform transform , final BiomeType biomeType ,
2824
+ final String expressionString , final boolean hollow , final int timeout ) throws ExpressionException {
2759
2825
2760
2826
final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
2761
2827
expression .optimize ();
2762
2828
2763
2829
final EditSession editSession = this ;
2764
- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (editSession , unit , zero );
2830
+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (editSession , transform );
2765
2831
expression .setEnvironment (environment );
2766
2832
2767
2833
AtomicInteger timedOut = new AtomicInteger ();
2834
+ final Transform transformInverse = transform .inverse ();
2768
2835
final ArbitraryBiomeShape shape = new ArbitraryBiomeShape (region ) {
2769
2836
@ Override
2770
2837
protected BiomeType getBiome (int x , int y , int z , BiomeType defaultBiomeType ) {
2771
2838
final Vector3 current = Vector3 .at (x , y , z );
2772
2839
environment .setCurrentBlock (current );
2773
- final Vector3 scaled = current . subtract ( zero ). divide ( unit );
2840
+ final Vector3 scaled = transformInverse . apply ( current );
2774
2841
2775
2842
try {
2776
2843
if (expression .evaluate (new double []{ scaled .x (), scaled .y (), scaled .z () }, timeout ) <= 0 ) {
0 commit comments