Frostdev

KilnAPI reference Guide

Declared registries: a registry of your own (0.2.0-dev.32, experimental, KILNX031)

A mod can declare a registry of its own, and Kiln declares its own data the same way. A declared registry has the tools of the game's registries: Kiln ids, fields with types, ranges and ops, layers in load order, exclusive and yield, Conflicts in kiln/state/registry.json, data packs' "registry" sections and C# OnRegistry. Nothing changes for a mod that declares none.

Declaring one

Put a file registries/<name>.json in your mod folder (Kiln.Sdk copies the folder with the mod). Its format is a registry schema (schema/registry-declared.schema.json): registrySchema 1, the same field kinds as schema/registry/*.json (int, float, bool, enum, flags, ref, time, struct, list), plus:

Member Meaning
registry "<your mod id>:<name>"; <name> is the file's name, lower camel case
declaredBy your mod id
backend kiln (default): Kiln holds the values, no game memory. binder: your code gives the entries' values (Registries.SetDeclaredEntries, native kiln.registry.declared entries) and takes the resolved ones back
entries the registry's own entries: "<kiln id>": {"<field>": value, "<struct>": {"<leaf>": value}, "_traits": [...]}
applies the default applies of every field without its own
a field's default the value of an entry that gives none (an entry another mod adds, a binder's entry without it)
entry {"add": true, "remove": false} by default: other mods may add entries under their own ids, nobody removes one
a field's joinedClient when a joined Kiln client consumes an edit (now, worldLoad, restart, serverOnly, localOnly); left out it counts as serverOnly (kiln lint's KL213 says so in its advice). Kiln's own schemas give it on every field

raw is always refused (a declared registry has no game paths). Kiln names only: no game type names or offsets in docs. In C#, Registries.Declare(schemaJson) in OnLoad declares the same way (before the stage). Kiln checks a declaration when kiln.content starts, as registrygen checks a schema; a refused one is named in kiln.log with every reason.

{
  "registrySchema": 1, "registry": "workshop-sample:workshops", "declaredBy": "workshop-sample", "version": "0.1.0",
  "doc": "The sample's workshops.", "applies": "now",
  "fields": {
    "speed": {"type": "float", "min": 0.1, "max": 100, "ops": "number", "default": 1},
    "slots": {"type": "int", "min": 1, "max": 16, "ops": "number", "default": 2}
  },
  "entries": {"workshop-sample:sawmill": {"speed": 1.5}, "workshop-sample:anvil": {"speed": 0.8, "slots": 1}}
}

The sample is mods/samples/WorkshopRegistry; mods/tests/declared-edit-test edits it.

Editing one (any mod)

Exactly as a game registry: name it in a data pack's "registry" section, or reach it in OnRegistry at GameStart with stage.Entries("<mod>:<name>") (RegistryEntry by Kiln path, the same typed checks).

{"registry": {"alter": [{"registry": "workshop-sample:workshops", "select": {"id": "workshop-sample:sawmill"}, "field": "speed", "op": {"mul": 2}}]}}

Relative edits stack in load order, a later absolute edit wins and is reported, exclusive refuses a later edit of the same field, and registry.json's field rows and conflict lines name every writer. After the stage, a live change of a declared registry goes through Registries.ChangeDeclared (it stays your layer until RevertDeclared or your mod's unload); Registries.Change and the later entry points of OnRegistry refuse declared registries, and so does kiln.registry.live (its refusal names kiln.registry.declared change). RevertDeclared takes back only your own change.

Reading one

Registries.Declared("<mod>:<name>") gives a snapshot of the resolved values (Get<T>(id, field)), WatchDeclared calls your handler on your mod's tick at the stage's end and whenever the values change. Kiln.Sdk generates a typed form from your registries/*.json: a class <TypeName>Registry (its Current holds the resolved values; an entry by id has one property per field, cost.fuel is CostFuel; namespace <RootNamespace>.Registries; warning KILN040 names a file it has no typed form for). Native: kiln.registry.declared resolved_json, read, subscribe; kiln.registry's read and select take a declared registry's name too.

Kiln's own declared registries

Registry What Edit
kiln:rarityRolls the rarity roll blocks' rules (<mod>:<rule>): which creations roll and the five weights sources, weights.*
kiln:lootTables the loot table blocks (<mod>:<table>): rolls, pick, each stack's counts, chance and weight rolls, pick, entries[i].*
kiln:stationMenus mods' own workshops' crafting-menu layouts (<mod>:<key>): a recipe's tab and set, a tab's icon placement[i].tab/set, tabs[i].icon
kiln:playerRules the named rule sets (kiln:creative, server:<file>, <mod>:<preset>) every one-value rule
kiln:modValues the mod values mods define (<owner>:<id>) read-only: a definition is its mod's contract with saved values
kiln:gemSockets gem sockets on gear besides weapons (one entry, kiln:sockets): per kind (rings, armour, shields, otherGear) whether it may hold a gem and the chance a new item rolls an empty socket; the defaults allow nothing and roll nothing (since 0.2.0-dev.32, G11b) <kind>.allowed, <kind>.rollChance
kiln:itemCosts, kiln:toolFamilies, kiln:clearance costs Kiln's features charge, tool families, pets' measured clearance read-only; declared, not fed yet in this release

Their schemas are schema/registry/kiln/*.json. Kiln's services are their binders: a block's or a layout's own values are the base, every mod's edits compose on top, and the service takes the result (kiln.log names what it changed: "rarity rolls: kiln:rarityRolls gives ...", "blocks: kiln:lootTables gives ...", "registry: kiln:stationMenus moves layout ...").

Limits

512 fields and 65,536 entries per declared registry, 256 declared registries per process, 64 files per mod, 1 MiB per declaration, 16 MiB per entries document, 32 levels of nesting. Kiln holds at most 1,048,576 values of one declared registry (every entry's fields with their defaults, a list's elements one each): a declaration's or a binder's entries past that are refused, and entries other mods add past it are left out (kiln.log and registry.json's declared rows say how many). A mod holds at most 256 live changes at once (revert one first), and every mod's together at most 64 MiB of IR. A declaration whose ref names a registry nobody declares is left out of the stage, and kiln.log says so. A changed declaration takes effect at the next start. A binder's entries given after the stage recompose the registry with the stage's edits and the live changes; an edit refused at the stage because the binder's entry was not there yet applies once the entry comes, and registry.json then shows it applied (its field row and writer; the stage's refusal of it goes).

Enshrouded is a trademark of Keen Games GmbH. Kiln is unofficial.