Datagen
PklDataProvider runs PKL through vanilla datagen for mods that prefer baking resources into the jar at build time. It walks data/**/*.pkl in your input resources, evaluates each file, and writes the JSON to the datagen output mirroring the path (.pkl to .json).
@SubscribeEvent
fun onGatherData(event: GatherDataEvent) {
event.generator.addProvider(
event.includeServer(),
PklDataProvider(event.generator.packOutput, event.inputs)
)
}Author src/main/resources/data/mymod/recipes/steel.pkl:
src/main/resources/data/mymod/recipes/steel.pkl
import "pklmc:recipe.pkl" as recipe
local r: recipe.ShapedRecipe = new {
// ...
}
output { renderer = new JsonRenderer {}; value = r }Run ./gradlew runData and steel.json lands in generated/ like any other datagen output.
Datagen vs virtual datapack
Datagen (PklDataProvider) | Virtual datapack (config/pkl4mc/) | |
|---|---|---|
| When evaluated | build time | game runtime |
| Output ships as | plain JSON in your jar | evaluated live, reloadable |
| pkl4mc required at runtime | no, output is JSON | yes |
| For | mod devs | pack devs, live iteration |
Failures during datagen are logged per file and don’t abort the run. Check the log for PKL datagen failed.