Skip to content

Tree Packs

supermassimo edited this page Apr 6, 2023 · 14 revisions

Tree packs are a new feature of Dynamic Trees for 1.16 and onwards, allowing mod pack developers and the average user to add their own custom content like trees and species with just a set of Json files, as well as allowing add-on developers to add their content in the same way.

Tree packs work much like Vanilla's resource and data packs, but are both loaded on the initial game launch and reloaded when data packs are (on world load and when the /reload command is executed). Below is the basis of the file structure:

trees/
  [namespace]/
    families/
    fruits/
    jo_codes/
    leaves_properties/
    pods/
    soil_properties/
    species/
    world_gen/

A trees folder can be found in the Minecraft directory (subject to change), which is where the user/mod pack developer can create their custom entries. The namespace will be used for any entries (such as species) registered in sub-folders. This works exactly like it does in vanilla - for example, a Minecraft grass block has the registry name minecraft:grass_block - the minecraft part is the namespace. Therefore in dynamic trees an oak species will have the registry name dynamictrees:oak. Note that for mods this is also referred to as the mod ID.

DT will generate any blocks and items needed automatically and according to the configurations set. For example, a family will generate a branch block by default with registry name namespace:family_branch. When this happens, it will use need a registry handler. Only DT itself and add-on mods will have registry handlers, so if a namespace is used that doesn't have a registry handler - like minecraft - it will autocorrect the block and item registry names to dynamictrees by default. For this reason, it is recommended that tree packs exclusively use either dynamictrees as the namespace or the mod ID of an add-on that is known to be loaded/required. This is so that the species, family, and leaves properties registry names match the registry names of their equivalent blocks and items.

So, in short, you should generally only use dynamictrees as the namespace, or one of the add-on mod IDs if the tree pack is related to a specific add-on.

For guides on how to add leaves properties, families, etc, refer to the relevant guide on the side-bar.

Add-ons

Add-ons can also use tree packs to define their custom entries fully using Json, and can also extend Json capabilities.

Setting up a new add-on

The following shows you how to start a new add-on project from scratch. If you'd prefer, you can use the template instead.

To start creating an add-on, you first need the basic Forge MDK from their downloads page. Follow the usual setup process.

Selecting a mod ID

For mods that aim to purely add DT support to another mod, it is conventional (in 1.16+) for mod IDs to be structured in the format dt<modid>, in which the modid is the mod ID for the mod the add-on adds support to.

Adding DT to the dev environment

To add DT to the dev environment, you first need to add Harley's maven repository by adding the following to the repositories block.

For Groovy build scripts [build.gradle]
maven {
    url 'https://harleyoconnor.com/maven'
}
For Kotlin build scripts [build.gradle.kts]
maven("https://harleyoconnor.com/maven")

Next, you need to add DT to the dependencies block under the implementation configuration, such as below:

For Groovy build scripts [build.gradle]
implementation fg.deobf("com.ferreusveritas.dynamictrees:DynamicTrees-<mc version>:<dt version>")
For Kotlin build scripts [build.gradle.kts]
implementation(fg.deobf("com.ferreusveritas.dynamictrees:DynamicTrees-<mc version>:<dt version>"))

Replace <mc_version> with the desired MC version, and <dt version> with the desired DT version (generally the latest, which is currently 0.10.0-Beta25).

Finally, refresh the Gradle project.

Adding DT as an FML dependency

Next, you will need to tell Forge that your mod depends on Dynamic Trees. This can be done by adding this to the bottom of the mods.toml:

[[dependencies.<modid>]]
    modId="dynamictrees"
    mandatory=true
    versionRange="[0.10.0,)"
    ordering="AFTER"
    side="BOTH"

Note that you may like to update the version range as appropriate, ideally to a minimum of the same one you are using in development.

Now your project should be ready, but make sure to see the 'using tree packs' section if you plan on using tree packs.

Template

There is a simple template you can use here which has much of the above setup done for you along with a few extras like issue templates and CI. To use it, follow the instructions on its README.

Note that in the template the RegistryHandler setup line mentioned below is already added.

Using tree packs

When creating an add-on, tree packs are loaded automatically from the trees directory inside the resources directory.

However, in order to be able to use your mod ID for DT to register blocks and items, you will need to add the following code to your mod constructor, in which modid is your mod's ID, to setup a new RegistryHandler:

RegistryHandler.setup("modid");

After this point you can use your mod ID as the namespace under the trees folder. Everything works like it does in a tree pack, using the same file structure as detailed above.