Minetest-WorldEditAdditions/worldeditadditions/lib/wireframe/make_compass.lua

39 lines
2.1 KiB
Lua
Raw Normal View History

2022-09-19 00:16:22 +00:00
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
---
-- @module worldeditadditions
2021-07-23 19:09:40 +00:00
-- ███ ███ █████ ██ ██ ███████ ██████ ██████ ███ ███ ██████ █████ ███████ ███████
-- ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██
-- ██ ████ ██ ███████ █████ █████ ██ ██ ██ ██ ████ ██ ██████ ███████ ███████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ███████ ██████ ██████ ██ ██ ██ ██ ██ ███████ ███████
--- Makes a compass with a bead pointing north (+Z).
-- @param pos1 Vector3 The 1st position defining the WorldEdit selection
-- @param node1 string Name of the node to place
-- @param node2 string Name of the node of the bead
2021-07-23 19:09:40 +00:00
function worldeditadditions.make_compass(pos1,node1,node2)
2022-09-19 00:16:22 +00:00
pos1 = Vector3.clone(pos1)
minetest.set_node(pos1 + Vector3.new(0,1,3), { name = node2 })
2021-07-23 19:09:40 +00:00
local counts = { replaced = 1 }
2021-07-23 23:21:58 +00:00
2021-07-23 19:09:40 +00:00
-- 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
2022-09-19 00:16:22 +00:00
minetest.set_node(Vector3.new(pos1.x+x,pos1.y,pos1.z+z), {name=node1})
2021-07-23 19:09:40 +00:00
counts.replaced = counts.replaced + 1
end
else
for x = -3,3 do
2022-09-19 00:16:22 +00:00
minetest.set_node(Vector3.new(pos1.x+x,pos1.y,pos1.z), {name=node1})
2021-07-23 19:09:40 +00:00
counts.replaced = counts.replaced + 1
end
end
end
2021-07-23 23:21:58 +00:00
return true, counts.replaced
2021-07-23 19:09:40 +00:00
end