Fix /shift command to conform to worldedit command standard

This commit is contained in:
Daniel Sosa 2015-02-16 02:28:50 +00:00
parent eaffe7e347
commit 6186a37dc5
2 changed files with 9 additions and 5 deletions

View File

@ -82,19 +82,23 @@ minetest.register_chatcommand("/inset", {
minetest.register_chatcommand("/shift", { minetest.register_chatcommand("/shift", {
params = "<amount> [up|down|left|right|front|back]", -- params = "<amount> [up|down|left|right|front|back]",
params = "[x|y|z|?|up|down|left|right|front|back] [+|-]<amount>",
description = "Moves the selection region. Does not move contents.", description = "Moves the selection region. Does not move contents.",
privs = {worldedit=true}, privs = {worldedit=true},
func = function(name, param) func = function(name, param)
local pos1 = worldedit.pos1[name] local pos1 = worldedit.pos1[name]
local pos2 = worldedit.pos2[name] local pos2 = worldedit.pos2[name]
local find, _, amount, direction = param:find("(%d+)%s*(%l*)") -- local find, _, amount, direction = param:find("(%d+)%s*(%l*)")
local find, _, direction, amount = param:find("([%?%l]+)%s*([+-]?%d+)")
if find == nil then if find == nil then
worldedit.player_notify(name, "invalid usage: " .. param) worldedit.player_notify(name, "invalid usage: " .. param)
return return
end end
worldedit.player_notify(name, "direction = " .. direction .. " amount = " .. amount)
if pos1 == nil or pos2 == nil then if pos1 == nil or pos2 == nil then
worldedit.player_notify(name, worldedit.player_notify(name,
"Undefined region. Region must be defined beforehand.") "Undefined region. Region must be defined beforehand.")
@ -102,14 +106,14 @@ minetest.register_chatcommand("/shift", {
end end
local axis, dir local axis, dir
if direction ~= "" then if direction ~= "?" then
axis, dir = worldedit.translate_direction(name, direction) axis, dir = worldedit.translate_direction(name, direction)
else else
axis, dir = worldedit.player_axis(name) axis, dir = worldedit.player_axis(name)
end end
if axis == nil or dir == nil then if axis == nil or dir == nil then
return false, "Invalid if looking up or down" return false, "Invalid"
end end
assert(worldedit.cuboid_shift(name, axis, amount * dir)) assert(worldedit.cuboid_shift(name, axis, amount * dir))

View File

@ -205,7 +205,7 @@ end
worldedit.translate_direction = function(name, direction) worldedit.translate_direction = function(name, direction)
local axis, dir = worldedit.player_axis(name) local axis, dir = worldedit.player_axis(name)
local resaxis, resdir local resaxis, resdir
if direction == "up" then if direction == "up" then
return 'y', 1 return 'y', 1
end end