Minetest-WorldEditAdditions/worldeditadditions_commands/commands/selectors/srect.lua

57 lines
2.5 KiB
Lua
Raw Normal View History

-- ███████ ██████ ███████ ██████ ████████
-- ██ ██ ██ ██ ██ ██
-- ███████ ██████ █████ ██ ██
-- ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ███████ ██████ ██
2021-03-11 04:56:38 +00:00
local wea = worldeditadditions
worldeditadditions_core.register_command("srect", {
params = "[<axis1> [<axis2>]] <length>",
description = "Set WorldEdit region position 2 at a set distance along 2 axes.",
2021-03-01 21:16:23 +00:00
privs = { worldedit = true },
2021-02-25 03:35:20 +00:00
require_pos = 1,
parse = function(params_text)
2021-03-11 04:56:38 +00:00
local vec, tmp = vector.new(0, 0, 0), {}
2021-03-01 21:08:32 +00:00
local find = wea.split(params_text, "%s", false)
2021-03-10 21:21:33 +00:00
local ax1, ax2 = (tostring(find[1]):match('[xyz]') or "g"):sub(1,1), (tostring(find[2]):match('[xyz]') or "g"):sub(1,1)
2021-03-09 19:05:03 +00:00
local sn1, sn2, len = wea.getsign(find[1]), wea.getsign(find[2]), find[table.maxn(find)]
2021-03-01 21:08:32 +00:00
2021-03-09 19:05:03 +00:00
tmp.len = tonumber(len)
2021-03-01 21:08:32 +00:00
-- If len == nill cancel the operation
2021-03-10 21:21:33 +00:00
if not tmp.len then return false, "No length specified." end
-- If axis is bad send "get" order
2021-03-09 19:05:03 +00:00
if ax1 == "g" then tmp.get = true
else vec[ax1] = sn1 * tmp.len end
2021-03-10 21:21:33 +00:00
if ax2 == "g" then tmp.get = true
else vec[ax2] = sn2 * tmp.len end
2021-03-01 21:08:32 +00:00
2021-03-10 21:21:33 +00:00
tmp.axes = ax1..","..ax2
2021-03-09 19:05:03 +00:00
return true, vec, tmp
2021-03-11 20:59:04 +00:00
-- tmp carries:
-- The length (len) arguement to the main function for use if "get" is invoked there
-- The bool value "get" to tell the main function if it needs to populate missing information in vec
-- The string "axes" to tell the main function what axes are and/or need to be populated if "get" is invoked
end,
2021-03-09 19:05:03 +00:00
func = function(name, vec, tmp)
if tmp.get then
2021-03-11 04:56:38 +00:00
local ax, dir = wea.player_axis2d(name)
2021-03-10 21:21:33 +00:00
if not tmp.axes:find("[xz]") then vec[ax] = tmp.len * dir end
if not tmp.axes:find("y") then vec.y = tmp.len end
2021-03-09 19:05:03 +00:00
end
2021-02-25 03:35:20 +00:00
2021-03-09 19:19:47 +00:00
local p2 = vector.add(vec,worldedit.pos1[name])
worldedit.pos2[name] = p2
worldedit.mark_pos2(name)
2021-02-26 04:22:39 +00:00
return true, "position 2 set to " .. minetest.pos_to_string(p2)
end,
})
-- Tests
2021-02-26 04:22:39 +00:00
-- /multi //fp set1 -63 19 -20 //srect 5
2021-02-28 19:59:46 +00:00
-- /multi //fp set1 -63 19 -20 //srect z 5
-- /multi //fp set1 -63 19 -20 //srect a z 5
-- /multi //fp set1 -63 19 -20 //srect z a 5
-- /multi //fp set1 -63 19 -20 //srect -z 5
-- /multi //fp set1 -63 19 -20 //srect a -x 5
-- /multi //fp set1 -63 19 -20 //srect -x -a 5
2021-03-09 19:05:03 +00:00
-- lua vec = vector.new(15,-12,17); vec["len"] = 5; vec.get = true; vec2 = vector.add(vector.new(1,1,1),vec) print(vec2.x,vec2.y,vec2.z,vec2.len)