Skip to content

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 evaluatedbuild timegame runtime
Output ships asplain JSON in your jarevaluated live, reloadable
pkl4mc required at runtimeno, output is JSONyes
Formod devspack devs, live iteration

Failures during datagen are logged per file and don’t abort the run. Check the log for PKL datagen failed.