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

40 lines
1.5 KiB
Lua
Raw Normal View History

2021-07-20 21:52:19 +02:00
-- ██ ██ ██████ ██████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ██ █ ██ ██████ ██ ██ ███
-- ██ ███ ██ ██ ██ ██ ██ ██ ██
-- ███ ███ ██████ ██████ ██ ██
local wea = worldeditadditions
local v3 = worldeditadditions.Vector3
worldeditadditions_core.register_command("wbox", {
2021-07-23 23:12:20 +02:00
params = "<replace_node>",
description = "Sets the edges of the current selection to <replace_node>",
2021-07-20 21:52:19 +02:00
privs = {worldedit=true},
require_pos = 2,
2021-07-22 22:29:29 +02:00
parse = function(params_text)
2021-07-23 23:12:20 +02:00
if params_text == "" then
return false, "Error: too few arguments! Expected: \"<replace_node>\""
end
2021-07-22 22:29:29 +02:00
local node = worldedit.normalize_nodename(params_text)
2021-07-20 21:52:19 +02:00
if not node then
2021-07-22 22:29:29 +02:00
return false, "invalid node name: " .. params_text
2021-07-20 21:52:19 +02:00
end
return true, node
end,
nodes_needed = function(name)
local delta = v3.subtract(worldedit.pos2[name], worldedit.pos1[name]):abs():add(1)
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)
local _, count = wea.wire_box(worldedit.pos1[name], worldedit.pos2[name], node)
return _, count .. " nodes set"
end,
})