blockgame/mods/bg_tree/fall_leaves.lua
2023-10-22 21:09:38 +02:00

36 lines
977 B
Lua

local modname = minetest.get_current_modname()
local level_max = minetest.registered_items[modname .. ":leaves"].level_max
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
local level = math.random(1, level_max)
minetest.set_node(pos, {name = modname .. ":leaves_" .. level})
minetest.check_for_falling(pos)
-- TODO: send out event here that makes nearby leaves check if they're unsupported as well?
end
end,
})