From c5a13d68c92e81acfa3e6f0afeed8ea9f4ef51be Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Sat, 21 Oct 2023 10:38:16 +0200 Subject: [PATCH] fix floating decomposing leaves. leaves will now, upon beginning decomposition, check if there are decomposing leaves on top of them which can fall down onto them. this fixes an error where this situation would leave the top leaves visually floating over the bottom leaves, even when there was space for them to stack. --- mods/bg_tree/node_leaves.lua | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) 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