Fix leafdecay along unloaded block boundaries
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>
Thu, 17 Oct 2013 21:48:49 +0000 (17:48 -0400)
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>
Thu, 17 Oct 2013 21:48:49 +0000 (17:48 -0400)
Also added separate check and variable for decaying default jungle leaves.

default_settings.txt
leafdecay.lua

index ef81c5321328d91287bc6cf910f2ce6f64f43600..6b0a1c8c710c62dcc788069f525c681af4b567eb 100644 (file)
@@ -38,17 +38,25 @@ moretrees.enable_leafdecay          = true
 
 moretrees.enable_default_leafdecay     = true
 
+-- Enable this one for default *jungle* leaves
+
+moretrees.enable_default_jungle_leafdecay      = true
+
 -- Enable this if you want moretrees to redefine default apples so that they
 -- fall when leaves decay/are dug.
 
 moretrees.enable_redefine_apple                = true
 
--- various settings to configure leaf decay in general.
+-- various settings to configure default and default-jungle leaf decay.
 
 moretrees.leafdecay_delay              = 2
 moretrees.leafdecay_chance             = 100
 moretrees.leafdecay_radius             = 5
 
+moretrees.default_jungle_leafdecay_delay = 2
+moretrees.default_jungle_leafdecay_chance = 100
+moretrees.default_jungle_leafdecay_radius = 5
+
 moretrees.palm_leafdecay_radius                = 15
 
 moretrees.default_leafdecay_delay      = 3
index be22ba4f680c24eae4af87b3a795d1ae42d71131..e2780adf41d646b7afbf941e29d006f1ddebeae3 100644 (file)
@@ -1,5 +1,14 @@
 -- leaf decay
 
+function clone_node(name)
+       node2={}
+       node=minetest.registered_nodes[name]
+       for k,v in pairs(node) do
+               node2[k]=v
+       end
+       return node2
+end
+
 if moretrees.enable_leafdecay then
        for i in ipairs(moretrees.treelist) do
                local treename = moretrees.treelist[i][1]
@@ -9,10 +18,10 @@ if moretrees.enable_leafdecay then
                                interval = moretrees.leafdecay_delay,
                                chance = moretrees.leafdecay_chance,
                                action = function(pos, node, active_object_count, active_object_count_wider)
-                                       if not minetest.find_node_near(pos, moretrees.leafdecay_radius, "moretrees:"..treename.."_trunk") then
-                                               minetest.remove_node(pos)
-                                               nodeupdate(pos)
-                                       end
+                                       if minetest.find_node_near(pos, moretrees.leafdecay_radius, "moretrees:"..treename.."_trunk") then return end
+                                       if minetest.find_node_near(pos, moretrees.leafdecay_radius, "ignore") then return end
+                                       minetest.remove_node(pos)
+                                       nodeupdate(pos)
                                end
                        })
                end
@@ -23,10 +32,10 @@ if moretrees.enable_leafdecay then
                interval = moretrees.leafdecay_delay,
                chance = moretrees.leafdecay_chance,
                action = function(pos, node, active_object_count, active_object_count_wider)
-                       if not minetest.find_node_near(pos, moretrees.leafdecay_radius, {"default:jungletree", "moretrees:jungletree_trunk"}) then
-                               minetest.remove_node(pos)
-                               nodeupdate(pos)
-                       end
+                       if minetest.find_node_near(pos, moretrees.leafdecay_radius, {"default:jungletree", "moretrees:jungletree_trunk"}) then return end
+                       if minetest.find_node_near(pos, moretrees.leafdecay_radius, "ignore") then return end
+                       minetest.remove_node(pos)
+                       nodeupdate(pos)
                end
        })
 
@@ -35,10 +44,10 @@ if moretrees.enable_leafdecay then
                interval = moretrees.leafdecay_delay,
                chance = moretrees.leafdecay_chance,
                action = function(pos, node, active_object_count, active_object_count_wider)
-                       if not minetest.find_node_near(pos, moretrees.leafdecay_radius, "moretrees:fir_trunk") then
+                       if minetest.find_node_near(pos, moretrees.leafdecay_radius, "moretrees:fir_trunk") then return end
+                       if minetest.find_node_near(pos, moretrees.leafdecay_radius, "ignore") then return end
                                minetest.remove_node(pos)
                                nodeupdate(pos)
-                       end
                end
        })
 
@@ -47,24 +56,49 @@ if moretrees.enable_leafdecay then
                interval = moretrees.leafdecay_delay,
                chance = moretrees.leafdecay_chance,
                action = function(pos, node, active_object_count, active_object_count_wider)
-                       if not minetest.find_node_near(pos, moretrees.palm_leafdecay_radius, "moretrees:palm_trunk") then
+                       if minetest.find_node_near(pos, moretrees.palm_leafdecay_radius, "moretrees:palm_trunk") then return end
+                       if minetest.find_node_near(pos, moretrees.palm_leafdecay_radius, "ignore") then return end
                                minetest.remove_node(pos)
                                nodeupdate(pos)
-                       end
                end
        })
 end
 
 if moretrees.enable_default_leafdecay then
+
+       new_default_leaves = clone_node("default:leaves")
+       new_default_leaves.groups = {snappy=3, flammable=2, leaves=1}
+       minetest.register_node(":default:leaves", new_default_leaves)
+
        minetest.register_abm({
                nodenames = "default:leaves",
                interval = moretrees.default_leafdecay_delay,
                chance = moretrees.default_leafdecay_chance,
                action = function(pos, node, active_object_count, active_object_count_wider)
-                       if not minetest.find_node_near(pos, moretrees.default_leafdecay_radius, {"default:tree"}) then
-                               minetest.remove_node(pos)
-                               nodeupdate(pos)
-                       end
+                       if minetest.find_node_near(pos, moretrees.default_leafdecay_radius, "default:tree") then return end
+                       if minetest.find_node_near(pos, moretrees.default_leafdecay_radius, "ignore") then return end
+                       minetest.remove_node(pos)
+                       nodeupdate(pos)
                end
        })      
 end
+
+if moretrees.enable_default_jungle_leafdecay then
+
+       new_default_jungle_leaves = clone_node("default:jungleleaves")
+       new_default_jungle_leaves.groups = {snappy=3, flammable=2, leaves=1}
+       minetest.register_node(":default:jungleleaves", new_default_jungle_leaves)
+
+       minetest.register_abm({
+               nodenames = "default:jungleleaves",
+               interval = moretrees.default_jungle_leafdecay_delay,
+               chance = moretrees.default_jungle_leafdecay_chance,
+               action = function(pos, node, active_object_count, active_object_count_wider)
+                       if minetest.find_node_near(pos, moretrees.default_jungle_leafdecay_radius, "default:jungletree") then return end
+                       if minetest.find_node_near(pos, moretrees.default_jungle_leafdecay_radius, "ignore") then return end
+                       minetest.remove_node(pos)
+                       nodeupdate(pos)
+               end
+       })      
+end
+