forked from VoxeLibre/VoxeLibre
Fix Wuzzy/MineClone2#1028 - Make tree saplings grow in inactive areas (approx. time calc.)
This commit is contained in:
parent
30b4b9661c
commit
948265fd6b
|
@ -899,19 +899,41 @@ local treelight = 9
|
||||||
|
|
||||||
local sapling_grow_action = function(tree_id, soil_needed, one_by_one, two_by_two, sapling)
|
local sapling_grow_action = function(tree_id, soil_needed, one_by_one, two_by_two, sapling)
|
||||||
return function(pos)
|
return function(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if meta:get("grown") then return end
|
||||||
-- Checks if the sapling at pos has enough light and the correct soil
|
-- Checks if the sapling at pos has enough light and the correct soil
|
||||||
local sapling_is_growable = function(pos)
|
|
||||||
local light = minetest.get_node_light(pos)
|
local light = minetest.get_node_light(pos)
|
||||||
|
if not light then return end
|
||||||
|
local low_light = (light < treelight)
|
||||||
|
|
||||||
|
local delta = 1
|
||||||
|
local current_game_time = minetest.get_day_count() + minetest.get_timeofday()
|
||||||
|
|
||||||
|
local last_game_time = tonumber(meta:get_string("last_gametime"))
|
||||||
|
meta:set_string("last_gametime", tostring(current_game_time))
|
||||||
|
|
||||||
|
if last_game_time then
|
||||||
|
delta = current_game_time - last_game_time
|
||||||
|
elseif low_light then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if low_light then
|
||||||
|
if delta < 1.2 then return end
|
||||||
|
if minetest.get_node_light(pos, 0.5) < treelight then return end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- TODO: delta is [days] missed in inactive area. Currently we just add it to stage, which is far from a perfect calculation...
|
||||||
|
|
||||||
local soilnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
local soilnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
||||||
local soiltype = minetest.get_item_group(soilnode.name, "soil_sapling")
|
local soiltype = minetest.get_item_group(soilnode.name, "soil_sapling")
|
||||||
return soiltype >= soil_needed and light and light >= treelight and not minetest.get_meta(pos):get("grown")
|
if soiltype < soil_needed then return end
|
||||||
end
|
|
||||||
if sapling_is_growable(pos) then
|
|
||||||
-- Increase and check growth stage
|
-- Increase and check growth stage
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local stage = meta:get_int("stage")
|
local stage = meta:get_int("stage")
|
||||||
if stage == nil then stage = 0 end
|
if stage == nil then stage = 0 end
|
||||||
stage = stage + 1
|
stage = stage + math.max(1, math.floor(delta))
|
||||||
if stage >= 3 then
|
if stage >= 3 then
|
||||||
meta:set_string("grown", "true")
|
meta:set_string("grown", "true")
|
||||||
-- This sapling grows in a special way when there are 4 saplings in a 2×2 pattern
|
-- This sapling grows in a special way when there are 4 saplings in a 2×2 pattern
|
||||||
|
@ -968,7 +990,6 @@ local sapling_grow_action = function(tree_id, soil_needed, one_by_one, two_by_tw
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if one_by_one and tree_id == OAK_TREE_ID then
|
if one_by_one and tree_id == OAK_TREE_ID then
|
||||||
-- There is a chance that this tree wants to grow as a balloon oak
|
-- There is a chance that this tree wants to grow as a balloon oak
|
||||||
if math.random(1, 12) == 1 then
|
if math.random(1, 12) == 1 then
|
||||||
|
@ -980,7 +1001,6 @@ local sapling_grow_action = function(tree_id, soil_needed, one_by_one, two_by_tw
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If this sapling can grow alone
|
-- If this sapling can grow alone
|
||||||
if one_by_one and check_tree_growth(pos, tree_id) then
|
if one_by_one and check_tree_growth(pos, tree_id) then
|
||||||
-- Single sapling
|
-- Single sapling
|
||||||
|
@ -994,7 +1014,6 @@ local sapling_grow_action = function(tree_id, soil_needed, one_by_one, two_by_tw
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local grow_oak = sapling_grow_action(OAK_TREE_ID, 1, true, false)
|
local grow_oak = sapling_grow_action(OAK_TREE_ID, 1, true, false)
|
||||||
local grow_dark_oak = sapling_grow_action(DARK_OAK_TREE_ID, 2, false, true, "mcl_core:darksapling")
|
local grow_dark_oak = sapling_grow_action(DARK_OAK_TREE_ID, 2, false, true, "mcl_core:darksapling")
|
||||||
|
@ -1040,7 +1059,14 @@ minetest.register_abm({
|
||||||
neighbors = {"group:soil_sapling"},
|
neighbors = {"group:soil_sapling"},
|
||||||
interval = 25,
|
interval = 25,
|
||||||
chance = 2,
|
chance = 2,
|
||||||
action = grow_oak,
|
action = grow_oak
|
||||||
|
})
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "Add growth for unloaded oak tree",
|
||||||
|
name = "mcl_core:lbm_oak",
|
||||||
|
nodenames = {"mcl_core:sapling"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = grow_oak
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Dark oak tree
|
-- Dark oak tree
|
||||||
|
@ -1050,7 +1076,14 @@ minetest.register_abm({
|
||||||
neighbors = {"group:soil_sapling"},
|
neighbors = {"group:soil_sapling"},
|
||||||
interval = 25,
|
interval = 25,
|
||||||
chance = 2,
|
chance = 2,
|
||||||
action = grow_dark_oak,
|
action = grow_dark_oak
|
||||||
|
})
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "Add growth for unloaded dark oak tree",
|
||||||
|
name = "mcl_core:lbm_dark_oak",
|
||||||
|
nodenames = {"mcl_core:darksapling"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = grow_dark_oak
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Jungle Tree
|
-- Jungle Tree
|
||||||
|
@ -1060,7 +1093,14 @@ minetest.register_abm({
|
||||||
neighbors = {"group:soil_sapling"},
|
neighbors = {"group:soil_sapling"},
|
||||||
interval = 25,
|
interval = 25,
|
||||||
chance = 2,
|
chance = 2,
|
||||||
action = grow_jungle_tree,
|
action = grow_jungle_tree
|
||||||
|
})
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "Add growth for unloaded jungle tree",
|
||||||
|
name = "mcl_core:lbm_jungle_tree",
|
||||||
|
nodenames = {"mcl_core:junglesapling"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = grow_jungle_tree
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Spruce tree
|
-- Spruce tree
|
||||||
|
@ -1072,6 +1112,13 @@ minetest.register_abm({
|
||||||
chance = 2,
|
chance = 2,
|
||||||
action = grow_spruce
|
action = grow_spruce
|
||||||
})
|
})
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "Add growth for unloaded spruce tree",
|
||||||
|
name = "mcl_core:lbm_spruce",
|
||||||
|
nodenames = {"mcl_core:sprucesapling"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = grow_spruce
|
||||||
|
})
|
||||||
|
|
||||||
-- Birch tree
|
-- Birch tree
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
|
@ -1080,7 +1127,14 @@ minetest.register_abm({
|
||||||
neighbors = {"group:soil_sapling"},
|
neighbors = {"group:soil_sapling"},
|
||||||
interval = 25,
|
interval = 25,
|
||||||
chance = 2,
|
chance = 2,
|
||||||
action = grow_birch,
|
action = grow_birch
|
||||||
|
})
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "Add growth for unloaded birch tree",
|
||||||
|
name = "mcl_core:lbm_birch",
|
||||||
|
nodenames = {"mcl_core:birchsapling"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = grow_spruce
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Acacia tree
|
-- Acacia tree
|
||||||
|
@ -1090,7 +1144,14 @@ minetest.register_abm({
|
||||||
neighbors = {"group:soil_sapling"},
|
neighbors = {"group:soil_sapling"},
|
||||||
interval = 20,
|
interval = 20,
|
||||||
chance = 2,
|
chance = 2,
|
||||||
action = grow_acacia,
|
action = grow_acacia
|
||||||
|
})
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "Add growth for unloaded acacia tree",
|
||||||
|
name = "mcl_core:lbm_acacia",
|
||||||
|
nodenames = {"mcl_core:acaciasapling"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = grow_spruce
|
||||||
})
|
})
|
||||||
|
|
||||||
local function leafdecay_particles(pos, node)
|
local function leafdecay_particles(pos, node)
|
||||||
|
|
Loading…
Reference in New Issue