forked from mtcontrib/Minetest-WorldEdit
Reimplement /shift to make use of new marker functions
This commit is contained in:
parent
0b97a7c740
commit
6cf8b92434
@ -159,16 +159,15 @@ end
|
|||||||
minetest.register_chatcommand(
|
minetest.register_chatcommand(
|
||||||
"/shift",
|
"/shift",
|
||||||
{
|
{
|
||||||
params = "[+|-]<amount> [x|y|z]",
|
params = "<amount> [up|down|left|right|front|back]",
|
||||||
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, _, sign, amount, axis = param:find("^([+-]?)(%d+)[%s+]?([xyz]?)$")
|
local find, _, amount, direction = param:find("(%d+)%s*(%l*)")
|
||||||
|
|
||||||
if find == nil then
|
if find == nil then
|
||||||
minetest.debug("entering if")
|
|
||||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -178,36 +177,21 @@ minetest.register_chatcommand(
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
amount = tonumber(amount)
|
local axis, dirsign
|
||||||
|
|
||||||
local direction = ""
|
if direction ~= "" then
|
||||||
|
axis, dirsign = worldedit.translate_direction(name, direction)
|
||||||
if sign ~= nil and sign == '-' then
|
|
||||||
amount = amount * -1
|
|
||||||
end
|
|
||||||
|
|
||||||
if axis == "" then
|
|
||||||
direction, _ = worldedit.player_axis(name)
|
|
||||||
amount = amount * _
|
|
||||||
else
|
else
|
||||||
direction = axis
|
axis, dirsign = worldedit.player_axis(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if direction == 'x' then
|
if axis == nil or dirsign == nil then
|
||||||
worldedit.pos1[name].x = pos1.x + amount
|
return false, "Invalid usage: " .. param
|
||||||
worldedit.pos2[name].x = pos2.x + amount
|
|
||||||
elseif direction == 'y' then
|
|
||||||
worldedit.pos1[name].y = pos1.y + amount
|
|
||||||
worldedit.pos2[name].y = pos2.y + amount
|
|
||||||
elseif direction == 'z' then
|
|
||||||
worldedit.pos1[name].z = pos1.z + amount
|
|
||||||
worldedit.pos2[name].z = pos2.z + amount
|
|
||||||
else
|
|
||||||
worldedit.player_notify(name, "unexpected error. direction = " .. direction)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
worldedit.mark_pos1(name)
|
worldedit.move_marker(name, 1, axis, amount * dirsign)
|
||||||
worldedit.mark_pos2(name)
|
worldedit.move_marker(name, 2, axis, amount * dirsign)
|
||||||
|
worldedit.update_markers(name)
|
||||||
|
|
||||||
worldedit.player_notify(name, "Area shifted by " .. amount .. " in " .. direction .. " axis")
|
worldedit.player_notify(name, "Area shifted by " .. amount .. " in " .. direction .. " axis")
|
||||||
end,
|
end,
|
||||||
@ -239,7 +223,7 @@ minetest.register_chatcommand(
|
|||||||
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
||||||
|
|
||||||
if arg3 ~= "" then
|
if arg3 ~= "" then
|
||||||
axis, direction = worldedit.translate_directions(name, arg3)
|
axis, direction = worldedit.translate_direction(name, arg3)
|
||||||
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -247,7 +231,7 @@ minetest.register_chatcommand(
|
|||||||
local tmp = tonumber(arg2)
|
local tmp = tonumber(arg2)
|
||||||
|
|
||||||
if tmp == nil then
|
if tmp == nil then
|
||||||
axis, direction = worldedit.translate_directions(name, arg2)
|
axis, direction = worldedit.translate_direction(name, arg2)
|
||||||
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
||||||
else
|
else
|
||||||
local tmpmark
|
local tmpmark
|
||||||
@ -301,7 +285,7 @@ minetest.register_chatcommand(
|
|||||||
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
||||||
|
|
||||||
if arg3 ~= "" then
|
if arg3 ~= "" then
|
||||||
axis, direction = worldedit.translate_directions(name, arg3)
|
axis, direction = worldedit.translate_direction(name, arg3)
|
||||||
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -309,7 +293,7 @@ minetest.register_chatcommand(
|
|||||||
local tmp = tonumber(arg2)
|
local tmp = tonumber(arg2)
|
||||||
|
|
||||||
if tmp == nil then
|
if tmp == nil then
|
||||||
axis, direction = worldedit.translate_directions(name, arg2)
|
axis, direction = worldedit.translate_direction(name, arg2)
|
||||||
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
mark = worldedit.get_marker_in_axis(name, axis, direction)
|
||||||
else
|
else
|
||||||
local tmpmark
|
local tmpmark
|
||||||
@ -438,7 +422,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- Translates up, down, left, right, front, back to their corresponding axes and directions according to faced direction
|
-- Translates up, down, left, right, front, back to their corresponding axes and directions according to faced direction
|
||||||
worldedit.translate_directions = 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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user