Frostdev

KilnAPI reference Guide

The creatures registry

Every creature the game defines: enemies, wildlife, farm animals and villagers: their level, faction, size, health and damage scaling, resistances, speeds, random loot, the enemy's sight, and a wild animal's taming (tameable, steps, favourite bait). An edit is global: every creature of the entry, now or later, as the field says.

Schema version 0.1.2, experimental (KILNX031: may change in any release until it is marked stable). C# entry type Kiln.Registry.CreatureEntry. What registries are, the stages, the conflict rules and how ids are made: README.

Edits per call: 4,096. One OnRegistry callback (one phase of one entry point) or one Registries.Change takes at most this many edits of this registry; a call with more is refused whole, with the reason in kiln.log and registry.json, and nothing of it applies (the other calls do). The default for a registry whose schema declares none (4,096).

Ids

  • Game entries: game:<the creature's stable name>. Mod entries: <mod id>:<name>. All ids are lower case. The mod ids game and kiln are reserved: no mod's entries use them.
  • A creature has the id of its template: the template's debug name in lower case (Enemy_Vukah_Melee is game:enemy_vukah_melee). A template without a name is game:template_<first 8 hex digits of its GUID>. When two templates would get the same name, the one that held it first keeps it and the other is game:~<first 8 hex digits of its GUID>. The entries are the templates with an enemy's, a wild animal's, a farm animal's or a villager's behaviour; the same id names the template in every registry.
  • Names: DisplayName (never empty; display names) is the name of the creature's template as TemplateInfo.DisplayName gives it: Kiln's creature catalog, else one made from the template's debug name. An id no template has is made readable from the id.

Fields

Applies: now = takes effect at the next use; worldLoad = takes effect when a world loads; restart = takes effect after a game restart. Ops: number = a value or the relative operations (mul, add, min, max, raiseOnly, lowerOnly); set = a value; list = clear, append, remove, replace; indexed = a list of fixed length, edited one element at a time (xpPerLevel[2]) with a value or a number operation. A field of a list's elements is named with [] in this table and with the element's index in an edit (entries[3].chance, or [*] for every element). Mapping: whether this Kiln maps the field onto the game; an unproven or unmapped field is refused per entry, with the reason, until a Kiln update maps it. Joined client: when a joined Kiln client consumes a server edit; see README.

Groups of fields:

  • health: How the creature's health grows. Health itself comes from its level through the game's formulas.
  • damage: How hard the creature hits.
  • resist: How much of each kind of damage the creature takes: 1 = normal, 0 = immune, 2 = double. Creatures that spawn after the edit get it; creatures already in the world keep the value they spawned with.
  • speed: How fast the creature moves, in metres per second. Creatures that spawn after the edit get it; creatures already in the world keep the value they spawned with.
  • loot: The random loot a killed creature leaves. Creatures that spawn after the edit get it; creatures already in the world keep the value they spawned with.
  • loot.slots: How many random loot rolls a kill gives: a number from min to max.
  • sight: What an enemy sees. Read at once by every enemy of the entry, also those already in the world.
