Keep forgetting to ./gradlew runDatagen before starting the game? What to dynamically generate resources based on what others mods are installed? Want other mods to be able to mixin into your data generation? (maybe ignore that last one)
Runtime Datagen allows mods to run their data generators at runtime.
The Basics
Create a class that implements RuntimeDatagenEntrypoint. This will be the trutils:datagen entrypoint for your mod.
public class ExampleDatagenEntrypoint implements RuntimeDatagenEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator generator) {
FabricDataGenerator.Pack pack = generator.createPack();
// Do your datagen stuff here, as normal.
}
}2
3
4
5
6
7
In your fabric.mod.json:
{
[...]
"entrypoints": {
"trutils:datagen": ["com.example.ExampleDatagenEntrypoint"]
}
[...]
}2
3
4
5
6
7
If you did everything correctly, you should see a new .runtime-datagen folder appear in your run directory. This is where the generated stuff will show up.
Migrating From Fabric Datagen
Remove everything in your
build.gradlerelated to data generation. You (probably) won't need it.In your data generation entrypoint, replace
implements DataGeneratorEntrypointwithimplements RuntimeDatagenEntrypoint.javapublic class ExampleDatagenEntrypoint implements DataGeneratorEntrypoint public class ExampleDatagenEntrypoint implements RuntimeDatagenEntrypoint1
2In your
fabric.mod.json, replacefabric-datagenwithtrutils:datagen.json"entrypoints": { "fabric-datagen": ["com.example.ExampleDatagenEntrypoint"] "trutils:datagen": ["com.example.ExampleDatagenEntrypoint"] }1
2
3
4Run the game and make sure everything works.
Strict Validation
By default, Fabric makes your life harder by enabling something called strict validation. It ensures that "all entries have data generated for them".
But what if you want to only generate data for certain entries? Thanks to me, you can disable this.
In your RuntimeDatagenEntrypoint class:
@Override
public boolean strictValidation() {
return false;
}2
3
4