2023-05-10 23:39:08 +00:00
|
|
|
|
2023-03-18 20:52:22 +00:00
|
|
|
local function growth_timer(pos)
|
|
|
|
minetest.get_node_timer(pos):start(3)
|
2023-03-19 21:47:19 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:mark_as_private("ebiometrees:age")
|
2023-05-10 23:39:08 +00:00
|
|
|
meta:set_int("ebiometrees:age", 0)
|
2023-03-18 20:52:22 +00:00
|
|
|
end
|
|
|
|
|
2023-05-10 23:39:08 +00:00
|
|
|
function ebiometrees.register_tree_leaves(modname, basename, data)
|
|
|
|
local S = minetest.get_translator(modname)
|
|
|
|
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
|
|
|
|
})
|
|
|
|
end
|
2023-03-18 20:52:22 +00:00
|
|
|
|
2023-05-10 23:39:08 +00:00
|
|
|
function ebiometrees.register_tree_sapling(modname, basename, data)
|
2023-03-18 20:52:22 +00:00
|
|
|
-- register saplings
|
2023-05-10 23:39:08 +00:00
|
|
|
local S = minetest.get_translator(modname)
|
2023-03-18 20:52:22 +00:00
|
|
|
local sapling_groups = table.copy(data.groups)
|
|
|
|
sapling_groups.sapling = 1
|
|
|
|
sapling_groups.snappy = 2
|
|
|
|
sapling_groups.dig_immediate = 3
|
2023-05-10 23:39:08 +00:00
|
|
|
minetest.register_node(modname..":"..basename.."_sapling", {
|
2023-03-18 20:52:22 +00:00
|
|
|
description = S(data.description.." sapling"),
|
|
|
|
drawtype = "plantlike",
|
|
|
|
tiles = { modname.."_"..basename.."_sapling.png"},
|
|
|
|
paramtype = "light",
|
2023-03-18 21:48:40 +00:00
|
|
|
on_timer = ebiometrees.grow_closure(
|
|
|
|
modname..":"..basename.."_sprout"
|
|
|
|
),
|
2023-03-18 20:52:22 +00:00
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = false,
|
|
|
|
groups = sapling_groups,
|
|
|
|
on_construct = growth_timer
|
|
|
|
})
|
2023-05-10 23:39:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ebiometrees.register_tree_sprout(modname, basename, data)
|
|
|
|
-- register tree leaves
|
|
|
|
local S = minetest.get_translator(modname)
|
|
|
|
local sprout_groups = table.copy(data.groups)
|
|
|
|
sprout_groups.sapling = 1
|
|
|
|
sprout_groups.snappy = 2
|
|
|
|
minetest.register_node(modname..":"..basename.."_sprout", {
|
2023-03-18 20:52:22 +00:00
|
|
|
description = S(data.description.." sprout"),
|
|
|
|
drawtype = "plantlike",
|
|
|
|
visual_scale = 1.4,
|
|
|
|
tiles = { modname.."_"..basename.."_sprout.png" },
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = false,
|
2023-03-18 21:48:40 +00:00
|
|
|
on_timer = ebiometrees.grow_closure(
|
|
|
|
modname..":"..basename.."_trunk_growing_terminal"
|
|
|
|
),
|
2023-03-18 20:52:22 +00:00
|
|
|
groups = sprout_groups,
|
|
|
|
on_construct = growth_timer
|
|
|
|
})
|
2023-05-10 23:39:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ebiometrees.register_tree_trunks(modname, basename, data)
|
|
|
|
local S = minetest.get_translator(modname)
|
2023-03-18 21:48:40 +00:00
|
|
|
-- registers corresponding trunk nodes
|
2023-03-18 20:52:22 +00:00
|
|
|
local trunk_groups = table.copy(data.groups)
|
|
|
|
trunk_groups.choppy = 2 -- TODO: customizations
|
2023-03-19 21:47:19 +00:00
|
|
|
trunk_groups.treetrunk = 1
|
2023-03-18 20:52:22 +00:00
|
|
|
local trunk_types = {"growing", "normal"}
|
|
|
|
local trunk_subtypes = {"terminal", "straight", "corner",
|
|
|
|
"tjunction", "t2junction", "xjunction",
|
|
|
|
"xtjunction", "x2junction"}
|
|
|
|
|
|
|
|
for _, trunk_type in ipairs(trunk_types)
|
|
|
|
do
|
|
|
|
local texture_basename = modname.."_"..basename.."_trunk_"..trunk_type.."_"
|
|
|
|
local subtype_tiles = {
|
|
|
|
terminal = {
|
2023-03-18 21:48:40 +00:00
|
|
|
texture_basename.."top.png",
|
2023-03-18 20:52:22 +00:00
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."terminal.png"
|
|
|
|
},
|
|
|
|
straight = {
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."normal.png"
|
|
|
|
},
|
|
|
|
corner = {
|
|
|
|
texture_basename.."normal.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."corner.png^[transformFX",
|
|
|
|
texture_basename.."corner.png",
|
|
|
|
texture_basename.."normal.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
},
|
|
|
|
tjunction = {
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."tjunction.png^[transformFX",
|
|
|
|
texture_basename.."tjunction.png",
|
|
|
|
texture_basename.."normal.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
},
|
|
|
|
t2junction = {
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."tjunction.png^[transformFX",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."tjunction.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
},
|
|
|
|
xjunction = {
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."xjunction.png^[transformFX",
|
|
|
|
texture_basename.."xjunction.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
},
|
|
|
|
xtjunction = {
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."xjunction.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
texture_basename.."slice.png",
|
|
|
|
},
|
|
|
|
x2junction = {
|
|
|
|
texture_basename.."slice.png"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, trunk_subtype in ipairs(trunk_subtypes)
|
|
|
|
do
|
2023-03-18 21:48:40 +00:00
|
|
|
local nodespec = {
|
2023-03-18 20:52:22 +00:00
|
|
|
description = S(data.description.." "..trunk_type.." "..trunk_subtype),
|
|
|
|
groups = trunk_groups,
|
|
|
|
tiles = subtype_tiles[trunk_subtype],
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
is_ground_content = false,
|
|
|
|
on_place = minetest.rotate_node,
|
|
|
|
on_construct = growth_timer
|
2023-03-18 21:48:40 +00:00
|
|
|
}
|
|
|
|
if trunk_type == "growing"
|
|
|
|
then
|
2023-03-19 21:47:19 +00:00
|
|
|
nodespec.on_timer = ebiometrees.tree_grower(
|
|
|
|
modname..":"..basename.."_leaves",
|
|
|
|
{
|
|
|
|
{ebiometrees.directions.up},
|
|
|
|
{
|
|
|
|
ebiometrees.directions.north,
|
|
|
|
ebiometrees.directions.east,
|
|
|
|
ebiometrees.directions.south,
|
|
|
|
ebiometrees.directions.west
|
|
|
|
}
|
|
|
|
},
|
|
|
|
modname..":"..basename.."_trunk_growing_terminal",
|
|
|
|
modname..":"..basename.."_trunk_normal_"..trunk_subtype,
|
2023-05-10 23:39:08 +00:00
|
|
|
20,
|
|
|
|
10
|
2023-03-19 21:47:19 +00:00
|
|
|
)
|
2023-03-18 21:48:40 +00:00
|
|
|
end
|
|
|
|
minetest.register_node(
|
|
|
|
modname..":"..basename.."_trunk_"..trunk_type.."_"..trunk_subtype,
|
|
|
|
nodespec)
|
2023-03-18 20:52:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|