master
HybridDog 2015-12-18 19:02:29 +01:00
parent 126a463b9f
commit 27644c260b
1 changed files with 31 additions and 22 deletions

View File

@ -649,34 +649,43 @@ minetest.register_node("extrablocks:house_redesignor", {
end end
}) })
-- depends on vector_extras
local set = vector.set_data_to_pos
local get = vector.get_data_from_pos
local remove = vector.remove_data_from_pos
local function get_tab2d(pos, func, max) local function get_tab2d(pos, func, max)
local count local z,y,x = vector.unpack(pos)
local tab = {pos} local tab = {{z,x}}
local tab_avoid = {[pos.x.." "..pos.y.." "..pos.z] = true} local tab_avoid = {}
set(tab_avoid, z,x,0, true)
local tab_done,num = {pos},2 local tab_done,num = {pos},2
while tab[1] do local n = 1
for n,p in pairs(tab) do while n do
for i = -1,1,2 do local z,x = unpack(tab[n])
for _,p2 in pairs({ for i = -1,1,2 do
{x=p.x+i, y=p.y, z=p.z}, for _,p2 in pairs({
{x=p.x, y=p.y, z=p.z+i}, {z+i,x},
}) do {z,x+i},
local pstr = p2.x.." "..p2.y.." "..p2.z }) do
if not tab_avoid[pstr] local z,x = unpack(p2)
and func(p2) then if not get(tab_avoid, z,x,0)
tab_avoid[pstr] = true and func({x=x, y=y, z=z}) then
tab_done[num] = p2 set(tab_avoid, z,x,0, true)
num = num+1 tab_done[num] = p2
table.insert(tab, p2) num = num+1
if max if max
and num > max then and num > max then
return false return false
end
end end
table.insert(tab, {z,x})
end end
end end
tab[n] = nil
end end
tab[n] = nil
n = next(tab)
end end
return tab_done return tab_done
end end