From f4d8c7597db276ea1d4ced0a145c6a6913232f6d Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Tue, 17 Oct 2023 16:13:54 +0200 Subject: [PATCH] improve sapling/root growth. trees will now create a living root node at their bottom when they grow for the first time. --- mods/bg_tree/grow_sapling.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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})