mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-23 23:53:44 +01:00
added wcompass
This commit is contained in:
parent
72513b350a
commit
8718e59206
@ -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")
|
||||
|
35
worldeditadditions/lib/wireframe/make_compass.lua
Normal file
35
worldeditadditions/lib/wireframe/make_compass.lua
Normal file
@ -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
|
@ -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")
|
||||
|
@ -0,0 +1,36 @@
|
||||
-- ██ ██ ██████ ██████ ███ ███ ██████ █████ ███████ ███████
|
||||
-- ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██
|
||||
-- ██ █ ██ ██ ██ ██ ██ ████ ██ ██████ ███████ ███████ ███████
|
||||
-- ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ███ ███ ██████ ██████ ██ ██ ██ ██ ██ ███████ ███████
|
||||
local wea = worldeditadditions
|
||||
worldedit.register_command("wcompass", {
|
||||
params = "<replace_node> [<bead_node>]",
|
||||
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 <replace_node>: " .. parts[1]
|
||||
elseif parts[2] and not node2 then
|
||||
return false, "Invalid <bead_node>: " .. 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,
|
||||
})
|
Loading…
Reference in New Issue
Block a user