2828import com .sk89q .worldedit .extension .platform .Watchdog ;
2929import com .sk89q .worldedit .extent .ChangeSetExtent ;
3030import com .sk89q .worldedit .extent .Extent ;
31+ import com .sk89q .worldedit .extent .InputExtent ;
3132import com .sk89q .worldedit .extent .MaskingExtent ;
3233import com .sk89q .worldedit .extent .NullExtent ;
3334import com .sk89q .worldedit .extent .TracingExtent ;
9596import com .sk89q .worldedit .math .interpolation .Node ;
9697import com .sk89q .worldedit .math .noise .RandomNoise ;
9798import com .sk89q .worldedit .math .transform .AffineTransform ;
99+ import com .sk89q .worldedit .math .transform .SimpleTransform ;
100+ import com .sk89q .worldedit .math .transform .Transform ;
98101import com .sk89q .worldedit .regions .CuboidRegion ;
99102import com .sk89q .worldedit .regions .CylinderRegion ;
100103import com .sk89q .worldedit .regions .EllipsoidRegion ;
@@ -2247,7 +2250,7 @@ public int makeShape(final Region region, final Vector3 zero, final Vector3 unit
22472250 final Variable dataVariable = expression .getSlots ().getVariable ("data" )
22482251 .orElseThrow (IllegalStateException ::new );
22492252
2250- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , unit , zero );
2253+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , new SimpleTransform ( zero , unit ) );
22512254 expression .setEnvironment (environment );
22522255
22532256 final int [] timedOut = {0 };
@@ -2314,7 +2317,8 @@ protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial)
23142317 */
23152318 public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final String expressionString )
23162319 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 );
23182322 }
23192323
23202324 /**
@@ -2333,11 +2337,33 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
23332337 * @throws ExpressionException thrown on invalid expression input
23342338 * @throws MaxChangedBlocksException thrown if too many blocks are changed
23352339 */
2340+ @ Deprecated
23362341 public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final String expressionString ,
23372342 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 {
23382364 final Expression expression = Expression .compile (expressionString , "x" , "y" , "z" );
23392365 expression .optimize ();
2340- return deformRegion (region , zero , unit , expression , timeout );
2366+ return deformRegion (region , outputTransform , expression , timeout , inputExtent , inputTransform );
23412367 }
23422368
23432369 /**
@@ -2347,32 +2373,47 @@ public int deformRegion(final Region region, final Vector3 zero, final Vector3 u
23472373 * The Expression class is subject to change. Expressions should be provided via the string overload.
23482374 * </p>
23492375 */
2376+ @ Deprecated
23502377 public int deformRegion (final Region region , final Vector3 zero , final Vector3 unit , final Expression expression ,
23512378 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 {
23522392 final Variable x = expression .getSlots ().getVariable ("x" )
23532393 .orElseThrow (IllegalStateException ::new );
23542394 final Variable y = expression .getSlots ().getVariable ("y" )
23552395 .orElseThrow (IllegalStateException ::new );
23562396 final Variable z = expression .getSlots ().getVariable ("z" )
23572397 .orElseThrow (IllegalStateException ::new );
23582398
2359- final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , unit , zero );
2399+ final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment (this , outputTransform );
23602400 expression .setEnvironment (environment );
23612401
23622402 final DoubleArrayList <BlockVector3 , BaseBlock > queue = new DoubleArrayList <>(false );
23632403
2404+ final Transform outputTransformInverse = outputTransform .inverse ();
23642405 for (BlockVector3 position : region ) {
23652406 // transform
2366- final Vector3 scaled = position .toVector3 (). subtract ( zero ). divide ( unit );
2407+ final Vector3 scaled = outputTransformInverse . apply ( position .toVector3 ());
23672408
23682409 // deform
23692410 expression .evaluate (new double []{scaled .getX (), scaled .getY (), scaled .getZ ()}, timeout );
23702411
23712412 // 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 ( );
23732414
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 );
23762417
23772418 // queue operation
23782419 queue .put (position , material );
0 commit comments