🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.21
This page is written for version:
1.21
Data generation (or datagen) is an API for programmatically generating recipes, advancements, tags, item models, language files, loot tables, and basically anything JSON-based.
The easiest way to enable datagen is at project creation. Check the "Enable Data Generation" box when using the template generator.
TIP
If datagen is enabled, you should have a "Data Generation" run configuration and a runDatagen
Gradle task.
First, we need to enable datagen in the build.gradle
file.
fabricApi {
configureDataGeneration() {
client = true
}
}
Next, we need an entrypoint class. This is where our datagen starts. Place this somewhere in the client
package - this example places it at src/client/java/com/example/docs/datagen/FabricDocsReferenceDataGenerator.java
.
public class FabricDocsReferenceDataGenerator implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
}
}
Finally, we need to tell Fabric about the entrypoint in our fabric.mod.json
:
{
// ...
"entrypoints": {
// ...
"client": [
// ...
],
"fabric-datagen": [
"com.exmaple.docs.datagen.FabricDocsReferenceDataGenerator"
]
}
}
WARNING
Don't forget to add a comma (,
) after the previous entrypoint block!
Close and reopen IntelliJ to create a run configuration for datagen.
Inside your datagen entrypoint's onInitializeDataGenerator
method, we need to create a Pack
. Later, you'll add providers, which put generated data into this Pack
.
FabricDataGenerator.Pack pack = fabricDataGenerator.createPack();
To run datagen, use the run configuration in your IDE, or run ./gradlew runDatagen
in the console. The generated files will be created in src/main/generated
.
Now that datagen is set up, we need to add providers. These are what generate the data to add to your Pack
. The following pages outline how to do this.