Optimize leaf decay based on EnvRef:find_node_near

This commit is contained in:
Perttu Ahola 2012-04-06 22:57:44 +03:00
parent 95f4ccab51
commit 4abfcda81f

@ -61,28 +61,16 @@ minetest.register_abm({
end end
default.leafdecay_trunk_find_allow_accumulator = default.leafdecay_trunk_find_allow_accumulator =
default.leafdecay_trunk_find_allow_accumulator - 1 default.leafdecay_trunk_find_allow_accumulator - 1
for dx = -d, d do if do_preserve then break end -- Assume ignore is a trunk, to make the thing work at the border of the active area
for dy = -d, d do if do_preserve then break end local p1 = minetest.env:find_node_near(p0, d, {"ignore", "group:tree"})
for dz = -d, d do if do_preserve then break end if p1 then
local p = { do_preserve = true
x = p0.x + dx, if default.leafdecay_enable_cache then
y = p0.y + dy, --print("caching trunk")
z = p0.z + dz, -- Cache the trunk
} default.leafdecay_trunk_cache[p0_hash] = p1
local n = minetest.env:get_node(p)
local reg = minetest.registered_nodes[n.name]
-- Assume ignore is a trunk, to make the thing work at the border of the active area
if n.name == "ignore" or (reg.groups.tree and reg.groups.tree ~= 0) then
do_preserve = true
if default.leafdecay_enable_cache then
--print("caching trunk")
-- Cache the trunk
default.leafdecay_trunk_cache[p0_hash] = p
end
end end
end end
end
end
if not do_preserve then if not do_preserve then
-- Drop stuff other than the node itself -- Drop stuff other than the node itself
itemstacks = minetest.get_node_drops(n0.name) itemstacks = minetest.get_node_drops(n0.name)