lib_trees is a mcfunction library that facilites the creation of custom trees. This library handles many of the functions required for growing custom trees from saplings: sapling placement and breaking, tree growth via saplings, and sapling drops from specific leaves.
The example data pack has everything required to use this library (except for full lantern load implementation). This document will refer to the example pack for specific details.
This library does not handle generation of trees via worldgen, but information of how to generate trees to be used in conjunction of this library will be outlined below.
Trees will need to be defined using custom structures. It is technically possible to use configured features (how normal trees generate), but the sapling drops become more complex. This will only outline the process using structures. Refer to the worldgen
, tags
, and structures
folder of the example pack to set up custom structures.
The most important thing for custom trees to be usable with this data pack is to add leaf markers to your trees. Leaf markers must be created with the gm4_tree_leaf
tag and an additional identifier tag:
summon marker ~ ~ ~ {Tags:["gm4_tree_leaf","LEAF_IDENTIFIER_TAG"]}
Markers can be placed in a few ways; this document will outline the 3 most reasonable ways.
When a leaf marker is no longer in a leaf block, it will run the #gm4_trees:destroy_leaf
function tag at the location of the leaf marker. The function tag should call a verification function to check if the marker was a custom marker from your data pack:
execute if entity @s[tag=LEAF_IDENTIFIER_TAG] run function ...
That should run a function that drops a sapling and kills the marker (@s
). The easiest way to drop saplings is to use a loot table to drop a custom sapling upon a specific chance, as shown in the example pack:
loot spawn ~ ~ ~ loot ...
kill @s
Custom sapling items need some specific data so this library knows it's a custom sapling and should be tracked when placed. You can use a command like below, or a loot table, like in the example pack. A loot table is recommended since it's more versatile.
# any sapling type can be used
give @s oak_sapling{gm4_trees:{item:{id:"sapling",type:"IDENTIFIER"}}}
When these custom saplings are placed, the library will find the placed sapling and run the #gm4_trees:initialize_sapling
function tag at the location of the sapling. The function tag should call a verification function to check if the sapling was a custom sapling from your data pack:
execute if data storage gm4_trees:temp sapling{type:"IDENTIFIER"} run function ...
That should run a function that summons a marker with the gm4_tree_sapling
tag and an additional identifier tag, and then sets its gm4_sap_growth
score to a positive number. This score increases every time the sapling increases its Age
block state. Vanilla saplings have 2 growth stages until they grow into a tree.
# this marker must be spawned at the center of the block (which is where it's run from)
summon marker ~ ~ ~ {Tags:["gm4_tree_sapling","SAPLING_ID_TAG"]}
# set stage requirement (higher = longer to grow)
scoreboard players set @e[type=marker,tag=SAPLING_ID_TAG,distance=..0.1] gm4_sap_growth 2
When a custom sapling is broken, the #gm4_trees:destroy_sapling
function tag is run from the sapling marker. The function tag should call a verification function to check if the sapling marker was a custom sapling from your data pack:
execute if entity @s[tag=SAPLING_ID_TAG] run function ...
That should run a function that replaces the normal item with the custom sapling item:
# any sapling type can be used (as long as it matches the custom item)
kill @e[type=item,nbt={Age:0s,Item:{id:"minecraft:oak_sapling",count:1}},nbt=!{Item:{components:{}}},limit=1,dx=0]
loot spawn ~ ~ ~ loot gm4_trees_example:items/apple_tree_sapling
Custom saplings can be grown like vanilla saplings. The growth is based on the block state of the sapling, so bonemeal can be used like normal. When the age reaches the sapling marker's gm4_sap_growth
score, it will generate a tree. When this happens, the #gm4_trees:generate_tree
function tag will run at the location of the sapling marker. The function tag should call a verification function to check if the sapling was a custom sapling from your data pack:
execute if entity @s[tag=SAPLING_ID_TAG] run function ...
That should run a function that generates the tree using /place jigsaw
then kills the marker (@s
):
# generate tree using custom structure
place jigsaw gm4_trees_example:apple_trees gm4_trees:trunk 6 ~ ~1 ~
kill @s
This library, and the contents of the lib_trees
directory on the [github repository](https://github.com/Gamemode4Dev/GM4_data packs), is licensed under the MIT License.
Copyright © 2024 Smithed
Not an official Minecraft product. Not approved by or associated with Mojang Studios