9494import com .sk89q .worldedit .math .interpolation .Node ;
9595import com .sk89q .worldedit .math .noise .RandomNoise ;
9696import com .sk89q .worldedit .math .transform .AffineTransform ;
97+ import com .sk89q .worldedit .math .transform .SimpleTransform ;
98+ import com .sk89q .worldedit .math .transform .Transform ;
9799import com .sk89q .worldedit .regions .CuboidRegion ;
98100import com .sk89q .worldedit .regions .CylinderRegion ;
99101import com .sk89q .worldedit .regions .EllipsoidRegion ;
@@ -2267,6 +2269,7 @@ public List<Countable<BlockState>> getBlockDistribution(Region region, boolean s
22672269 * @throws ExpressionException if there is a problem with the expression
22682270 * @throws MaxChangedBlocksException if the maximum block change limit is exceeded
22692271 */
2272+ @ Deprecated
22702273 public int makeShape (final Region region , final Vector3 zero , final Vector3 unit ,
22712274 final Pattern pattern , final String expressionString , final boolean hollow )
22722275 throws ExpressionException , MaxChangedBlocksException {
@@ -2287,12 +2290,32 @@ public int makeShape(final Region region, final Vector3 zero, final Vector3 unit
22872290 * @throws ExpressionException if there is a problem with the expression
22882291 * @throws MaxChangedBlocksException if the maximum block change limit is exceeded
22892292 */
2293+ @ Deprecated
22902294 public int makeShape (final Region region , final Vector3 zero , final Vector3 unit ,
22912295 final Pattern pattern , final String expressionString , final boolean hollow , final int timeout )
22922296 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 {
22932316 final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" , "type" , "data" );
22942317 expression .optimize ();
2295- return makeShape (region , zero , unit , pattern , expression , hollow , timeout );
2318+ return makeShape (region , transform , pattern , expression , hollow , timeout );
22962319 }
22972320
22982321 /**
@@ -2302,7 +2325,7 @@ public int makeShape(final Region region, final Vector3 zero, final Vector3 unit
23022325 * The Expression class is subject to change. Expressions should be provided via the string overload.
23032326 * </p>
23042327 */
2305- public int makeShape (final Region region , final Vector3 zero , final Vector3 unit ,
2328+ public int makeShape (final Region region , Transform transform ,
23062329 final Pattern pattern , final Expression expression , final boolean hollow , final int timeout )
23072330 throws ExpressionException , MaxChangedBlocksException {
23082331
@@ -2318,16 +2341,17 @@ public int makeShape(final Region region, final Vector3 zero, final Vector3 unit
23182341 final Variable dataVariable = expression .getSlots ().getVariable ("data" )
23192342 .orElseThrow (IllegalStateException ::new );
23202343
2321- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , unit , zero );
2344+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , transform );
23222345 expression .setEnvironment (environment );
23232346
23242347 final int [] timedOut = {0 };
2348+ final Transform transformInverse = transform .inverse ();
23252349 final ArbitraryShape shape = new ArbitraryShape (region ) {
23262350 @ Override
23272351 protected BaseBlock getMaterial (int x , int y , int z , BaseBlock defaultMaterial ) {
23282352 final Vector3 current = Vector3 .at (x , y , z );
23292353 environment .setCurrentBlock (current );
2330- final Vector3 scaled = current . subtract ( zero ). divide ( unit );
2354+ final Vector3 scaled = transformInverse . apply ( current );
23312355
23322356 try {
23332357 int [] legacy = LegacyMapper .getInstance ().getLegacyFromBlock (defaultMaterial .toImmutableState ());
@@ -2384,9 +2408,10 @@ protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial)
23842408 * @throws ExpressionException thrown on invalid expression input
23852409 * @throws MaxChangedBlocksException thrown if too many blocks are changed
23862410 */
2411+ @ Deprecated
23872412 public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final String expressionString )
23882413 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 );
23902415 }
23912416
23922417 /**
@@ -2405,11 +2430,31 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
24052430 * @throws ExpressionException thrown on invalid expression input
24062431 * @throws MaxChangedBlocksException thrown if too many blocks are changed
24072432 */
2433+ @ Deprecated
24082434 public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final String expressionString ,
24092435 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 {
24102455 final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
24112456 expression .optimize ();
2412- return deformRegion (region , zero , unit , expression , timeout );
2457+ return deformRegion (region , transform , expression , timeout );
24132458 }
24142459
24152460 /**
@@ -2419,29 +2464,43 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
24192464 * The Expression class is subject to change. Expressions should be provided via the string overload.
24202465 * </p>
24212466 */
2467+ @ Deprecated
24222468 public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final Expression expression ,
24232469 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 {
24242482 final Variable x = expression .getSlots ().getVariable ("x" )
24252483 .orElseThrow (IllegalStateException ::new );
24262484 final Variable y = expression .getSlots ().getVariable ("y" )
24272485 .orElseThrow (IllegalStateException ::new );
24282486 final Variable z = expression .getSlots ().getVariable ("z" )
24292487 .orElseThrow (IllegalStateException ::new );
24302488
2431- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , unit , zero );
2489+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , transform );
24322490 expression .setEnvironment (environment );
24332491
24342492 final DoubleArrayList <BlockVector3 , BaseBlock > queue = new DoubleArrayList <>(false );
24352493
2494+ final Transform transformInverse = transform .inverse ();
24362495 for (BlockVector3 position : region ) {
24372496 // transform
2438- final Vector3 scaled = position .toVector3 (). subtract ( zero ). divide ( unit );
2497+ final Vector3 scaled = transformInverse . apply ( position .toVector3 ());
24392498
24402499 // deform
24412500 expression .evaluate (new double []{ scaled .x (), scaled .y (), scaled .z () }, timeout );
24422501
24432502 // 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 ( );
24452504
24462505 // read block from world
24472506 final BaseBlock material = world .getFullBlock (sourcePosition );
@@ -2749,28 +2808,36 @@ private void recurseHollow(Region region, BlockVector3 origin, Set<BlockVector3>
27492808 }
27502809 }
27512810
2811+ @ Deprecated
27522812 public int makeBiomeShape (final Region region , final Vector3 zero , final Vector3 unit , final BiomeType biomeType ,
27532813 final String expressionString , final boolean hollow ) throws ExpressionException {
27542814 return makeBiomeShape (region , zero , unit , biomeType , expressionString , hollow , WorldEdit .getInstance ().getConfiguration ().calculationTimeout );
27552815 }
27562816
2817+ @ Deprecated
27572818 public int makeBiomeShape (final Region region , final Vector3 zero , final Vector3 unit , final BiomeType biomeType ,
27582819 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 {
27592825
27602826 final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
27612827 expression .optimize ();
27622828
27632829 final EditSession editSession = this ;
2764- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (editSession , unit , zero );
2830+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (editSession , transform );
27652831 expression .setEnvironment (environment );
27662832
27672833 AtomicInteger timedOut = new AtomicInteger ();
2834+ final Transform transformInverse = transform .inverse ();
27682835 final ArbitraryBiomeShape shape = new ArbitraryBiomeShape (region ) {
27692836 @ Override
27702837 protected BiomeType getBiome (int x , int y , int z , BiomeType defaultBiomeType ) {
27712838 final Vector3 current = Vector3 .at (x , y , z );
27722839 environment .setCurrentBlock (current );
2773- final Vector3 scaled = current . subtract ( zero ). divide ( unit );
2840+ final Vector3 scaled = transformInverse . apply ( current );
27742841
27752842 try {
27762843 if (expression .evaluate (new double []{ scaled .x (), scaled .y (), scaled .z () }, timeout ) <= 0 ) {
0 commit comments