34
34
import com .sk89q .worldedit .function .operation .RunContext ;
35
35
import com .sk89q .worldedit .internal .expression .Expression ;
36
36
import com .sk89q .worldedit .internal .expression .ExpressionException ;
37
+ import com .sk89q .worldedit .math .BlockVector3 ;
37
38
import com .sk89q .worldedit .math .Vector3 ;
38
39
import com .sk89q .worldedit .math .transform .Identity ;
39
40
import com .sk89q .worldedit .math .transform .SimpleTransform ;
40
41
import com .sk89q .worldedit .math .transform .Transform ;
41
42
import com .sk89q .worldedit .regions .NullRegion ;
42
43
import com .sk89q .worldedit .regions .Region ;
44
+ import com .sk89q .worldedit .session .Placement ;
45
+ import com .sk89q .worldedit .session .PlacementType ;
43
46
import com .sk89q .worldedit .util .formatting .text .Component ;
44
47
import com .sk89q .worldedit .util .formatting .text .TextComponent ;
45
48
import com .sk89q .worldedit .util .formatting .text .TranslatableComponent ;
@@ -54,7 +57,7 @@ public class Deform implements Contextual<Operation> {
54
57
private Region region ;
55
58
private final Expression expression ;
56
59
private Mode mode ;
57
- private Vector3 offset = Vector3 . ZERO ;
60
+ Placement placement ;
58
61
private boolean useClipboard ;
59
62
60
63
public Deform (String expression ) {
@@ -81,6 +84,17 @@ public Deform(Extent destination, Region region, String expression, Mode mode) {
81
84
this .mode = mode ;
82
85
}
83
86
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
+
84
98
public Extent getDestination () {
85
99
return destination ;
86
100
}
@@ -108,21 +122,17 @@ public void setMode(Mode mode) {
108
122
this .mode = mode ;
109
123
}
110
124
111
- public boolean getUseClipboard () {
112
- return useClipboard ;
113
- }
114
-
115
- public void setUseClipboard (boolean useClipboard ) {
116
- this .useClipboard = useClipboard ;
117
- }
118
-
125
+ @ Deprecated
119
126
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 ();
121
131
}
122
132
123
133
public void setOffset (Vector3 offset ) {
124
134
checkNotNull (offset , "offset" );
125
- this .offset = offset ;
135
+ this .placement = new Placement ( PlacementType . WORLD , offset . toBlockPoint ()) ;
126
136
}
127
137
128
138
@ Override
@@ -176,11 +186,14 @@ public Operation resume(RunContext run) throws WorldEditException {
176
186
177
187
final Vector3 min = region .getMinimumPoint ().toVector3 ();
178
188
final Vector3 max = region .getMaximumPoint ().toVector3 ();
179
- final Transform outputTransform = createTransform (min , max , Deform .this .offset );
180
189
181
190
final LocalSession session = context .getSession ();
182
191
final EditSession editSession = (EditSession ) context .getDestination ();
183
192
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
+
184
197
final InputExtent inputExtent ;
185
198
final Transform inputTransform ;
186
199
if (Deform .this .useClipboard && session != null ) {
0 commit comments