Simplify sapling growth code

This commit is contained in:
Wuzzy 2017-03-08 01:54:04 +01:00
parent 04960c8ab9
commit 1cf9e3701d

View File

@ -415,17 +415,12 @@ minetest.register_abm({
local treelight = 9
-- Oak tree
minetest.register_abm({
nodenames = {"mcl_core:sapling"},
neighbors = {"group:soil_sapling"},
interval = 20,
chance = 1,
action = function(pos)
local sapling_grow_action = function(trunknode, leafnode, tree_id, soil_needed)
return function(pos)
local light = minetest.get_node_light(pos)
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")
if soiltype >= 1 and light and light >= treelight then
if soiltype >= soil_needed and light and light >= treelight then
-- Increase and check growth stage
local meta = minetest.get_meta(pos)
local stage = meta:get_int("stage")
@ -433,12 +428,21 @@ minetest.register_abm({
stage = stage + 1
if stage == 2 then
minetest.set_node(pos, {name="air"})
mcl_core.generate_tree(pos, "mcl_core:tree", "mcl_core:leaves", 1)
mcl_core.generate_tree(pos, trunknode, leafnode, tree_id)
else
meta:set_int("stage", stage)
end
end
end,
end
end
-- Oak tree
minetest.register_abm({
nodenames = {"mcl_core:sapling"},
neighbors = {"group:soil_sapling"},
interval = 20,
chance = 1,
action = sapling_grow_action("mcl_core:tree", "mcl_core:leaves", 1, 1),
})
-- Jungle Tree
@ -447,24 +451,7 @@ minetest.register_abm({
neighbors = {"group:soil_sapling"},
interval = 20,
chance = 1,
action = function(pos)
local light = minetest.get_node_light(pos)
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")
if soiltype == 2 and light and light >= treelight then
-- Increase and check growth stage
local meta = minetest.get_meta(pos)
local stage = meta:get_int("stage")
if stage == nil then stage = 0 end
stage = stage + 1
if stage == 2 then
minetest.set_node(pos, {name="air"})
mcl_core.generate_tree(pos, "mcl_core:jungletree", "mcl_core:jungleleaves", 2)
else
meta:set_int("stage", stage)
end
end
end,
action = sapling_grow_action("mcl_core:jungletree", "mcl_core:jungleleaves", 1, 2)
})
---------------------