Minetest-WorldEditAdditions/worldeditadditions_commands/commands/selectors/sshift.lua
2023-07-20 10:47:56 -07:00

36 lines
1.4 KiB
Lua

local wea = worldeditadditions
local wea_c = worldeditadditions_core
local Vector3 = worldeditadditions.Vector3
-- ███████ ███████ ██ ██ ██ ███████ ████████
-- ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ███████ ██ █████ ██
-- ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ██ ██ ██ ██ ██
worldeditadditions_core.register_command("sshift", {
params = "<axis1> <distance1> [<axis2> <distance2> [<axis3> <distance3>]]",
description = "Shift the WorldEdit region in 3 dimensions.",
privs = { worldedit = true },
require_pos = 2,
parse = function(params_text)
return true, wea_c.split(params_text, "%s")
end,
func = function(name, params_text)
local facing = wea_c.player_dir(name)
local vec, err = wea_c.parse.axes_multi(params_text, facing, "sum")
if err then return false, err end -- Error check before proceeding.
local positions = wea_c.pos.get_all(name)
wea_c.pos.set(name, 1, positions[1] + vec)
wea_c.pos.set(name, 2, positions[2] + vec)
return true, "Region shifted by " .. (vec.x + vec.y + vec.z) .. " nodes."
end,
})
-- Register "shift" alias
wea_c.register_alias("shift", "sshift", true)
-- Tests
-- //sshift front 5 left 3 y 2