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.
This commit is contained in:
parent
8584d0ac3e
commit
c5a13d68c9
1 changed files with 19 additions and 12 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue