e20268de06
* refactored tree registration * renamed textures so they can be used in loops
129 lines
4.2 KiB
Lua
129 lines
4.2 KiB
Lua
local function growth_timer(pos)
|
|
minetest.get_node_timer(pos):start(3)
|
|
end
|
|
|
|
|
|
local S = minetest.get_translator("ebiometrees")
|
|
function ebiometrees.register_tree(modname, basename, data)
|
|
-- register saplings
|
|
local sapling_name = modname..":"..basename.."_sapling"
|
|
local sprout_name = modname..":"..basename.."_sprout"
|
|
|
|
local sapling_groups = table.copy(data.groups)
|
|
local sprout_groups = table.copy(data.groups)
|
|
sapling_groups.sapling = 1
|
|
sapling_groups.snappy = 2
|
|
sapling_groups.dig_immediate = 3
|
|
sprout_groups.sapling = 1
|
|
sprout_groups.snappy = 2
|
|
minetest.register_node(sapling_name, {
|
|
description = S(data.description.." sapling"),
|
|
drawtype = "plantlike",
|
|
tiles = { modname.."_"..basename.."_sapling.png"},
|
|
paramtype = "light",
|
|
on_timer = ebiometrees.get_sapling_grower(sprout_name),
|
|
sunlight_propagates = true,
|
|
walkable = false,
|
|
groups = sapling_groups,
|
|
on_construct = growth_timer
|
|
})
|
|
minetest.register_node(sprout_name, {
|
|
description = S(data.description.." sprout"),
|
|
drawtype = "plantlike",
|
|
visual_scale = 1.4,
|
|
tiles = { modname.."_"..basename.."_sprout.png" },
|
|
paramtype = "light",
|
|
sunlight_propagates = true,
|
|
walkable = false,
|
|
on_timer = ebiometrees.get_sprout_grower(
|
|
modname..":"..basename.."_trunk_growing_straight",
|
|
modname..":"..basename.."_trunk_growing_terminal"),
|
|
groups = sprout_groups,
|
|
on_construct = growth_timer
|
|
})
|
|
-- registers tree and corresponding nodes
|
|
local trunk_groups = table.copy(data.groups)
|
|
trunk_groups.choppy = 2 -- TODO: customizations
|
|
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 = {
|
|
texture_basename.."terminal.png",
|
|
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
|
|
minetest.register_node(
|
|
modname..":"..basename.."_trunk_"..trunk_type.."_"..trunk_subtype, {
|
|
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_timer = function(pos)
|
|
return true
|
|
end,
|
|
on_construct = growth_timer
|
|
})
|
|
end
|
|
end
|
|
end
|
|
|