A hacky extension to Fabric Loom that adds support for generating data at build time.
Example mod at goodasintended/fabric-datagen-example-mod
- Add badasintended maven repository to
settings.gradlepluginManagement { repositories { maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' } ++ maven { ++ name = 'badasintended' ++ url = 'https://maven.bai.lol/' ++ } gradlePluginPortal() } } - Add fabric-datagen into the plugins block on your
build.gradleplugins { id 'fabric-loom' version '0.9-SNAPSHOT' ++ id 'lol.bai.fabric-datagen' version '0.3.+' id 'maven-publish' } - On
datagensource set, create a class that implementsDataInitializer, install your providers therepublic class ExampleData implements DataInitializer { @Override public void onInitializeData(DataGenerator generator, GeneratorOptions options) { generator.install(new BlockTagsProvider(generator)); } }
- Create a
fabric.mod.jsonin thedatagensource set, add your class tobai:datagenentrypoint{ "schemaVersion": 1, "id" : "example-data", "version" : "1", "entrypoints" : { "bai:datagen": ["com.example.data.ExampleData"] } } - Add your data mod id to the
datagenblock on yourbuild.gradledatagen { mods("example-data") }
- Run
runDatagradle task - Build your mod jar
Most of the time you don't really need to include the generated files to the git history,
so you can add it to the .gitignore file.
src/generated/But, if you want to include those files, I recommend only ignoring the cache folder instead.
src/generated/resources/.cache/You can specify the source set used and the output directory to your liking.
To do that, add a datagen block to your build.gradle.
datagen {
sourceSet = sourceSets.main
output = file('src/main/resources')
}Though keep in mind that you need to add the main classpath if you use custom source set, also the output won't be automatically included in the jar.