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.gradle
pluginManagement { 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.gradle
plugins { id 'fabric-loom' version '0.9-SNAPSHOT' ++ id 'lol.bai.fabric-datagen' version '0.3.+' id 'maven-publish' }
- On
datagen
source 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.json
in thedatagen
source set, add your class tobai:datagen
entrypoint{ "schemaVersion": 1, "id" : "example-data", "version" : "1", "entrypoints" : { "bai:datagen": ["com.example.data.ExampleData"] } }
- Add your data mod id to the
datagen
block on yourbuild.gradle
datagen { mods("example-data") }
- Run
runData
gradle 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.