From 4abfcda81fab470b9011c7fd3e09b4e19671d2fa Mon Sep 17 00:00:00 2001
From: Perttu Ahola <celeron55@gmail.com>
Date: Fri, 6 Apr 2012 22:57:44 +0300
Subject: [PATCH] Optimize leaf decay based on EnvRef:find_node_near
---
mods/default/leafdecay.lua | 28 ++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/mods/default/leafdecay.lua b/mods/default/leafdecay.lua
index 36b6df8..8f4ff97 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)