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

53 lines
1.9 KiB
Lua
Raw Permalink Normal View History

2022-09-18 20:39:48 +00:00
local wea = worldeditadditions
2022-09-19 17:59:45 +00:00
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
2022-09-18 20:39:48 +00:00
2021-07-20 19:52:19 +00:00
-- ██ ██ ██████ ██████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ██ █ ██ ██████ ██ ██ ███
-- ██ ███ ██ ██ ██ ██ ██ ██ ██
-- ███ ███ ██████ ██████ ██ ██
2022-09-18 20:39:48 +00:00
worldeditadditions_core.register_command("wbox", {
2021-07-23 21:12:20 +00:00
params = "<replace_node>",
description = "Sets the edges of the current selection to <replace_node>",
2021-07-20 19:52:19 +00:00
privs = {worldedit=true},
require_pos = 2,
2021-07-22 20:29:29 +00:00
parse = function(params_text)
2021-07-23 21:12:20 +00:00
if params_text == "" then
return false, "Error: too few arguments! Expected: \"<replace_node>\""
end
2021-07-22 20:29:29 +00:00
local node = worldedit.normalize_nodename(params_text)
2021-07-20 19:52:19 +00:00
if not node then
2021-07-22 20:29:29 +00:00
return false, "invalid node name: " .. params_text
2021-07-20 19:52:19 +00:00
end
return true, node
end,
nodes_needed = function(name)
2022-09-18 20:39:48 +00:00
local delta = Vector3.subtract(worldedit.pos2[name], worldedit.pos1[name]):abs():add(1)
2021-07-20 19:52:19 +00:00
local total, mult, axes = 1, 4, {"x","y","z"}
for k,v in pairs(axes) do
if worldedit.pos1[name] ~= worldedit.pos2[name] then total = total*2
else mult = mult/2 end
end
for k,v in pairs(axes) do
if delta[v] > 2 then total = total + (delta[v] - 2)*mult 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.wire_box(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 //wbox at "..pos1.." - "..pos2..", taking "..time_taken)
return true, count .. " nodes set in "..time_taken
2021-07-20 19:52:19 +00:00
end,
})