blockgame/mods/bg_tree/fall_leaves.lua
trans_soup 4ea8050c67 simplify leaves falling from trees.
by using minetest builtin support for nodes that fall when they're not
supported.
2023-10-17 19:15:52 +02:00

33 lines
847 B
Lua

local modname = minetest.get_current_modname()
blockgame.register_abm({
label = "make unsupported leaves fall",
nodenames = {
modname .. ":leaves_alive",
modname .. ":leaves_growing",
},
interval = 5,
chance = 4,
action = function (pos, node)
local is_supported = false
blockgame.flood_fill(pos, function (pos, distance)
local nodename = minetest.get_node(pos).name
if blockgame.item_matches(nodename, {"group:supports_leaves"}) then
is_supported = true
return false
end
if blockgame.item_matches(nodename, {"group:extends_leaves_support"}) then
return true
end
end, 3)
if not is_supported then
minetest.set_node(pos, {name = modname .. ":leaves"})
minetest.check_for_falling(pos)
-- TODO: send out event here that makes nearby leaves check if they're unsupported as well?
end
end,
})