From d7d96ae2636d39f1c4d3c6892441b8ea93d69fef Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Tue, 20 Jul 2021 12:52:19 -0700 Subject: [PATCH] //wbox added --- worldeditadditions/lib/wireframe/wire_box.lua | 55 +++++++++++++++++++ .../commands/wireframe/init.lua | 2 +- .../commands/wireframe/wbox.lua | 36 ++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 worldeditadditions/lib/wireframe/wire_box.lua diff --git a/worldeditadditions/lib/wireframe/wire_box.lua b/worldeditadditions/lib/wireframe/wire_box.lua new file mode 100644 index 0000000..6e52a2c --- /dev/null +++ b/worldeditadditions/lib/wireframe/wire_box.lua @@ -0,0 +1,55 @@ +-- ██ ██ ██ ██████ ███████ ██████ ██████ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ █ ██ ██ ██████ █████ ██████ ██ ██ ███ +-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███ ███ ██ ██ ██ ███████ ██████ ██████ ██ ██ + +--- Fills the edges of the selection box with nodes. +-- @param {Position} pos1 The 1st position defining the WorldEdit selection +-- @param {Position} pos2 The 2nd positioon defining the WorldEdit selection +-- @param {string} node Name of the node to place +local v3 = worldeditadditions.Vector3 +function worldeditadditions.wire_box(pos1,pos2,node) + local node_id_replace = minetest.get_content_id(node) + local ps1, ps2 = v3.sort(pos1,pos2) + + -- Fetch the nodes in the specified area + local manip, area = worldedit.manip_helpers.init(pos1, pos2) + local data = manip:get_data() + + -- Using three loops to reduce the number of nodes processed + local counts = { replaced = 0 } + + for z = ps1.z,ps2.z do + for k,y in pairs({pos1.y,pos2.y}) do + for k,x in pairs({pos1.x,pos2.x}) do + data[area:index(x, y, z)] = node_id_replace + counts.replaced = counts.replaced + 1 + end + end + end + if math.abs(ps2.y-ps1.y) > 1 then + for k,z in pairs({pos1.z,pos2.z}) do + for y = pos1.y+1,pos2.y-1 do + for k,x in pairs({pos1.x,pos2.x}) do + data[area:index(x, y, z)] = node_id_replace + counts.replaced = counts.replaced + 1 + end + end + end + end + if math.abs(ps2.x-ps1.x) > 1 then + for k,z in pairs({pos1.z,pos2.z}) do + for k,y in pairs({pos1.y,pos2.y}) do + for x = pos1.x+1,pos2.x-1 do + data[area:index(x, y, z)] = node_id_replace + counts.replaced = counts.replaced + 1 + end + end + end + end + -- Save the modified nodes back to disk & return + worldedit.manip_helpers.finish(manip, data) + + return true, counts.replaced +end diff --git a/worldeditadditions_commands/commands/wireframe/init.lua b/worldeditadditions_commands/commands/wireframe/init.lua index 400a4a3..185cfa3 100644 --- a/worldeditadditions_commands/commands/wireframe/init.lua +++ b/worldeditadditions_commands/commands/wireframe/init.lua @@ -8,6 +8,6 @@ local we_cm = worldeditadditions_commands.modpath .. "/commands/wireframe/" --- dofile(we_cm.."wbox.lua") +dofile(we_cm.."wbox.lua") -- dofile(we_cm.."wcompass.lua") dofile(we_cm.."wcorner.lua") diff --git a/worldeditadditions_commands/commands/wireframe/wbox.lua b/worldeditadditions_commands/commands/wireframe/wbox.lua index e69de29..56a01ce 100644 --- a/worldeditadditions_commands/commands/wireframe/wbox.lua +++ b/worldeditadditions_commands/commands/wireframe/wbox.lua @@ -0,0 +1,36 @@ +-- ██ ██ ██████ ██████ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ █ ██ ██████ ██ ██ ███ +-- ██ ███ ██ ██ ██ ██ ██ ██ ██ +-- ███ ███ ██████ ██████ ██ ██ +local wea = worldeditadditions +local v3 = worldeditadditions.Vector3 +worldedit.register_command("wbox", { + params = "", + description = "Set the corners of the current selection to ", + privs = {worldedit=true}, + require_pos = 2, + parse = function(param) + local node = worldedit.normalize_nodename(param) + if not node then + return false, "invalid node name: " .. param + 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, +})