Skip to content
Config Support

Config Support

PklConfig evaluates PKL files directly into typed Kotlin (or Java) objects via kotlinx.serialization. Your datapacks are already PKL, so your configs can be too.

One-shot load

@Serializable
data class MyConfig(val tickRate: Int, val enabled: Boolean)

val config = PklConfig.load<MyConfig>(
    FMLPaths.CONFIGDIR.get().resolve("mymod/config.pkl")
)

PklConfig.loadText<T>(source) does the same from an in-memory PKL string.

The matching config file:

config.pkl
tickRate = 20
enabled = true

output { renderer = new JsonRenderer {} }

Amending a schema you ship in your jar is nicer: users get autocomplete and the output block comes from the schema.

Auto-reload with register

register calls your callback immediately with the current value, and again on every reload. No manual reload wiring:

PklConfig.register<MyConfig>(configPath) { cfg ->
    tickRate = cfg.tickRate
    enabled = cfg.enabled
}

Reloads are mtime-checked. If the file hasn’t changed, the callback isn’t re-run.

Notes

  • Deserialization ignores unknown keys and is lenient. Adding fields to the PKL file before the code ships is safe.
  • Evaluation errors throw at load time. Decide yourself whether to fall back to defaults or hard-fail.
  • Java works too: any type kotlinx.serialization can deserialize.