blockgame/mods/bg_tree/fall_leaves.lua
2023-10-19 13:14:50 +02:00

34 lines
923 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
-- TODO: become randomly-sized leaves pile when layered leaves is added.
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,
})