diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index 10f6d71..a01356e 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -67,4 +67,5 @@ dofile(wea.modpath.."/lib/selection/stack.lua") dofile(wea.modpath.."/lib/selection/cloud.lua") dofile(wea.modpath.."/lib/wireframe/corner_set.lua") +dofile(wea.modpath.."/lib/wireframe/make_compass.lua") dofile(wea.modpath.."/lib/wireframe/wire_box.lua") diff --git a/worldeditadditions/lib/wireframe/make_compass.lua b/worldeditadditions/lib/wireframe/make_compass.lua new file mode 100644 index 0000000..372de86 --- /dev/null +++ b/worldeditadditions/lib/wireframe/make_compass.lua @@ -0,0 +1,35 @@ +-- ███ ███ █████ ██ ██ ███████ ██████ ██████ ███ ███ ██████ █████ ███████ ███████ +-- ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ +-- ██ ████ ██ ███████ █████ █████ ██ ██ ██ ██ ████ ██ ██████ ███████ ███████ ███████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ ██ ███████ ██████ ██████ ██ ██ ██ ██ ██ ███████ ███████ + +--- Makes a compass with a bead pointing north (+Z). +-- @param {Position} pos1 The 1st position defining the WorldEdit selection +-- @param {string} node1 Name of the node to place +-- @param {string} node2 Name of the node of the bead +function worldeditadditions.make_compass(pos1,node1,node2) + local debug, ret = "", {} + minetest.set_node(vector.add(pos1,vector.new(0,1,3)), {name=node2}) + local counts = { replaced = 1 } + -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) + for z = -3,3 do + if z ~= 0 then + for k,x in pairs({math.floor(-3/math.abs(z)),0,math.ceil(3/math.abs(z))}) do + minetest.set_node(vector.new(pos1.x+x,pos1.y,pos1.z+z), {name=node1}) + counts.replaced = counts.replaced + 1 + table.insert(ret,x) + end + else + for x = -3,3 do + minetest.set_node(vector.new(pos1.x+x,pos1.y,pos1.z), {name=node1}) + counts.replaced = counts.replaced + 1 + table.insert(ret,pos1.x+x) + end + end + debug = debug..z.." -- "..table.concat(ret,", ").."\n" + ret={} + end + + return true, debug..counts.replaced +end diff --git a/worldeditadditions_commands/commands/wireframe/init.lua b/worldeditadditions_commands/commands/wireframe/init.lua index 185cfa3..337a710 100644 --- a/worldeditadditions_commands/commands/wireframe/init.lua +++ b/worldeditadditions_commands/commands/wireframe/init.lua @@ -9,5 +9,5 @@ local we_cm = worldeditadditions_commands.modpath .. "/commands/wireframe/" dofile(we_cm.."wbox.lua") --- dofile(we_cm.."wcompass.lua") +dofile(we_cm.."wcompass.lua") dofile(we_cm.."wcorner.lua") diff --git a/worldeditadditions_commands/commands/wireframe/wcompass.lua b/worldeditadditions_commands/commands/wireframe/wcompass.lua index e69de29..5a62b1e 100644 --- a/worldeditadditions_commands/commands/wireframe/wcompass.lua +++ b/worldeditadditions_commands/commands/wireframe/wcompass.lua @@ -0,0 +1,36 @@ +-- ██ ██ ██████ ██████ ███ ███ ██████ █████ ███████ ███████ +-- ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ +-- ██ █ ██ ██ ██ ██ ██ ████ ██ ██████ ███████ ███████ ███████ +-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███ ███ ██████ ██████ ██ ██ ██ ██ ██ ███████ ███████ +local wea = worldeditadditions +worldedit.register_command("wcompass", { + params = " []", + description = "Creates a compass around pos1 with a single node bead pointing north (+Z).", + privs = {worldedit=true}, + require_pos = 1, + parse = function(params_text) + local parts = wea.split(params_text," ",true) + local node1 = worldedit.normalize_nodename(parts[1]) + local node2 = worldedit.normalize_nodename(parts[2]) + if not node1 then + return false, "Invalid : " .. parts[1] + elseif parts[2] and not node2 then + return false, "Invalid : " .. parts[2] + elseif not parts[2] then + node2 = node1 + end + return true, node1, node2 + 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, node1, node2) + local _, count = wea.make_compass(worldedit.pos1[name], node1, node2) + return _, count .. " nodes set" + end, +})