3434import com .sk89q .worldedit .function .operation .RunContext ;
3535import com .sk89q .worldedit .internal .expression .Expression ;
3636import com .sk89q .worldedit .internal .expression .ExpressionException ;
37+ import com .sk89q .worldedit .math .BlockVector3 ;
3738import com .sk89q .worldedit .math .Vector3 ;
3839import com .sk89q .worldedit .math .transform .Identity ;
3940import com .sk89q .worldedit .math .transform .SimpleTransform ;
4041import com .sk89q .worldedit .math .transform .Transform ;
4142import com .sk89q .worldedit .regions .NullRegion ;
4243import com .sk89q .worldedit .regions .Region ;
44+ import com .sk89q .worldedit .session .Placement ;
45+ import com .sk89q .worldedit .session .PlacementType ;
4346import com .sk89q .worldedit .util .formatting .text .Component ;
4447import com .sk89q .worldedit .util .formatting .text .TextComponent ;
4548import com .sk89q .worldedit .util .formatting .text .TranslatableComponent ;
@@ -54,7 +57,7 @@ public class Deform implements Contextual<Operation> {
5457 private Region region ;
5558 private final Expression expression ;
5659 private Mode mode ;
57- private Vector3 offset = Vector3 . ZERO ;
60+ Placement placement ;
5861 private boolean useClipboard ;
5962
6063 public Deform (String expression ) {
@@ -81,6 +84,17 @@ public Deform(Extent destination, Region region, String expression, Mode mode) {
8184 this .mode = mode ;
8285 }
8386
87+ public Deform (Placement placement , String expression , Mode mode ) {
88+ checkNotNull (mode , "mode" );
89+ checkNotNull (expression , "expression" );
90+
91+ this .placement = placement ;
92+ this .expression = Expression .compile (expression , "x" , "y" , "z" );
93+ this .expression .optimize ();
94+ this .mode = mode ;
95+ }
96+
97+
8498 public Extent getDestination () {
8599 return destination ;
86100 }
@@ -108,21 +122,17 @@ public void setMode(Mode mode) {
108122 this .mode = mode ;
109123 }
110124
111- public boolean getUseClipboard () {
112- return useClipboard ;
113- }
114-
115- public void setUseClipboard (boolean useClipboard ) {
116- this .useClipboard = useClipboard ;
117- }
118-
125+ @ Deprecated
119126 public Vector3 getOffset () {
120- return offset ;
127+ if (this .placement .getPlacementType () != PlacementType .WORLD ) {
128+ throw new IllegalStateException ("Deform.getOffset is deprecated and only supported after using setOffset." );
129+ }
130+ return placement .getOffset ().toVector3 ();
121131 }
122132
123133 public void setOffset (Vector3 offset ) {
124134 checkNotNull (offset , "offset" );
125- this .offset = offset ;
135+ this .placement = new Placement ( PlacementType . WORLD , offset . toBlockPoint ()) ;
126136 }
127137
128138 @ Override
@@ -176,11 +186,14 @@ public Operation resume(RunContext run) throws WorldEditException {
176186
177187 final Vector3 min = region .getMinimumPoint ().toVector3 ();
178188 final Vector3 max = region .getMaximumPoint ().toVector3 ();
179- final Transform outputTransform = createTransform (min , max , Deform .this .offset );
180189
181190 final LocalSession session = context .getSession ();
182191 final EditSession editSession = (EditSession ) context .getDestination ();
183192
193+ // TODO: deal with session == null
194+ final BlockVector3 placement = Deform .this .placement .getPlacementPosition (session .getRegionSelector (editSession .getWorld ()), editSession .getActor ());
195+ final Transform outputTransform = createTransform (min , max , placement .toVector3 ());
196+
184197 final InputExtent inputExtent ;
185198 final Transform inputTransform ;
186199 if (Deform .this .useClipboard && session != null ) {
0 commit comments