Skip to content

Commit f8f1f3b

Browse files
committedJul 4, 2016
Reimplement /expand and /contract to conform to WE standards
1 parent d5e004b commit f8f1f3b

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed
 

Diff for: ‎worldedit_commands/cuboid.lua

+44-26
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ minetest.register_chatcommand("/shift", {
122122

123123

124124
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]",
126126
description = "expand the selection in one or two directions at once",
127127
privs = {worldedit=true},
128128
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*)")
130131

131132
if find == nil then
132133
worldedit.player_notify(name, "invalid use: " .. param)
@@ -139,38 +140,47 @@ minetest.register_chatcommand("/expand", {
139140
return
140141
end
141142

142-
local tmp = tonumber(arg2)
143-
local axis, dir
144-
local reverse_amount = 0
143+
local absolute = direction:find("[xyz?]")
144+
local dir, axis
145145

146-
axis,dir = worldedit.player_axis(name)
146+
if rev_amount == "" then
147+
rev_amount = 0
148+
end
147149

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)
151159
else
152-
reverse_amount = tmp
160+
axis = direction
161+
dir = 1
153162
end
154163
end
155164

156-
if arg3 ~= "" then
157-
axis, dir = worldedit.translate_direction(name, arg3)
165+
if sign == "-" then
166+
dir = -dir
158167
end
159168

160169
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)
162171
worldedit.marker_update(name)
163172
end,
164173
}
165174
)
166175

167176

168177
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]",
170179
description = "contract the selection in one or two directions at once",
171180
privs = {worldedit=true},
172181
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*)")
174184

175185
if find == nil then
176186
worldedit.player_notify(name, "invalid use: " .. param)
@@ -183,26 +193,34 @@ minetest.register_chatcommand("/contract", {
183193
return
184194
end
185195

186-
local tmp = tonumber(arg2)
187-
local axis, dir
188-
local reverse_amount = 0
196+
local absolute = direction:find("[xyz?]")
197+
local dir, axis
189198

190-
axis,dir = worldedit.player_axis(name)
199+
if rev_amount == "" then
200+
rev_amount = 0
201+
end
191202

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)
195212
else
196-
reverse_amount = tmp
213+
axis = direction
214+
dir = 1
197215
end
198216
end
199217

200-
if arg3 ~= "" then
201-
axis, dir = worldedit.translate_direction(name, arg3)
218+
if sign == "-" then
219+
dir = -dir
202220
end
203221

204222
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)
206224
worldedit.marker_update(name)
207225
end,
208226
}

0 commit comments

Comments
 (0)
Please sign in to comment.