1
+ dofile (minetest .get_modpath (" worldedit_commands" ) .. " /cuboidapi.lua" )
2
+
3
+
4
+ minetest .register_chatcommand (" /outset" , {
5
+ params = " [h|v] <amount>" ,
6
+ description = " outset the selection" ,
7
+ privs = {worldedit = true },
8
+ func = function (name , param )
9
+ local find , _ , dir , amount = param :find (" (%a*)%s*([+-]?%d+)" )
10
+
11
+ if find == nil then
12
+ return false , " invalid usage: " .. param
13
+ end
14
+
15
+ local pos1 = worldedit .pos1 [name ]
16
+ local pos2 = worldedit .pos2 [name ]
17
+
18
+ if pos1 == nil or pos2 == nil then
19
+ return false ,
20
+ " Undefined region. Region must be defined beforehand."
21
+ end
22
+
23
+ local hv_test = dir :find (" [^hv]+" )
24
+
25
+ if hv_test ~= nil then
26
+ return false , " Invalid direction."
27
+ end
28
+
29
+ if dir == " " or dir == " hv" or dir == " vh" then
30
+ assert (worldedit .cuboid_volumetric_expand (name , amount ))
31
+ elseif dir == " h" then
32
+ assert (worldedit .cuboid_linear_expand (name , ' x' , 1 , amount ))
33
+ assert (worldedit .cuboid_linear_expand (name , ' x' , - 1 , amount ))
34
+ assert (worldedit .cuboid_linear_expand (name , ' z' , 1 , amount ))
35
+ assert (worldedit .cuboid_linear_expand (name , ' z' , - 1 , amount ))
36
+ elseif dir == " v" then
37
+ assert (worldedit .cuboid_linear_expand (name , ' y' , 1 , amount ))
38
+ assert (worldedit .cuboid_linear_expand (name , ' y' , - 1 , amount ))
39
+ else
40
+ return false , " Invalid number of arguments"
41
+ end
42
+
43
+ worldedit .marker_update (name )
44
+ return true , " Region outset by " .. amount .. " blocks"
45
+ end ,
46
+ }
47
+ )
48
+
49
+
50
+ minetest .register_chatcommand (" /inset" , {
51
+ params = " [h|v] <amount>" ,
52
+ description = " inset the selection" ,
53
+ privs = {worldedit = true },
54
+ func = function (name , param )
55
+ local find , _ , dir , amount = param :find (" (%a*)%s*([+-]?%d+)" )
56
+
57
+ if find == nil then
58
+ return false , " invalid usage: " .. param
59
+ end
60
+
61
+ local pos1 = worldedit .pos1 [name ]
62
+ local pos2 = worldedit .pos2 [name ]
63
+
64
+ if pos1 == nil or pos2 == nil then
65
+ return false ,
66
+ " Undefined region. Region must be defined beforehand."
67
+ end
68
+
69
+ local hv_test = dir :find (" [^hv]+" )
70
+
71
+ if hv_test ~= nil then
72
+ return false , " Invalid direction."
73
+ end
74
+
75
+ if dir == " " or dir == " vh" or dir == " hv" then
76
+ assert (worldedit .cuboid_volumetric_expand (name , - amount ))
77
+ elseif dir == " h" then
78
+ assert (worldedit .cuboid_linear_expand (name , ' x' , 1 , - amount ))
79
+ assert (worldedit .cuboid_linear_expand (name , ' x' , - 1 , - amount ))
80
+ assert (worldedit .cuboid_linear_expand (name , ' z' , 1 , - amount ))
81
+ assert (worldedit .cuboid_linear_expand (name , ' z' , - 1 , - amount ))
82
+ elseif dir == " v" then
83
+ assert (worldedit .cuboid_linear_expand (name , ' y' , 1 , - amount ))
84
+ assert (worldedit .cuboid_linear_expand (name , ' y' , - 1 , - amount ))
85
+ else
86
+ return false , " Invalid number of arguments"
87
+ end
88
+
89
+ worldedit .marker_update (name )
90
+ return true , " Region inset by " .. amount .. " blocks"
91
+ end ,
92
+ }
93
+ )
94
+
95
+
96
+ minetest .register_chatcommand (" /shift" , {
97
+ params = " [x|y|z|?|up|down|left|right|front|back] [+|-]<amount>" ,
98
+ description = " Moves the selection region. Does not move contents." ,
99
+ privs = {worldedit = true },
100
+ func = function (name , param )
101
+ local pos1 = worldedit .pos1 [name ]
102
+ local pos2 = worldedit .pos2 [name ]
103
+ local find , _ , direction , amount = param :find (" ([%?%l]+)%s*([+-]?%d+)" )
104
+
105
+ if find == nil then
106
+ worldedit .player_notify (name , " invalid usage: " .. param )
107
+ return
108
+ end
109
+
110
+ if pos1 == nil or pos2 == nil then
111
+ worldedit .player_notify (name ,
112
+ " Undefined region. Region must be defined beforehand." )
113
+ return
114
+ end
115
+
116
+ local axis , dir
117
+ if direction ~= " ?" then
118
+ axis , dir = worldedit .translate_direction (name , direction )
119
+ else
120
+ axis , dir = worldedit .player_axis (name )
121
+ end
122
+
123
+ if axis == nil or dir == nil then
124
+ return false , " Invalid if looking straight up or down"
125
+ end
126
+
127
+ assert (worldedit .cuboid_shift (name , axis , amount * dir ))
128
+ worldedit .marker_update (name )
129
+
130
+ return true , " region shifted by " .. amount .. " nodes"
131
+ end ,
132
+ }
133
+ )
134
+
135
+
136
+ minetest .register_chatcommand (" /expand" , {
137
+ params = " [+|-]<x|y|z|?|up|down|left|right|front|back> <amount> [reverse-amount]" ,
138
+ description = " expand the selection in one or two directions at once" ,
139
+ privs = {worldedit = true },
140
+ func = function (name , param )
141
+ local find , _ , sign , direction , amount ,
142
+ rev_amount = param :find (" ([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)" )
143
+
144
+ if find == nil then
145
+ worldedit .player_notify (name , " invalid use: " .. param )
146
+ return
147
+ end
148
+
149
+ if worldedit .pos1 [name ] == nil or worldedit .pos2 [name ] == nil then
150
+ worldedit .player_notify (name ,
151
+ " Undefined region. Region must be defined beforehand." )
152
+ return
153
+ end
154
+
155
+ local absolute = direction :find (" [xyz?]" )
156
+ local dir , axis
157
+
158
+ if rev_amount == " " then
159
+ rev_amount = 0
160
+ end
161
+
162
+ if absolute == nil then
163
+ axis , dir = worldedit .translate_direction (name , direction )
164
+
165
+ if axis == nil or dir == nil then
166
+ return false , " Invalid if looking straight up or down"
167
+ end
168
+ else
169
+ if direction == " ?" then
170
+ axis , dir = worldedit .player_axis (name )
171
+ else
172
+ axis = direction
173
+ dir = 1
174
+ end
175
+ end
176
+
177
+ if sign == " -" then
178
+ dir = - dir
179
+ end
180
+
181
+ worldedit .cuboid_linear_expand (name , axis , dir , amount )
182
+ worldedit .cuboid_linear_expand (name , axis , - dir , rev_amount )
183
+ worldedit .marker_update (name )
184
+ end ,
185
+ }
186
+ )
187
+
188
+
189
+ minetest .register_chatcommand (" /contract" , {
190
+ params = " [+|-]<x|y|z|?|up|down|left|right|front|back> <amount> [reverse-amount]" ,
191
+ description = " contract the selection in one or two directions at once" ,
192
+ privs = {worldedit = true },
193
+ func = function (name , param )
194
+ local find , _ , sign , direction , amount ,
195
+ rev_amount = param :find (" ([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)" )
196
+
197
+ if find == nil then
198
+ worldedit .player_notify (name , " invalid use: " .. param )
199
+ return
200
+ end
201
+
202
+ if worldedit .pos1 [name ] == nil or worldedit .pos2 [name ] == nil then
203
+ worldedit .player_notify (name ,
204
+ " Undefined region. Region must be defined beforehand." )
205
+ return
206
+ end
207
+
208
+ local absolute = direction :find (" [xyz?]" )
209
+ local dir , axis
210
+
211
+ if rev_amount == " " then
212
+ rev_amount = 0
213
+ end
214
+
215
+ if absolute == nil then
216
+ axis , dir = worldedit .translate_direction (name , direction )
217
+
218
+ if axis == nil or dir == nil then
219
+ return false , " Invalid if looking straight up or down"
220
+ end
221
+ else
222
+ if direction == " ?" then
223
+ axis , dir = worldedit .player_axis (name )
224
+ else
225
+ axis = direction
226
+ dir = 1
227
+ end
228
+ end
229
+
230
+ if sign == " -" then
231
+ dir = - dir
232
+ end
233
+
234
+ worldedit .cuboid_linear_expand (name , axis , dir , - amount )
235
+ worldedit .cuboid_linear_expand (name , axis , - dir , - rev_amount )
236
+ worldedit .marker_update (name )
237
+ end ,
238
+ }
239
+ )
0 commit comments