27
27
import com .sk89q .worldedit .extent .Extent ;
28
28
import com .sk89q .worldedit .extent .InputExtent ;
29
29
import com .sk89q .worldedit .extent .NullExtent ;
30
+ import com .sk89q .worldedit .extent .clipboard .Clipboard ;
30
31
import com .sk89q .worldedit .function .Contextual ;
31
32
import com .sk89q .worldedit .function .EditContext ;
32
33
import com .sk89q .worldedit .function .operation .Operation ;
38
39
import com .sk89q .worldedit .math .transform .Transform ;
39
40
import com .sk89q .worldedit .regions .NullRegion ;
40
41
import com .sk89q .worldedit .regions .Region ;
42
+ import com .sk89q .worldedit .session .ClipboardHolder ;
41
43
import com .sk89q .worldedit .util .formatting .text .Component ;
42
44
import com .sk89q .worldedit .util .formatting .text .TextComponent ;
43
45
import com .sk89q .worldedit .util .formatting .text .TranslatableComponent ;
44
46
import com .sk89q .worldedit .util .formatting .text .format .TextColor ;
45
47
48
+ import java .util .Optional ;
49
+
46
50
import static com .google .common .base .Preconditions .checkNotNull ;
47
51
import static com .sk89q .worldedit .util .GuavaUtil .firstNonNull ;
48
52
@@ -53,6 +57,7 @@ public class Deform implements Contextual<Operation> {
53
57
private final Expression expression ;
54
58
private Mode mode ;
55
59
private Vector3 offset = Vector3 .ZERO ;
60
+ private boolean useClipboard ;
56
61
57
62
public Deform (String expression ) {
58
63
this (new NullExtent (), new NullRegion (), expression );
@@ -114,6 +119,14 @@ public void setOffset(Vector3 offset) {
114
119
this .offset = offset ;
115
120
}
116
121
122
+ public boolean useClipboard () {
123
+ return useClipboard ;
124
+ }
125
+
126
+ public void setUseClipboard (boolean useClipboard ) {
127
+ this .useClipboard = useClipboard ;
128
+ }
129
+
117
130
@ Override
118
131
public String toString () {
119
132
return "deformation of " + expression .getSource ();
@@ -126,11 +139,29 @@ public Operation createFromContext(final EditContext context) {
126
139
final Vector3 min = region .getMinimumPoint ().toVector3 ();
127
140
final Vector3 max = region .getMaximumPoint ().toVector3 ();
128
141
129
- final Transform transform = TransformUtil .createTransformForExpressionCommand (mode , min , max , offset );
130
142
LocalSession session = context .getSession ();
131
143
EditSession editSession = (EditSession ) context .getDestination ();
132
- return new DeformOperation (context .getDestination (), region , transform , expression ,
133
- session == null ? WorldEdit .getInstance ().getConfiguration ().calculationTimeout : session .getTimeout (), editSession .getWorld (), transform );
144
+ final Optional <Clipboard > clipboardOptional = Optional .ofNullable (session )
145
+ .flatMap (LocalSession ::getClipboardOptional )
146
+ .map (ClipboardHolder ::getClipboard );
147
+
148
+ final Transform targetTransform = TransformUtil .createTransformForExpressionCommand (mode , min , max , offset );
149
+ final InputExtent sourceExtent ;
150
+ final Transform sourceTransform ;
151
+ if (useClipboard && clipboardOptional .isPresent ()) {
152
+ final Clipboard clipboard = clipboardOptional .get ();
153
+ final Vector3 clipboardMin = clipboard .getMinimumPoint ().toVector3 ();
154
+ final Vector3 clipboardMax = clipboard .getMaximumPoint ().toVector3 ();
155
+
156
+ sourceExtent = clipboard ;
157
+ sourceTransform = TransformUtil .createTransformForExpressionCommand (mode , clipboardMin , clipboardMax , offset );
158
+ } else {
159
+ sourceExtent = editSession .getWorld ();
160
+ sourceTransform = targetTransform ;
161
+ }
162
+
163
+ return new DeformOperation (context .getDestination (), region , targetTransform , expression ,
164
+ session == null ? WorldEdit .getInstance ().getConfiguration ().calculationTimeout : session .getTimeout (), sourceExtent , sourceTransform );
134
165
}
135
166
136
167
private record DeformOperation (
0 commit comments