From 58e692bc65fe67cf03a99303862842a2727e0f2a Mon Sep 17 00:00:00 2001 From: KaadmY Date: Mon, 3 Jul 2017 15:33:38 -0700 Subject: [PATCH] Fix some bugs with the new sapling code and add legacy support for old saplings --- mods/default/functions.lua | 32 ++++++++++++++++++++++++++++++-- mods/default/nodes.lua | 6 +++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/mods/default/functions.lua b/mods/default/functions.lua index 32360d0..b01fc77 100644 --- a/mods/default/functions.lua +++ b/mods/default/functions.lua @@ -50,7 +50,21 @@ function default.place_sapling(itemstack, placer, pointed_thing) minetest.set_node(pointed_thing.above, {name = itemstack:get_name()}) - return itemstack:take_item() + itemstack:take_item() + + return itemstack +end + +function default.begin_growing_sapling(pos) + local node = minetest.get_node(pos) + + if node.name == "default:sapling" then + minetest.get_node_timer(pos):start(math.random(300, 480)) + elseif node.name == "default:sapling_oak" then + minetest.get_node_timer(pos):start(math.random(700, 960)) + elseif node.name == "default:sapling_birch" then + minetest.get_node_timer(pos):start(math.random(480, 780)) + end end function default.grow_sapling(pos, variety) @@ -99,9 +113,23 @@ function default.grow_sapling(pos, variety) minetest.after(0, grow) - default.log(variety.." tree sapling grows at "..minetest.pos_to_string(pos), "info") + default.log("A " .. variety .. " tree sapling grows at " .. + minetest.pos_to_string(pos), "info") end +-- Make preexisting trees restart the growing process + +minetest.register_lbm( + { + label = "Grow legacy trees", + name = "default:grow_legacy_trees", + nodenames = {"default:sapling", "default:sapling_oak", "default:sapling_birch"}, + action = function(pos, node) + default.begin_growing_sapling(pos) + end + } +) + -- Vertical plants function default.dig_up(pos, node, digger) diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 6586bb4..2f98181 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -448,7 +448,7 @@ minetest.register_node( end, on_construct = function(pos) - minetest.get_node_timer(pos):start(math.random(300, 480)) + default.begin_growing_sapling(pos) end, on_place = default.place_sapling, @@ -477,7 +477,7 @@ minetest.register_node( end, on_construct = function(pos) - minetest.get_node_timer(pos):start(math.random(700, 960)) + default.begin_growing_sapling(pos) end, on_place = default.place_sapling, @@ -507,7 +507,7 @@ minetest.register_node( end, on_construct = function(pos) - minetest.get_node_timer(pos):start(math.random(480, 780)) + default.begin_growing_sapling(pos) end, on_place = default.place_sapling,