diff --git a/mods/bg_tree/node_leaves.lua b/mods/bg_tree/node_leaves.lua index 1fa19cb..79d7479 100644 --- a/mods/bg_tree/node_leaves.lua +++ b/mods/bg_tree/node_leaves.lua @@ -66,26 +66,33 @@ reg_leaves("leaves_alive", { -- TODO: generalize stacking node registration and put into API. local decomposing_leaves_layers = 4 -local after_place_stack = function (pos) +local function after_place_stack (pos) local node = minetest.get_node(pos) if not blockgame.starts_with(node.name, modname .. ":leaves_decomposing") then return end local below = pos + blockgame.vector.dirs.down local below_node = minetest.get_node(below) - if not blockgame.starts_with(below_node.name, modname .. ":leaves_decomposing") then return end + if blockgame.starts_with(below_node.name, modname .. ":leaves_decomposing") then + local def = minetest.registered_nodes[node.name] + local below_def = minetest.registered_nodes[below_node.name] - local def = minetest.registered_nodes[node.name] - local below_def = minetest.registered_nodes[below_node.name] + if below_def.level ~= decomposing_leaves_layers then + local max_diff = decomposing_leaves_layers - below_def.level + local diff = math.min(max_diff, def.level) - if below_def.level == decomposing_leaves_layers then return end - local max_diff = decomposing_leaves_layers - below_def.level - local diff = math.min(max_diff, def.level) + minetest.swap_node(below, {name = modname .. ":leaves_decomposing_" .. (below_def.level + diff)}) + if diff == def.level then + minetest.remove_node(pos) + else + minetest.swap_node(pos, {name = modname .. ":leaves_decomposing_" .. (def.level - diff)}) + end + end + end - minetest.swap_node(below, {name = modname .. ":leaves_decomposing_" .. (below_def.level + diff)}) - if diff == def.level then - minetest.remove_node(pos) - else - minetest.swap_node(pos, {name = modname .. ":leaves_decomposing_" .. (def.level - diff)}) + local above = pos:offset(0, 1, 0) + local above_node = minetest.get_node(above) + if blockgame.starts_with(above_node.name, modname .. ":leaves_decomposing") then + after_place_stack(above) end end