local modname = minetest.get_current_modname() -- NODE NAMES local log_alive = modname .. ":log_alive" local leaves = modname .. ":leaves" local leaves_growing = modname .. ":leaves_growing" local leaves_alive = modname .. ":leaves_alive" -- END OF NODE NAMES local max_grow_distance = 2 -- TODO: turn this into an increasing ABM. blockgame.register_abm({ label = "grow leaves", nodenames = {leaves_growing}, neighbors = {log_alive, leaves_growing, leaves_alive}, interval = 15, chance = 8, action = function (pos, node) -- TODO: give leaves energy over time, that they spend when creating new leaves. local meta = minetest.get_meta(pos) local distance = meta:get_int("leaf_distance") or 1 if distance >= max_grow_distance then return end local neighbors = blockgame.get_neighbors(pos) for _, target in pairs(neighbors) do if blockgame.chance(2) then blockgame.attempt_place(target, {name = leaves_growing}) minetest.get_meta(target):set_int("leaf_distance", distance + 1) end end minetest.set_node(pos, {name = leaves_alive}) end, })