2021-02-24 16:40:53 +00:00
|
|
|
-- ███████ ██████ ███████ ██████ ████████
|
|
|
|
-- ██ ██ ██ ██ ██ ██
|
|
|
|
-- ███████ ██████ █████ ██ ██
|
|
|
|
-- ██ ██ ██ ██ ██ ██
|
|
|
|
-- ███████ ██ ██ ███████ ██████ ██
|
|
|
|
worldedit.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-01 21:08:32 +00:00
|
|
|
local wea = worldeditadditions
|
|
|
|
local find = wea.split(params_text, "%s", false)
|
|
|
|
local ax1, ax2, len = find[1], find[2], find[table.maxn(find)]
|
|
|
|
|
|
|
|
-- If ax1 is bad set to player facing dir
|
2021-03-01 21:16:23 +00:00
|
|
|
if ax1 == len or not ax1:match('[xyz]') then ax1 = "get"
|
2021-03-01 21:08:32 +00:00
|
|
|
else
|
|
|
|
local success, value = wea.getsign(ax1, "int")
|
|
|
|
if not success then return success, value
|
2021-03-01 21:16:23 +00:00
|
|
|
else ax1 = { value, ax1:gsub('[^xyz]', ''):sub(1, 1) } end
|
2021-03-01 21:08:32 +00:00
|
|
|
end
|
|
|
|
-- If ax2 is bad set to +y
|
|
|
|
if not ax2 or ax2 == len or not ax2:match('[xyz]') then ax2 = "y" end
|
|
|
|
local success, value = wea.getsign(ax2, "int")
|
|
|
|
if not success then return success, value end
|
2021-03-01 21:16:23 +00:00
|
|
|
ax2 = { value, ax2:gsub('[^xyz]', ''):sub(1, 1) }
|
2021-03-01 21:08:32 +00:00
|
|
|
|
|
|
|
len = tonumber(len)
|
|
|
|
-- If len == nill cancel the operation
|
|
|
|
if len == nil then
|
|
|
|
return false, "No length specified."
|
|
|
|
end
|
|
|
|
|
|
|
|
return true, ax1, ax2, len
|
2021-02-24 16:40:53 +00:00
|
|
|
end,
|
|
|
|
func = function(name, axis1, axis2, len)
|
2021-02-25 03:35:20 +00:00
|
|
|
if axis1 == "get" then axis1 = worldeditadditions.player_axis2d(name) end
|
|
|
|
|
2021-02-28 17:59:09 +00:00
|
|
|
local p2 = vector.new(worldedit.pos1[name])
|
2021-02-25 03:35:20 +00:00
|
|
|
|
|
|
|
p2[axis1[2]] = p2[axis1[2]] + tonumber(len) * axis1[1]
|
|
|
|
p2[axis2[2]] = p2[axis2[2]] + tonumber(len) * axis2[1]
|
|
|
|
|
2021-02-24 16:40:53 +00:00
|
|
|
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)
|
2021-02-24 16:40:53 +00:00
|
|
|
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
|