refactor: decomposition placement checks.

generalize a repeated node check into a single function.
This commit is contained in:
trans_soup 2023-10-21 10:50:11 +02:00
parent c5a13d68c9
commit 914f26e613

View file

@ -63,16 +63,22 @@ reg_leaves("leaves_alive", {
}, },
}) })
local function check_decompose (pos)
local node = minetest.get_node(pos)
return blockgame.item_matches(node.name, {"group:leaves_decomposing"})
end
-- TODO: generalize stacking node registration and put into API. -- TODO: generalize stacking node registration and put into API.
local decomposing_leaves_layers = 4 local decomposing_leaves_layers = 4
local function after_place_stack (pos) local function after_place_stack (pos)
local node = minetest.get_node(pos) if not check_decompose(pos) then return end
if not blockgame.starts_with(node.name, modname .. ":leaves_decomposing") then return end
local below = pos + blockgame.vector.dirs.down local below = pos + blockgame.vector.dirs.down
local below_node = minetest.get_node(below) if check_decompose(below) then
if blockgame.starts_with(below_node.name, modname .. ":leaves_decomposing") then local node = minetest.get_node(pos)
local below_node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
local below_def = minetest.registered_nodes[below_node.name] local below_def = minetest.registered_nodes[below_node.name]
@ -90,8 +96,7 @@ local function after_place_stack (pos)
end end
local above = pos:offset(0, 1, 0) local above = pos:offset(0, 1, 0)
local above_node = minetest.get_node(above) if check_decompose(above) then
if blockgame.starts_with(above_node.name, modname .. ":leaves_decomposing") then
after_place_stack(above) after_place_stack(above)
end end
end end