1
0
Fork 0

Simplify sapling growth code

objects
Wuzzy 2017-03-08 01:54:04 +01:00
parent 04960c8ab9
commit 1cf9e3701d
1 changed files with 15 additions and 28 deletions

View File

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