cherry-pick from github.com/minetest/minetest_game> Default: Convert saplings to use node timers
Each sapling is given a single node timer that is between 2 and 4 days of game play time (40-80 minutes). If you walk out of the zone, and come back later, the tree will always grow to full if the timer has elapsed. Because trees.lua is all functions, it needs to be parsed before nodes.lua, since that references some of its functions. Hence, change the order of parsing here. Otherwise saplings would not grow to full.
This commit is contained in:
parent
b80af1bc95
commit
0da14dbb56
@ -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")
|
||||
|
@ -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}
|
||||
|
@ -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
|
||||
--
|
||||
|
Loading…
x
Reference in New Issue
Block a user