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

36 lines
1.4 KiB
Lua
Raw Normal View History

2022-09-18 21:20:04 +00:00
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
2021-03-16 03:51:23 +00:00
-- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████
-- ██ ██ ██ ████ ██ ██ ██ ██ ██
-- ███████ ██ █████ ██ ██ ██ ██ █████ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██
worldeditadditions_core.register_command("scentre", {
2021-03-16 03:51:23 +00:00
params = "",
description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.",
privs = {worldedit=true},
require_pos = 2,
parse = function(params_text)
return true
end,
func = function(name)
local mean = Vector3.mean(
Vector3.clone(worldedit.pos1[name]),
Vector3.clone(worldedit.pos2[name])
)
local pos1, pos2 = Vector3.clone(mean), Vector3.clone(mean)
2022-09-18 21:20:04 +00:00
pos1 = pos1:floor()
pos2 = pos2:ceil()
worldedit.pos1[name], worldedit.pos2[name] = pos1, pos2
2021-03-16 03:51:23 +00:00
worldedit.mark_pos1(name)
worldedit.mark_pos2(name)
2022-09-18 21:20:04 +00:00
return true, "position 1 set to "..pos1..", position 2 set to "..pos2
2021-03-16 03:51:23 +00:00
end,
})
-- lua print(vecs.mean.x..", "..vecs.mean.y..", "..vecs.mean.z)