diff --git a/mods/default/init.lua b/mods/default/init.lua index 6f1b148..b362fc7 100644 --- a/mods/default/init.lua +++ b/mods/default/init.lua @@ -36,6 +36,7 @@ default.gui_survival_form = "size[8,8.5]".. -- Load files dofile(minetest.get_modpath("default").."/functions.lua") +dofile(minetest.get_modpath("default").."/trees.lua") dofile(minetest.get_modpath("default").."/nodes.lua") dofile(minetest.get_modpath("default").."/furnace.lua") dofile(minetest.get_modpath("default").."/tools.lua") @@ -43,6 +44,5 @@ dofile(minetest.get_modpath("default").."/craftitems.lua") dofile(minetest.get_modpath("default").."/crafting.lua") dofile(minetest.get_modpath("default").."/mapgen.lua") dofile(minetest.get_modpath("default").."/player.lua") -dofile(minetest.get_modpath("default").."/trees.lua") dofile(minetest.get_modpath("default").."/aliases.lua") dofile(minetest.get_modpath("default").."/legacy.lua") diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index a97a30f..9c1dc44 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -455,6 +455,10 @@ minetest.register_node("default:sapling", { paramtype = "light", sunlight_propagates = true, walkable = false, + on_timer = default.grow_sapling, + on_construct = function(pos) + minetest.get_node_timer(pos):start(math.random(2400,4800)) + end, selection_box = { type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} @@ -573,6 +577,10 @@ minetest.register_node("default:junglesapling", { paramtype = "light", sunlight_propagates = true, walkable = false, + on_timer = default.grow_sapling, + on_construct = function(pos) + minetest.get_node_timer(pos):start(math.random(2400,4800)) + end, selection_box = { type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} @@ -634,6 +642,10 @@ minetest.register_node("default:pine_sapling", { paramtype = "light", sunlight_propagates = true, walkable = false, + on_timer = default.grow_sapling, + on_construct = function(pos) + minetest.get_node_timer(pos):start(math.random(2400,4800)) + end, selection_box = { type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} @@ -695,6 +707,10 @@ minetest.register_node("default:acacia_sapling", { paramtype = "light", sunlight_propagates = true, walkable = false, + on_timer = default.grow_sapling, + on_construct = function(pos) + minetest.get_node_timer(pos):start(math.random(2400,4800)) + end, selection_box = { type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} @@ -755,6 +771,10 @@ minetest.register_node("default:aspen_sapling", { paramtype = "light", sunlight_propagates = true, walkable = false, + on_timer = default.grow_sapling, + on_construct = function(pos) + minetest.get_node_timer(pos):start(math.random(2400,4800)) + end, selection_box = { type = "fixed", fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3} diff --git a/mods/default/trees.lua b/mods/default/trees.lua index de2452e..1b06266 100644 --- a/mods/default/trees.lua +++ b/mods/default/trees.lua @@ -59,58 +59,63 @@ end -- Sapling ABM -minetest.register_abm({ - nodenames = {"default:sapling", "default:junglesapling", - "default:pine_sapling", "default:acacia_sapling", - "default:aspen_sapling"}, - interval = 10, - chance = 50, - action = function(pos, node) - if not default.can_grow(pos) then - return - end +function default.grow_sapling(pos) + if not default.can_grow(pos) then + -- try a bit later again + minetest.get_node_timer(pos):start(math.random(240, 600)) + return + end - local mapgen = minetest.get_mapgen_params().mgname - if node.name == "default:sapling" then - minetest.log("action", "A sapling grows into a tree at ".. - minetest.pos_to_string(pos)) - if mapgen == "v6" then - default.grow_tree(pos, random(1, 4) == 1) - else - default.grow_new_apple_tree(pos) - end - elseif node.name == "default:junglesapling" then - minetest.log("action", "A jungle sapling grows into a tree at ".. - minetest.pos_to_string(pos)) - if mapgen == "v6" then - default.grow_jungle_tree(pos) - else - default.grow_new_jungle_tree(pos) - end - elseif node.name == "default:pine_sapling" then - minetest.log("action", "A pine sapling grows into a tree at ".. - minetest.pos_to_string(pos)) - local snow = is_snow_nearby(pos) - if mapgen == "v6" then - default.grow_pine_tree(pos, snow) - elseif snow then - default.grow_new_snowy_pine_tree(pos) - else - default.grow_new_pine_tree(pos) - end - elseif node.name == "default:acacia_sapling" then - minetest.log("action", "An acacia sapling grows into a tree at ".. - minetest.pos_to_string(pos)) - default.grow_new_acacia_tree(pos) - elseif node.name == "default:aspen_sapling" then - minetest.log("action", "An aspen sapling grows into a tree at ".. - minetest.pos_to_string(pos)) - default.grow_new_aspen_tree(pos) + local mapgen = minetest.get_mapgen_params().mgname + local node = minetest.get_node(pos) + if node.name == "default:sapling" then + minetest.log("action", "A sapling grows into a tree at ".. + minetest.pos_to_string(pos)) + if mapgen == "v6" then + default.grow_tree(pos, random(1, 4) == 1) + else + default.grow_new_apple_tree(pos) end + elseif node.name == "default:junglesapling" then + minetest.log("action", "A jungle sapling grows into a tree at ".. + minetest.pos_to_string(pos)) + if mapgen == "v6" then + default.grow_jungle_tree(pos) + else + default.grow_new_jungle_tree(pos) + end + elseif node.name == "default:pine_sapling" then + minetest.log("action", "A pine sapling grows into a tree at ".. + minetest.pos_to_string(pos)) + local snow = is_snow_nearby(pos) + if mapgen == "v6" then + default.grow_pine_tree(pos, snow) + elseif snow then + default.grow_new_snowy_pine_tree(pos) + else + default.grow_new_pine_tree(pos) + end + elseif node.name == "default:acacia_sapling" then + minetest.log("action", "An acacia sapling grows into a tree at ".. + minetest.pos_to_string(pos)) + default.grow_new_acacia_tree(pos) + elseif node.name == "default:aspen_sapling" then + minetest.log("action", "An aspen sapling grows into a tree at ".. + minetest.pos_to_string(pos)) + default.grow_new_aspen_tree(pos) + end +end + +minetest.register_lbm({ + name = "default:convert_saplings_to_node_timer", + nodenames = {"default:sapling", "default:junglesapling", + "default:pine_sapling", "default:acacia_sapling", + "default:aspen_sapling"}, + action = function(pos) + minetest.get_node_timer(pos):start(math.random(1200, 2400)) end }) - -- -- Tree generation --