local modname = minetest.get_current_modname() local api = blockgame.tree local vec = blockgame.vector -- NODE NAMES local leaves = modname .. ":leaves" local leaves_decomposing = modname .. ":leaves_decomposing" -- END OF NODE NAMES blockgame.register_increasing_abm({ id = modname .. ":begin_decompose", label = "decompose leaves", nodenames = {leaves}, neighbors = {"group:dirty", leaves_decomposing}, interval = 15, chance = 4, rate = function (pos, node, data) return data.value + math.random(4, 6) end, check = function (pos, node, data) return data.value >= 20 end, action = function (pos, node, data) minetest.set_node(pos, {name = leaves_decomposing}) end, }) local decompose_node_scores = { [leaves_decomposing] = 30, } local decompose_group_scores = { dirty = 50, } local decompose_cost = 2000 local average_leaves_per_dirt = 4 blockgame.register_increasing_abm({ id = modname .. ":decompose", label = "decompose leaves", nodenames = {leaves_decomposing}, neighbors = {"group:dirty", leaves_decomposing}, interval = 30, chance = 10, rate = function (pos, node, data) local score = 100 local source_pos = pos blockgame.flood_fill(pos, function (pos, distance) if pos == source_pos then return true end local name = minetest.get_node(pos).name local gain = 0 for group, value in pairs(decompose_group_scores) do if minetest.get_item_group(name, group) > 0 then gain = math.max(gain, value) end end gain = math.floor(gain / distance) if gain > 0 then score = score + gain return true end if decompose_node_scores[name] then score = score + math.floor(decompose_node_scores[name] / distance) return true end end, 4) return data.value + score end, check = function (pos, node, data) return data.value >= decompose_cost end, action = function (pos, node, data) if blockgame.chance(average_leaves_per_dirt) then minetest.set_node(pos, {name = "bg_terrain:dirt"}) else minetest.remove_node(pos) end end, })