Minetest-WorldEditAdditions/worldeditadditions_commands/commands/wireframe/wcorner.lua

46 lines
1.8 KiB
Lua
Raw Normal View History

2022-09-19 17:59:45 +00:00
local wea_c = worldeditadditions_core
2022-09-18 20:39:48 +00:00
local wea = worldeditadditions
local Vector3 = wea_c.Vector3
2021-07-19 00:27:37 +00:00
-- ██ ██ ██████ ██████ ██████ ███ ██ ███████ ██████
-- ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██
-- ██ █ ██ ██ ██ ██ ██████ ██ ██ ██ █████ ██████
-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███ ███ ██████ ██████ ██ ██ ██ ████ ███████ ██ ██
2022-09-18 20:39:48 +00:00
worldeditadditions_core.register_command("wcorner", {
2021-07-23 21:12:20 +00:00
params = "<replace_node>",
description = "Set the corners of the current selection to <replace_node>",
2021-07-19 00:27:37 +00:00
privs = {worldedit=true},
require_pos = 2,
2021-07-22 20:29:29 +00:00
parse = function(params_text)
local node = worldedit.normalize_nodename(params_text)
2021-07-19 00:27:37 +00:00
if not node then
2021-07-22 20:29:29 +00:00
return false, "invalid node name: " .. params_text
2021-07-19 00:27:37 +00:00
end
return true, node
end,
nodes_needed = function(name)
local p1, p2, total = worldedit.pos1[name], worldedit.pos2[name], 1
for k,v in pairs({"x","y","z"}) do
if p1[v] ~= p2[v] then total = total*2 end
end
return total
end,
func = function(name, node)
2022-09-18 20:39:48 +00:00
local start_time = wea_c.get_ms_time()
local pos1, pos2 = Vector3.sort(worldedit.pos1[name], worldedit.pos2[name])
local success, count = wea.corner_set(pos1, pos2, node)
if not success then return success, count end
local time_taken = wea_c.format.human_time(wea_c.get_ms_time() - start_time)
minetest.log("action", name.." used //wcorner at "..pos1.." - "..pos2..", taking "..time_taken)
return true, count .. " nodes set in "..time_taken
2021-07-19 00:27:37 +00:00
end,
})