Field Type Applies Ops Since Mapping Joined client About
kind enum (enemy, wildlife, animal, villager) now read-only 0.1.0 mapped serverOnly What the creature is, by the behaviour it has: an enemy, a wild animal, a farm animal or pet, a villager.
level int 1..10000 now number 0.1.0 mapped serverOnly The level a creature spawns at when its spawner sets none (most spawners set their own). Creatures that spawn after the edit get it; creatures already in the world keep the value they spawned with.
levelMax int 1..10000 now number 0.1.0 mapped serverOnly The highest level the creature can have; a level above it is cut to it. Creatures that spawn after the edit get it; creatures already in the world keep the value they spawned with.
faction enum (environment, hitAll, fogger, vukah, scavenger, wildlife, wildBeast, player, automatedPlayer, hitOthers, skeleton, playerAlly, farmAnimal, cyclops, drak, ancients) now set 0.1.0 mapped serverOnly The side the creature fights for (playerAlly: on the players' side). Creatures that spawn after the edit get it; creatures already in the world keep the value they spawned with.
scale float 0.01..100 now number 0.1.0 mapped serverOnly The creature's size (1 = as made). Only a creature that has a size value of its own can take one. Creatures that spawn after the edit get it; creatures already in the world keep the value they spawned with.
xp float 0..1000 now number 0.1.0 mapped serverOnly The factor on the experience a kill gives (1 = as the game gives). Creatures that spawn after the edit get it; creatures already in the world keep the value they spawned with.
health.levelFactor float 0..1000 now number 0.1.0 mapped serverOnly The factor of the health a level adds (the game's level scaling). Read at the creature's next health update.
health.perPlayer float 0..100 now number 0.1.0 mapped serverOnly The health added per player nearby beyond the first, as a share (0.48 = 48 %). Read at the creature's next health update.
damage.multiplier float 0..1000 now number 0.1.0 mapped serverOnly The factor on all the damage the creature deals (1 = as made). Creatures that spawn after the edit get it; creatures already in the world keep the value they spawned with.
damage.perPlayer float 0..100 now number 0.1.0 mapped serverOnly The damage added per player nearby beyond the first, as a share (0.05 = 5 %). Read at the creature's next health update.
resist.physical float 0..100 now number 0.1.0 mapped serverOnly The share of physical damage as a whole the creature takes.
resist.cut float 0..100 now number 0.1.0 mapped serverOnly The share of cutting damage the creature takes.
resist.pierce float 0..100 now number 0.1.0 mapped serverOnly The share of piercing damage the creature takes.
resist.blunt float 0..100 now number 0.1.0 mapped serverOnly The share of blunt damage the creature takes.
resist.wood float 0..100 now number 0.1.0 mapped serverOnly The share of wood damage (tools) the creature takes.
resist.stone float 0..100 now number 0.1.0 mapped serverOnly The share of stone damage (tools) the creature takes.
resist.metal float 0..100 now number 0.1.0 mapped serverOnly The share of metal damage (tools) the creature takes.
resist.poison float 0..100 now number 0.1.0 mapped serverOnly The share of poison damage the creature takes.
resist.explosion float 0..100 now number 0.1.0 mapped serverOnly The share of explosion damage the creature takes.
resist.skillShot float 0..100 now number 0.1.0 mapped serverOnly The share of skill-shot hits (weak spots) the creature takes.
resist.fire float 0..100 now number 0.1.0 mapped serverOnly The share of fire damage the creature takes.
resist.shroud float 0..100 now number 0.1.0 mapped serverOnly The share of shroud damage the creature takes.
resist.ice float 0..100 now number 0.1.0 mapped serverOnly The share of ice damage the creature takes.
resist.lightning float 0..100 now number 0.1.0 mapped serverOnly The share of lightning damage the creature takes.
speed.sneak float m/s 0..1000 now number 0.1.0 mapped serverOnly Its speed when sneaking.
speed.walk float m/s 0..1000 now number 0.1.0 mapped serverOnly Its speed when walking.
speed.run float m/s 0..1000 now number 0.1.0 mapped serverOnly Its speed when running.
speed.sprint float m/s 0..1000 now number 0.1.0 mapped serverOnly Its speed when sprinting.
speed.combat float m/s 0..1000 now number 0.1.0 mapped serverOnly Its speed when moving in combat.
speed.patrol float m/s 0..1000 now number 0.1.0 mapped serverOnly Its speed when patrolling.
speed.flee float m/s 0..1000 now number 0.1.0 mapped serverOnly Its speed when fleeing.
loot.disabled bool now set 0.1.0 mapped serverOnly The creature leaves no random loot.
loot.slots.min int 0..255 now number 0.1.0 mapped serverOnly The fewest random loot rolls.
loot.slots.max int 0..255 now number 0.1.0 mapped serverOnly The most random loot rolls.
arsenal ref arsenals, optional now read-only 0.1.0 mapped serverOnly The enemy's arsenal: the attacks it chooses from (arsenals registry). Creatures of the same kind share one.
sight.range float m 0..10000 now number 0.1.0 mapped serverOnly How far the enemy sees a target by day, in metres (night shortens it by the game's night factor).
sight.engageRange float m 0..10000 now number 0.1.0 mapped serverOnly Within this distance, in metres, the enemy engages a target it sees at once.
sight.coneAngle float degrees 0..360 now number 0.1.2 mapped serverOnly Half the angle of the enemy's view cone, in degrees, to either side of where it looks (the game's own enemies go up to 360).
sight.nightFactor float 0..10 now number 0.1.2 mapped serverOnly How far the enemy sees at night, as a factor of its range.
sight.waterFactor float 0..10 now number 0.1.2 mapped serverOnly How far the enemy sees a target in water, as a factor of its range.
sight.knownTargetFactor float 0..100 now number 0.1.2 mapped serverOnly How far the enemy keeps seeing a target it already knows, as a factor of its range.
sight.engageRangeMoving float m 0..10000 now number 0.1.2 mapped serverOnly Within this distance, in metres, the enemy engages a moving target it sees at once (0: its combat distances and half a metre).
tameable bool now set 0.1.1 mapped serverOnly Whether the game lets the creature be tamed its own way: a wild animal whose template allows taming (a dog, a cat, a goat, a bunny, a catdeer, a turkey, a yak, a capybara, a sanddigger). Null for a creature that is no wild animal. Writable since dev.32 round 3: false makes a tameable animal untameable (the game stops sensing baits and never makes it a farm animal); true is accepted only where the template has the pet interaction sequence (and the farm-animal component) the game's taming needs, which on this game build are exactly the animals that are tameable already; elsewhere it is refused: the game cannot tame it.
tamingSteps int 1..255 now number 0.1.1 mapped serverOnly How many of the game's taming steps (a petting while the animal eats its favourite bait) tame a tameable wild animal into a farm animal. Read at once by every animal of the entry, also those already in the world (the game keeps it in the template only); an animal whose progress already reaches the new number is tamed at its next update. Null for a creature that is no wild animal.
favoriteBait ref templates, optional now set 0.1.1 mapped serverOnly The bait a tameable wild animal eats (the template its bait item places, game:foodbait_t2_dog for a dog); none for an animal with no favourite bait. Writable since dev.32 round 3, at once for every animal of the entry: another bait template (game:foodbait_* or a mod's own); an id that is no bait is refused.

Traits

Selectors ask for these with has / hasNot.

Trait Means
enemy an enemy (kind enemy)
wildlife a wild animal (kind wildlife)
animal a farm animal or pet (kind animal)
villager a villager or workshop NPC (kind villager)

Components

Each entry is a template, so a selector's has / hasNot also name the components its template holds or lacks, as component:<kind> with the kind's Kiln name from the template view (views): "has": ["component:inventoryCraftingStock"]. A kind no template holds selects nothing (since 0.2.0-dev.32.1).

Entries

  • Add (stage add, id <your mod id>:<name>): yes. GameStart only. A copy of a game creature's template (its components, behaviour, loot and values) under the mod's id, made by kiln.gamedata's template clones; the fields given are the entry's own. A copy of another added creature is refused. Template clones a mod makes through kiln.gamedata or a block are entries of their mod too.
  • Add requires GameStart and an explicit present Kiln like id; clone chains end at a game entry. Kiln retains the stable identity and pins the structural base install-wide. Use a new id for an incompatible base.
  • Remove: no.
  • Raw game paths in edits (the Advanced tier): allowed.

Edit it from a data pack

A creature's id is its template's: game:enemy_vukah_melee. An edit is global to the creature's kind, never one creature in the world (kiln.creatures keeps its per-creature setters for that). Select by id, glob or trait ("has": ["enemy"]; wildlife, animal and villager too); creatures without a value of a field are named below.

  • Number fields take values and relative operations ("op": {"mul": 1.5}); faction, loot.disabled are set ("op": "scavenger", "op": true).
  • A field a creature does not have (most have no size of their own; only enemies have sight and an arsenal) reads null there: an absolute value is refused for that creature alone, and a relative operation refuses the edit. Select the creatures that have the field ("has": ["enemy"]) or name them.
  • kind, arsenal, tameable and favoriteBait are read-only. The wild animals' taming: tamingSteps (taming guide).

Edit it from C#

registry.Alter(stage =>
{
    var vukah = stage.Creatures["game:enemy_vukah_melee"];
    vukah.Sight.Range = vukah.Sight.Range * 1.5;
    vukah.Resist.Fire = 2.0;                               // takes double fire damage; 0 would make it immune
    foreach (var wolf in stage.Creatures.Select("game:enemy_wildbeast_wolf_*"))
        if (wolf.Kind == RegistryCreatureKind.Enemy) wolf.Level = 12;
    var dog = stage.Creatures["game:animal_wildlife_dog_05_white_ag2"];
    if (dog.Tameable) dog.TamingSteps = 3;
});

stage.Creatures is a RegistryEntries<CreatureEntry>. A typed property reads 0 (or false) for a creature that has no value of that field: tell such creatures by Kind or id, never by a 0, which for Resist.* would mean immune (RegistryEdits sample).

Views

RegistryViews.Find("creatures") is the stable view (705 creatures on server 27054986, 689 on 26430253). Its arsenal field is a Ref to the arsenals view, favoriteBait a Ref to the game's templates. The advanced view template lists every template (12,269) and reports CoveredBy where this registry maps the member (views.md).

Since 0.2.0-dev.32 an entry's Template is its template in that view, every component readable by kind (stage.Creatures["game:enemy_vukah_melee"].Template.Get<int>("components[level].dataStorage[0]"); views.md). A component path this registry maps one to one names the field (CoveredBy, or Covers for one index), and stage.View("template")[id].Set(path, value) edits it as this registry's field (at WorldLoad, HotReload or in Registries.Change; never inside GameStart, where views are not open yet).

Worked example

Every Vukah enemy sees half again as far, early-game wolves spawn at level 12 (when their spawner sets no level of its own), and the white wild dog takes 3 pettings to tame:

{
  "format": 1,
  "registry": {
    "alter": [
      { "registry": "creatures", "select": { "id": "game:enemy_vukah_*", "has": ["enemy"] }, "field": "sight.range", "op": { "mul": 1.5 } },
      { "registry": "creatures", "select": { "id": "game:enemy_wildbeast_wolf_earlygame" }, "field": "level", "op": 12 },
      { "registry": "creatures", "select": { "id": "game:animal_wildlife_dog_05_white_ag2" }, "field": "tamingSteps", "op": 3 }
    ]
  }
}

This is mods/samples/RegistryEdits's pack. level, levelMax, faction, scale, xp, damage.multiplier, resist.*, speed.* and loot.* reach creatures that spawn after the edit; health.*, damage.perPlayer, sight.* and tamingSteps are read at once by every creature of the entry. sight.* (since round 3 also coneAngle, nightFactor, waterFactor, knownTargetFactor and engageRangeMoving) are the AI's sight check: how far and how wide an enemy sees, by night and in water, and when it engages at once.

In multiplayer

The server owns creatures: every field is serverOnly, so no client holds a copy and a vanilla client plays against the changed creatures unchanged. A pack with only creature edits is clients: none (choosing clients).

Known limits

  • An edit cannot reach one creature, and cannot remove a kind. Entry add (0.2.0-dev.32, GameStart only): {"registry": "creatures", "entry": "add", "id": "<mod>:<name>", "like": "game:<creature>", "fields": {"level": 12}} (C# Creatures.AddLike) is a kiln.gamedata template clone of the like creature (its components, behaviour, loot and values; spawn it by its GUID); the fields given are its own. A template clone a mod makes through kiln.gamedata or a block (an NPC body, a creature block) is an entry of its mod too.
  • A creature already in the world keeps the values it spawned with (see the field's note).
  • levelMax lower than before may load a saved creature at a lower level (a warning in registry.json).
  • Not yet seen in a real game: creature, faction and speed edits in play on a joined server, and the taming steps a real animal takes after tamingSteps.

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