refactor: decomposition placement checks.
generalize a repeated node check into a single function.
This commit is contained in:
parent
c5a13d68c9
commit
914f26e613
1 changed files with 11 additions and 6 deletions
|
@ -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.
|
||||
local decomposing_leaves_layers = 4
|
||||
|
||||
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
|
||||
if not check_decompose(pos) then return end
|
||||
|
||||
local below = pos + blockgame.vector.dirs.down
|
||||
local below_node = minetest.get_node(below)
|
||||
if blockgame.starts_with(below_node.name, modname .. ":leaves_decomposing") then
|
||||
if check_decompose(below) then
|
||||
local node = minetest.get_node(pos)
|
||||
local below_node = minetest.get_node(pos)
|
||||
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
local below_def = minetest.registered_nodes[below_node.name]
|
||||
|
||||
|
@ -90,8 +96,7 @@ local function after_place_stack (pos)
|
|||
end
|
||||
|
||||
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
|
||||
if check_decompose(above) then
|
||||
after_place_stack(above)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue