From: Perttu Ahola Date: Fri, 6 Apr 2012 19:57:44 +0000 (+0300) Subject: Optimize leaf decay based on EnvRef:find_node_near X-Git-Tag: 0.4.dev-20120408~10 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4abfcda81fab470b9011c7fd3e09b4e19671d2fa;p=oweals%2Fminetest_game.git Optimize leaf decay based on EnvRef:find_node_near --- diff --git a/mods/default/leafdecay.lua b/mods/default/leafdecay.lua index 36b6df87..8f4ff974 100644 --- a/mods/default/leafdecay.lua +++ b/mods/default/leafdecay.lua @@ -61,28 +61,16 @@ minetest.register_abm({ end default.leafdecay_trunk_find_allow_accumulator = default.leafdecay_trunk_find_allow_accumulator - 1 - for dx = -d, d do if do_preserve then break end - for dy = -d, d do if do_preserve then break end - for dz = -d, d do if do_preserve then break end - local p = { - x = p0.x + dx, - y = p0.y + dy, - z = p0.z + dz, - } - 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 + -- Assume ignore is a trunk, to make the thing work at the border of the active area + local p1 = minetest.env:find_node_near(p0, d, {"ignore", "group:tree"}) + if p1 then + do_preserve = true + if default.leafdecay_enable_cache then + --print("caching trunk") + -- Cache the trunk + default.leafdecay_trunk_cache[p0_hash] = p1 end end - end - end if not do_preserve then -- Drop stuff other than the node itself itemstacks = minetest.get_node_drops(n0.name)