diff --git a/mods/bg_tree/grow_sapling.lua b/mods/bg_tree/grow_sapling.lua index 048ad11..ffe7336 100644 --- a/mods/bg_tree/grow_sapling.lua +++ b/mods/bg_tree/grow_sapling.lua @@ -5,7 +5,6 @@ local modname = minetest.get_current_modname() local sapling = modname .. ":sapling" local log_alive = modname .. ":log_alive" local leaves_growing = modname .. ":leaves_growing" -local root_alive = modname .. ":root_alive" -- END OF NODE NAMES @@ -42,11 +41,24 @@ blockgame.register_increasing_abm({ -- (this will require the api adding support for increasing_abm actions modifying their data.) local above = pos + blockgame.vector.dirs.up + -- grow up, with a chance to stop growing. if not blockgame.chance(4) then minetest.set_node(above, {name = sapling}) end - minetest.set_node(pos, {name = log_alive}) + local below = pos + blockgame.vector.dirs.down + -- if this tree have already grown at least once, create a log... + if blockgame.item_matches(minetest.get_node(below).name, { + modname .. ":root_alive", + modname .. ":log_alive", + }) then + minetest.set_node(pos, {name = log_alive}) + else + -- ... otherwise, create a root + minetest.set_node(pos, {name = modname .. ":root_alive"}) + end + + -- grow out leaves to the sides. local sides = blockgame.vector.get_sides_of(pos) for _, side in pairs(sides) do blockgame.attempt_place(side, {name = leaves_growing})