day 03-18: add leaves, leaf growing

* added simple leaf growing, leave occupy free adjacent space next to
  growng trunks
* addded leaves node
This commit is contained in:
Aleksey Chubukov 2023-03-19 00:48:40 +03:00
parent e20268de06
commit d1c1c3bfac
7 changed files with 51 additions and 28 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 674 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 936 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 829 B

View File

@ -1,19 +1,26 @@
ebiometrees = {} ebiometrees = {}
function ebiometrees.get_sapling_grower(sprout_name) function ebiometrees.is_leaves_can_grow_here(pos)
local function rooter(pos) return false
minetest.set_node(pos, {name=sprout_name})
end
return rooter
end end
function ebiometrees.get_sprout_grower(trunk_name, apex_name) function ebiometrees.grow_closure(nextstage)
local function grower(pos) local function growtree(pos)
minetest.set_node(pos, {name=trunk_name}) minetest.set_node(pos, {name=nextstage})
local upper = {x=pos.x, y=pos.y+1, z=pos.z}
minetest.set_node(upper, {name=apex_name})
end end
return grower return growtree
end
function ebiometrees.leaves_grower(leaves_name)
local function grow_leaves(pos)
local free_node = minetest.find_node_near(pos, 1, "air")
if free_node
then
minetest.set_node(free_node, {name=leaves_name})
end
return true
end
return grow_leaves
end end
function ebiometrees.root_sapling(pos) function ebiometrees.root_sapling(pos)
@ -21,8 +28,3 @@ function ebiometrees.root_sapling(pos)
return false return false
end end
function ebiometrees.set_rooting_sapling(itemstack, placer, pointed_thing)
itemstack = minetest.item_place(itemstack, placer, pointed_thing)
minetest.get_node_timer(pointed_thing.above):start(3)
return itemstack
end

View File

@ -21,7 +21,9 @@ function ebiometrees.register_tree(modname, basename, data)
drawtype = "plantlike", drawtype = "plantlike",
tiles = { modname.."_"..basename.."_sapling.png"}, tiles = { modname.."_"..basename.."_sapling.png"},
paramtype = "light", paramtype = "light",
on_timer = ebiometrees.get_sapling_grower(sprout_name), on_timer = ebiometrees.grow_closure(
modname..":"..basename.."_sprout"
),
sunlight_propagates = true, sunlight_propagates = true,
walkable = false, walkable = false,
groups = sapling_groups, groups = sapling_groups,
@ -35,13 +37,28 @@ function ebiometrees.register_tree(modname, basename, data)
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
walkable = false, walkable = false,
on_timer = ebiometrees.get_sprout_grower( on_timer = ebiometrees.grow_closure(
modname..":"..basename.."_trunk_growing_straight", modname..":"..basename.."_trunk_growing_terminal"
modname..":"..basename.."_trunk_growing_terminal"), ),
groups = sprout_groups, groups = sprout_groups,
on_construct = growth_timer on_construct = growth_timer
}) })
-- registers tree and corresponding nodes -- register tree leaves
local leaves_groups = table.copy(data.groups)
leaves_groups.leaves = 1
leaves_groups.leafdecay = 3
leaves_groups.snappy = 3
minetest.register_node(modname..":"..basename.."_leaves", {
description = S(data.description.." leaves"),
drawtype = "allfaces_optional",
waving = 1,
tiles = { modname.."_"..basename.."_leaves.png" },
special_tiles = { modname.."_"..basename.."_leaves_simple.png" },
paramtype = "light",
is_ground_content = false,
groups = leaves_groups
})
-- registers corresponding trunk nodes
local trunk_groups = table.copy(data.groups) local trunk_groups = table.copy(data.groups)
trunk_groups.choppy = 2 -- TODO: customizations trunk_groups.choppy = 2 -- TODO: customizations
local trunk_types = {"growing", "normal"} local trunk_types = {"growing", "normal"}
@ -54,7 +71,7 @@ function ebiometrees.register_tree(modname, basename, data)
local texture_basename = modname.."_"..basename.."_trunk_"..trunk_type.."_" local texture_basename = modname.."_"..basename.."_trunk_"..trunk_type.."_"
local subtype_tiles = { local subtype_tiles = {
terminal = { terminal = {
texture_basename.."terminal.png", texture_basename.."top.png",
texture_basename.."slice.png", texture_basename.."slice.png",
texture_basename.."terminal.png" texture_basename.."terminal.png"
}, },
@ -109,19 +126,23 @@ function ebiometrees.register_tree(modname, basename, data)
} }
for _, trunk_subtype in ipairs(trunk_subtypes) for _, trunk_subtype in ipairs(trunk_subtypes)
do do
minetest.register_node( local nodespec = {
modname..":"..basename.."_trunk_"..trunk_type.."_"..trunk_subtype, {
description = S(data.description.." "..trunk_type.." "..trunk_subtype), description = S(data.description.." "..trunk_type.." "..trunk_subtype),
groups = trunk_groups, groups = trunk_groups,
tiles = subtype_tiles[trunk_subtype], tiles = subtype_tiles[trunk_subtype],
paramtype2 = "facedir", paramtype2 = "facedir",
is_ground_content = false, is_ground_content = false,
on_place = minetest.rotate_node, on_place = minetest.rotate_node,
on_timer = function(pos)
return true
end,
on_construct = growth_timer on_construct = growth_timer
}) }
if trunk_type == "growing"
then
nodespec.on_timer = ebiometrees.leaves_grower(
modname..":"..basename.."_leaves")
end
minetest.register_node(
modname..":"..basename.."_trunk_"..trunk_type.."_"..trunk_subtype,
nodespec)
end end
end end
end end