Add growth stages, kinda fix jungle sapling

This commit is contained in:
Wuzzy 2017-03-07 23:28:54 +01:00
parent 269c9d764f
commit 442b2a21c9
2 changed files with 60 additions and 16 deletions

@ -166,11 +166,11 @@ minetest.register_on_dignode(function(pos, node)
end
end)
local function air_leave()
local function air_leaf(leaftype)
if math.random(0, 50) == 3 then
return {name = "air"}
else
return {name = "mcl_core:leaves"}
return {name = leaftype}
end
end
@ -217,23 +217,23 @@ function mcl_core.generate_tree(pos, trunk, leaves, typearbre)
if dx == 0 and dz == 0 and dy==3 then
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.add_node(pos, node)
minetest.add_node(pos, air_leave())
minetest.add_node(pos, air_leaf(leaves))
end
elseif dx == 0 and dz == 0 and dy==4 then
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.add_node(pos, node)
minetest.add_node(pos, air_leave())
minetest.add_node(pos, air_leaf(leaves))
end
elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
if minetest.get_node(pos).name == "air" then
minetest.add_node(pos, node)
minetest.add_node(pos, air_leave())
minetest.add_node(pos, air_leaf(leaves))
end
else
if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then
if minetest.get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.add_node(pos, node)
minetest.add_node(pos, air_leave())
minetest.add_node(pos, air_leaf(leaves))
end
end
end
@ -348,7 +348,7 @@ function mcl_core.generate_tree(pos, trunk, leaves, typearbre)
elseif dx == 0 and dz == 0 and dy==4 then
if minetest.get_node(pos).name == "air" or minetest.get_node(pos).name == "mcl_core:vine" and math.random(1, 5) == 1 then
minetest.add_node(pos, node)
minetest.add_node(pos, air_leave())
minetest.add_node(pos, air_leaf(leaves))
end
elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
if minetest.get_node(pos).name == "air" or minetest.get_node(pos).name == "mcl_core:vine" then
@ -413,19 +413,30 @@ minetest.register_abm({
--------------------------
-- TODO: Acacia, dark oak, spruce, birch
-- Normal tree
local treelight = 9
-- Oak tree
minetest.register_abm({
nodenames = {"mcl_core:sapling"},
neighbors = {"group:soil_sapling"},
interval = 20,
chance = 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 >= 1 and light and light >= 9 then
minetest.add_node(pos, {name="air"})
mcl_core.generate_tree(pos, "mcl_core:tree", "mcl_core:leaves", 1)
if soiltype >= 1 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:tree", "mcl_core:leaves", 1)
else
meta:set_int("stage", stage)
end
end
end,
})
@ -435,14 +446,23 @@ minetest.register_abm({
nodenames = {"mcl_core:junglesapling"},
neighbors = {"group:soil_sapling"},
interval = 20,
chance = 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 >= 9 then
minetest.add_node(pos, {name="air"})
mcl_core.generate_tree(pos, "mcl_core:jungletree", "mcl_core:jungleleaves", 2)
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", 1)
else
meta:set_int("stage", stage)
end
end
end,
})

@ -601,6 +601,10 @@ minetest.register_node("mcl_core:sapling", {
stack_max = 64,
groups = {dig_immediate=3, sapling=1,attached_node=1,dig_by_water=1,deco_block=1},
sounds = mcl_sounds.node_sound_leaves_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("stage", 0)
end,
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
})
@ -673,6 +677,10 @@ minetest.register_node("mcl_core:darksapling", {
stack_max = 64,
groups = {dig_immediate=3, sapling=1,attached_node=1,dig_by_water=1,deco_block=1},
sounds = mcl_sounds.node_sound_leaves_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("stage", 0)
end,
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
})
@ -801,6 +809,10 @@ minetest.register_node("mcl_core:junglesapling", {
stack_max = 64,
groups = {dig_immediate=3, sapling=1,attached_node=1,dig_by_water=1,deco_block=1},
sounds = mcl_sounds.node_sound_leaves_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("stage", 0)
end,
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
})
@ -866,6 +878,10 @@ minetest.register_node("mcl_core:acaciasapling", {
type = "fixed",
fixed = {-0.3, -0.5, -0.3, 0.3, 0.35, 0.3}
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("stage", 0)
end,
stack_max = 64,
groups = {dig_immediate=3, sapling=1,attached_node=1,dig_by_water=1,deco_block=1},
sounds = mcl_sounds.node_sound_leaves_defaults(),
@ -942,6 +958,10 @@ minetest.register_node("mcl_core:sprucesapling", {
stack_max = 64,
groups = {dig_immediate=3, sapling=1,attached_node=1,dig_by_water=1,deco_block=1},
sounds = mcl_sounds.node_sound_leaves_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("stage", 0)
end,
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
})
@ -1010,6 +1030,10 @@ minetest.register_node("mcl_core:birchsapling", {
stack_max = 64,
groups = {dig_immediate=3, sapling=1,attached_node=1,dig_by_water=1,deco_block=1},
sounds = mcl_sounds.node_sound_leaves_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("stage", 0)
end,
_mcl_blast_resistance = 0,
_mcl_hardness = 0,
})