@@ -122,11 +122,12 @@ minetest.register_chatcommand("/shift", {
122
122
123
123
124
124
minetest .register_chatcommand (" /expand" , {
125
- params = " <amount> [reverse-amount] [ up|down|left|right|front|back]" ,
125
+ params = " [+|-]<x|y|z|?| up|down|left|right|front|back> <amount> [reverse-amount ]" ,
126
126
description = " expand the selection in one or two directions at once" ,
127
127
privs = {worldedit = true },
128
128
func = function (name , param )
129
- local find , _ , amount , arg2 , arg3 = param :find (" (%d+)%s*(%w*)%s*(%l*)" )
129
+ local find , _ , sign , direction , amount ,
130
+ rev_amount = param :find (" ([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)" )
130
131
131
132
if find == nil then
132
133
worldedit .player_notify (name , " invalid use: " .. param )
@@ -139,38 +140,47 @@ minetest.register_chatcommand("/expand", {
139
140
return
140
141
end
141
142
142
- local tmp = tonumber (arg2 )
143
- local axis , dir
144
- local reverse_amount = 0
143
+ local absolute = direction :find (" [xyz?]" )
144
+ local dir , axis
145
145
146
- axis ,dir = worldedit .player_axis (name )
146
+ if rev_amount == " " then
147
+ rev_amount = 0
148
+ end
147
149
148
- if arg2 ~= " " then
149
- if tmp == nil then
150
- axis , dir = worldedit .translate_direction (name , arg2 )
150
+ if absolute == nil then
151
+ axis , dir = worldedit .translate_direction (name , direction )
152
+
153
+ if axis == nil or dir == nil then
154
+ return false , " Invalid if looking straight up or down"
155
+ end
156
+ else
157
+ if direction == " ?" then
158
+ axis , dir = worldedit .player_axis (name )
151
159
else
152
- reverse_amount = tmp
160
+ axis = direction
161
+ dir = 1
153
162
end
154
163
end
155
164
156
- if arg3 ~= " " then
157
- axis , dir = worldedit . translate_direction ( name , arg3 )
165
+ if sign == " - " then
166
+ dir = - dir
158
167
end
159
168
160
169
worldedit .cuboid_linear_expand (name , axis , dir , amount )
161
- worldedit .cuboid_linear_expand (name , axis , - dir , reverse_amount )
170
+ worldedit .cuboid_linear_expand (name , axis , - dir , rev_amount )
162
171
worldedit .marker_update (name )
163
172
end ,
164
173
}
165
174
)
166
175
167
176
168
177
minetest .register_chatcommand (" /contract" , {
169
- params = " <amount> [reverse-amount] [ up|down|left|right|front|back]" ,
178
+ params = " [+|-]<x|y|z|?| up|down|left|right|front|back> <amount> [reverse-amount ]" ,
170
179
description = " contract the selection in one or two directions at once" ,
171
180
privs = {worldedit = true },
172
181
func = function (name , param )
173
- local find , _ , amount , arg2 , arg3 = param :find (" (%d+)%s*(%w*)%s*(%l*)" )
182
+ local find , _ , sign , direction , amount ,
183
+ rev_amount = param :find (" ([+-]?)([%?%l]+)%s*(%d+)%s*(%d*)" )
174
184
175
185
if find == nil then
176
186
worldedit .player_notify (name , " invalid use: " .. param )
@@ -183,26 +193,34 @@ minetest.register_chatcommand("/contract", {
183
193
return
184
194
end
185
195
186
- local tmp = tonumber (arg2 )
187
- local axis , dir
188
- local reverse_amount = 0
196
+ local absolute = direction :find (" [xyz?]" )
197
+ local dir , axis
189
198
190
- axis ,dir = worldedit .player_axis (name )
199
+ if rev_amount == " " then
200
+ rev_amount = 0
201
+ end
191
202
192
- if arg2 ~= " " then
193
- if tmp == nil then
194
- axis , dir = worldedit .translate_direction (name , arg2 )
203
+ if absolute == nil then
204
+ axis , dir = worldedit .translate_direction (name , direction )
205
+
206
+ if axis == nil or dir == nil then
207
+ return false , " Invalid if looking straight up or down"
208
+ end
209
+ else
210
+ if direction == " ?" then
211
+ axis , dir = worldedit .player_axis (name )
195
212
else
196
- reverse_amount = tmp
213
+ axis = direction
214
+ dir = 1
197
215
end
198
216
end
199
217
200
- if arg3 ~= " " then
201
- axis , dir = worldedit . translate_direction ( name , arg3 )
218
+ if sign == " - " then
219
+ dir = - dir
202
220
end
203
221
204
222
worldedit .cuboid_linear_expand (name , axis , dir , - amount )
205
- worldedit .cuboid_linear_expand (name , axis , - dir , - reverse_amount )
223
+ worldedit .cuboid_linear_expand (name , axis , - dir , - rev_amount )
206
224
worldedit .marker_update (name )
207
225
end ,
208
226
}
0 commit comments