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_scores = { dirty = 50, leaves_decomposing = 30, } local decompose_cost = 2000 blockgame.register_increasing_abm({ id = modname .. ":decompose", label = "decompose leaves", nodenames = {"group:leaves_decomposing"}, -- neighbors = {"group:dirty", "group: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_scores) do local group = minetest.get_item_group(name, group) if group > 0 then gain = math.max(gain, value * group) end end gain = math.floor(gain / distance) if gain > 0 then score = score + gain return true end return false end, 4) return data.value + score end, check = function (pos, node, data) return data.value >= decompose_cost end, action = function (pos, node, data) -- currently, larger leaf piles have a greater chance of turning into dirt instead of disappearing. -- might wanna make it so that instead, dirt is layered as well? local def = minetest.registered_nodes[node.name] local dirt_chance = def.level_max - def.level + 1 if blockgame.chance(dirt_chance) then minetest.set_node(pos, {name = "bg_terrain:dirt"}) else minetest.remove_node(pos) end end, })