2013-02-11 18:23:05 +01:00
|
|
|
-- leaf decay
|
|
|
|
|
2013-10-27 07:05:44 +01:00
|
|
|
-- this function is based on the default leafdecay code
|
|
|
|
local process_drops = function(pos, name)
|
|
|
|
local drops = minetest.get_node_drops(name)
|
|
|
|
for _,dropitem in ipairs(drops) do
|
2014-07-13 09:41:31 +02:00
|
|
|
if dropitem ~= name
|
|
|
|
or (string.find(name, "leaves") and moretrees.decay_leaves_as_items) then
|
2013-10-27 07:05:44 +01:00
|
|
|
local newpos = {
|
2013-10-27 07:11:32 +01:00
|
|
|
x=pos.x + math.random() - 0.5,
|
|
|
|
y=pos.y + math.random() - 0.5,
|
|
|
|
z=pos.z + math.random() - 0.5
|
2013-10-27 07:05:44 +01:00
|
|
|
}
|
|
|
|
minetest.add_item(newpos, dropitem)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-12 04:07:40 +01:00
|
|
|
if moretrees.enable_leafdecay then
|
|
|
|
for i in ipairs(moretrees.treelist) do
|
|
|
|
local treename = moretrees.treelist[i][1]
|
2015-08-14 17:50:34 +02:00
|
|
|
if treename ~= "jungletree" and treename ~= "pine" and treename ~= "acacia" and treename ~= "fir" and treename ~= "palm" then
|
2013-02-12 04:07:40 +01:00
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = "moretrees:"..treename.."_leaves",
|
|
|
|
interval = moretrees.leafdecay_delay,
|
|
|
|
chance = moretrees.leafdecay_chance,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2014-08-08 03:38:51 +02:00
|
|
|
if minetest.find_node_near(pos, moretrees.leafdecay_radius, { "ignore", "moretrees:"..treename.."_trunk" }) then return end
|
2013-10-27 07:05:44 +01:00
|
|
|
process_drops(pos, node.name)
|
2013-10-17 23:48:49 +02:00
|
|
|
minetest.remove_node(pos)
|
|
|
|
nodeupdate(pos)
|
2013-02-12 04:07:40 +01:00
|
|
|
end
|
|
|
|
})
|
2013-02-11 18:23:05 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-12 04:07:40 +01:00
|
|
|
minetest.register_abm({
|
2015-08-14 17:50:34 +02:00
|
|
|
nodenames = {"default:jungleleaves", "moretrees:jungletree_leaves_red", "moretrees:jungletree_leaves_yellow"},
|
2013-02-12 04:07:40 +01:00
|
|
|
interval = moretrees.leafdecay_delay,
|
|
|
|
chance = moretrees.leafdecay_chance,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2015-08-14 17:50:34 +02:00
|
|
|
if minetest.find_node_near(pos, moretrees.leafdecay_radius, {"ignore", "default:jungletree"}) then return end
|
2013-10-27 07:05:44 +01:00
|
|
|
process_drops(pos, node.name)
|
2013-10-17 23:48:49 +02:00
|
|
|
minetest.remove_node(pos)
|
|
|
|
nodeupdate(pos)
|
2013-02-11 18:23:05 +01:00
|
|
|
end
|
2013-02-12 04:07:40 +01:00
|
|
|
})
|
2013-02-11 18:23:05 +01:00
|
|
|
|
2013-02-12 04:07:40 +01:00
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"moretrees:fir_leaves", "moretrees:fir_leaves_bright"},
|
|
|
|
interval = moretrees.leafdecay_delay,
|
|
|
|
chance = moretrees.leafdecay_chance,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2014-08-08 03:38:51 +02:00
|
|
|
if minetest.find_node_near(pos, moretrees.leafdecay_radius, { "ignore", "moretrees:fir_trunk" }) then return end
|
2014-08-08 03:46:56 +02:00
|
|
|
process_drops(pos, node.name)
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
nodeupdate(pos)
|
2013-02-12 04:07:40 +01:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = "moretrees:palm_leaves",
|
|
|
|
interval = moretrees.leafdecay_delay,
|
|
|
|
chance = moretrees.leafdecay_chance,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2014-08-08 03:38:51 +02:00
|
|
|
if minetest.find_node_near(pos, moretrees.palm_leafdecay_radius, { "ignore", "moretrees:palm_trunk" }) then return end
|
2014-08-08 03:46:56 +02:00
|
|
|
process_drops(pos, node.name)
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
nodeupdate(pos)
|
2013-02-12 04:07:40 +01:00
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
2013-02-11 18:23:05 +01:00
|
|
|
|
2014-09-10 23:17:16 +02:00
|
|
|
-- Decay apple tree blossoms from nature_classic mod
|
|
|
|
if minetest.get_modpath("nature_classic") then
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = "moretrees:apple_blossoms",
|
|
|
|
interval = moretrees.default_leafdecay_delay,
|
|
|
|
chance = moretrees.default_leafdecay_chance,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
if minetest.find_node_near(pos, moretrees.leafdecay_radius, { "ignore", "moretrees:apple_tree_trunk" }) then return end
|
|
|
|
process_drops(pos, "moretrees:apple_tree_leaves")
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
nodeupdate(pos)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|