trees_lib
This mod/lib is not yet finished. It is a work in progress, and some feedback would be welcome.
Trees are very popular elements in Minetest-like games, and modders frequently want to add some trees. People even ask for advice here on the forum as to how to create new types. There are multiple ways to do so. And it is a pain to keep track of all trees out there when trying to maintain compatibility with them from withhin other mods (villages, tree cutting tools, letting trunks grow through leaves, new nodes for all wood types, ...).
For the sake of this mod/library, a tree is a structure that can be cut down for renewable ressources; it provides saplings of some kind which allow to reproduce either the exact same structure or a very similar one.
The api of the trees_lib ought to contain the following:
1. Easy way to add new tree types.
2. A function that allows to react to new tree types beeing registered (i.e. for adding furniture for the new wood it comes with).
3. A function that allows to react to a tree growing at a certain position (i.e. for putting a lumberjack hut or mob next to it).
4. Functions that determine weather or not a tree can/will grow at a certain position. This may go so far as to change how the tree will grow/look like.
5. Trees failing to grow won't trigger further abm calls; they just mutate into dry shrub, thus turning dry shrub into a renewable ressource.
6. The same way of growing (i.e. a function or schematic) can be used for multiple tree types (good for fruit trees).
7. Tree-related nodes (trunk, wood, leaves, further leaves and fruits) can be registered automaticly if the nodes don't exist yet. Advantage: Just change one function if you want your leaves to be climbable, your trunks round or whatever - instead of having to hunt down each tree mod.
All other things tree-related (leafdecay) also ought to be part of it. But not the initial placement of the trees at mapgen time - because that's really too dependant on the mapgen and not the job of this lib.
Registering a tree will require information about the nodes the tree ought to consist of, an (optional) list of node types on which it grows, an (optional) function that is called whenever a sapling wants to grow (it can deny tree growth, change how the tree grows or just allow it), and an (optional) function that chooses how the tree ought to grow.
Methods of growing a tree are either a function (that's how the old trees/apple trees in mapgen v6 grew), a schematic (that's how they grow now) or a table containing the information for L-system tree growth.
The current implementation already contains a "silly" tree as an example (use "/giveme trees_lib:silly_sapling"). It will randomly grow like a normal apple tree, like an acacia from the same schematic, or like a beech from moretrees.
The mod in its current form can be found at https://github.com/Sokomine/trees_lib.
I'm not yet satisfied with my implementation, and it's not finished yet. But I do think that we need a common tree lib. Right now, I do need to keep a copy of an old version of minetest_game/mods/default/trees.lua in mg_villages just to be able to place trees around villages. That can't go on indefinitely as cut&paste really is not a good idea regarding maintenance. And more and more diffrent tree types keep showing up.
Trees are very popular elements in Minetest-like games, and modders frequently want to add some trees. People even ask for advice here on the forum as to how to create new types. There are multiple ways to do so. And it is a pain to keep track of all trees out there when trying to maintain compatibility with them from withhin other mods (villages, tree cutting tools, letting trunks grow through leaves, new nodes for all wood types, ...).
For the sake of this mod/library, a tree is a structure that can be cut down for renewable ressources; it provides saplings of some kind which allow to reproduce either the exact same structure or a very similar one.
The api of the trees_lib ought to contain the following:
1. Easy way to add new tree types.
2. A function that allows to react to new tree types beeing registered (i.e. for adding furniture for the new wood it comes with).
3. A function that allows to react to a tree growing at a certain position (i.e. for putting a lumberjack hut or mob next to it).
4. Functions that determine weather or not a tree can/will grow at a certain position. This may go so far as to change how the tree will grow/look like.
5. Trees failing to grow won't trigger further abm calls; they just mutate into dry shrub, thus turning dry shrub into a renewable ressource.
6. The same way of growing (i.e. a function or schematic) can be used for multiple tree types (good for fruit trees).
7. Tree-related nodes (trunk, wood, leaves, further leaves and fruits) can be registered automaticly if the nodes don't exist yet. Advantage: Just change one function if you want your leaves to be climbable, your trunks round or whatever - instead of having to hunt down each tree mod.
All other things tree-related (leafdecay) also ought to be part of it. But not the initial placement of the trees at mapgen time - because that's really too dependant on the mapgen and not the job of this lib.
Registering a tree will require information about the nodes the tree ought to consist of, an (optional) list of node types on which it grows, an (optional) function that is called whenever a sapling wants to grow (it can deny tree growth, change how the tree grows or just allow it), and an (optional) function that chooses how the tree ought to grow.
Methods of growing a tree are either a function (that's how the old trees/apple trees in mapgen v6 grew), a schematic (that's how they grow now) or a table containing the information for L-system tree growth.
The current implementation already contains a "silly" tree as an example (use "/giveme trees_lib:silly_sapling"). It will randomly grow like a normal apple tree, like an acacia from the same schematic, or like a beech from moretrees.
The mod in its current form can be found at https://github.com/Sokomine/trees_lib.
I'm not yet satisfied with my implementation, and it's not finished yet. But I do think that we need a common tree lib. Right now, I do need to keep a copy of an old version of minetest_game/mods/default/trees.lua in mg_villages just to be able to place trees around villages. That can't go on indefinitely as cut&paste really is not a good idea regarding maintenance. And more and more diffrent tree types keep showing up.