Frostdev

KilnAPI reference Guide

The impacts registry

Every effect an ability or a creature spawns that hits or acts by itself: projectiles (a spell's bolt, an arrow, a thrown bomb, an enemy's shot) and areas (an explosion, a zone, a slam's hit volume). How long one lasts, and how hard it pushes what it hits. An edit is global: every impact of the entry that spawns after it.

Schema version 0.1.1, experimental (KILNX031: may change in any release until it is marked stable). C# entry type Kiln.Registry.ImpactEntry. 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 impact'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.
  • An impact has the id of its template: the template's debug name in lower case (Projectile_Player_Staff_Fireball_1 is game:projectile_player_staff_fireball_1). 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 that run an impact program; the same id names the template in every registry (a spell item's launch, creatures).
  • Names: DisplayName (never empty; display names) is the name of the impact's template, as for creatures: Kiln's catalog, else one made from the template's debug name.

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.

Field Type Applies Ops Since Mapping Joined client About
kind enum (projectile, area) now read-only 0.1.0 mapped serverOnly What the impact is: a projectile, which flies from where it is launched (its speed is the launching item's, items.launch.speed), or an area, which acts where it is spawned.
lifetime time s 0..3600 now number 0.1.0 mapped serverOnly How long the impact exists, in seconds, unless it ends itself first (a projectile that hits something, an explosion's program): a projectile's reach with its speed, an area's duration. Only impacts that have a lifetime of their own can take one (an impact without one reads null and refuses an edit). Impacts that spawn after the edit get it; one already in the world keeps the end it spawned with.
pushBack enum (none, verySmall, small, normal, big, veryBig, pullSmall, pullNormal) now set 0.1.0 mapped serverOnly How hard the impact pushes back what it hits (pullSmall and pullNormal pull it in), for the impacts whose own data carries it (others read null and refuse an edit; their program's default applies). Read when the impact's program starts: impacts that spawn after the edit get it.
radius float m 0..100 now number 0.1.1 mapped serverOnly How big the impact is: the radius, in metres, of its sphere (the first sphere of its normal shape), the volume an explosion or a zone hits or a projectile collides with. Only impacts shaped as a sphere have one (others, a box or a capsule, read null and refuse an edit). Impacts that spawn after the edit get it; one already in the world takes it at its next move.
gravity float -100..100 now number 0.1.1 mapped serverOnly How strongly gravity pulls a projectile, as a factor of the world's gravity (0: it flies straight, 1: it falls like a thrown stone). Only impacts with a gravity factor of their own have one (60 on this game build, all but one of them projectiles; others read null and refuse an edit). Impacts that spawn after the edit get it; one already in the world keeps its own.

Traits

Selectors ask for these with has / hasNot.

Trait Means
projectile a projectile: it flies (kind projectile)
area an area: an explosion, a zone or a hit volume (kind area)

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 impact's template under the mod's id (kiln.gamedata's template clones); the fields given are the entry's own. The impact runs its like's program: what it does stays its like's. Template clones a mod makes through kiln.gamedata or Kiln.Blocks (projectiles, areas) 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. Impacts are never removed: an ability or item that spawns one names it.
  • Raw game paths in edits (the Advanced tier): allowed.

Edit it from a data pack

An impact is a template that runs an impact program: a projectile (has: ["projectile"]: a spell's bolt, an arrow, a thrown bomb, an enemy's shot) or an area (has: ["area"]: an explosion, a zone, a slam's hit volume). Its id is its template's: game:projectile_player_staff_fireball_1. An edit is global: every impact of the entry that spawns after it.

  • "field": "lifetime", "op": {"mul": 0.5}: how long the impact exists, in seconds (a projectile's reach with its speed, an area's duration). Impacts that spawn after the edit get it; one already in the world keeps the end it spawned with.
  • "field": "pushBack", "op": "veryBig": how hard it pushes back what it hits (pullSmall and pullNormal pull it in), read when its program starts.
  • "field": "radius", "op": {"mul": 1.5}: its size, the radius of its sphere (the first sphere of its normal collider: explosions, zones, most projectiles; impacts 0.1.1). One shaped as a box or a capsule reads null. It reaches impacts that spawn after the edit, and one in the world at its next move.
  • "field": "gravity", "op": 0: how strongly gravity pulls it, a factor of the world's (Fireball I's bolt 0.1; impacts 0.1.1). Only the impacts with a factor of their own have one (60 on this build, all but one projectiles).
  • An impact without a value of a field (no lifetime of its own, no push-back in its own data: the Fireball's explosion uses its program's default) reads null: an absolute value is refused for that impact alone and a relative operation refuses the edit. Select the impacts that have it, or name them.
  • kind is read-only. A projectile's speed is the item that launches it: items launch.speed (straight ahead) and launch.lift (upward, a throw's arc), read at each launch; a cast whose spawn sets a speed of its own (the Lightning Ball spells') ignores the item's.
  • No entry remove. Entry add (0.2.0-dev.32, GameStart only): {"registry": "impacts", "entry": "add", "id": "<mod>:<name>", "like": "game:<impact>"} (C# Impacts.AddLike) is a kiln.gamedata template clone of the like impact, running its program; the fields given are its own. A template clone of an impact that a mod makes through kiln.gamedata or Kiln.Blocks (a spell's projectile, its area) is an entry of its mod too. Raw paths are allowed (the template's own members); kiln.gamedata's templates section keeps working, and a registry edit is the later layer and wins (reported).

Edit it from C#

Kiln.Registry.Registries.For(context).Alter(stage =>
{
    var bolt = stage.Impacts["game:projectile_player_staff_fireball_1"];
    bolt.Lifetime = TimeSpan.FromSeconds(bolt.Lifetime.TotalSeconds * 0.6667);   // with a 1.5x launch speed: the same reach
    stage.Impacts["game:explosion_player_spell_lightburst_explosion1"].PushBack = ImpactPushBack.VeryBig;
    stage.Items["game:ammo_t1_spell_fire_ball_lvl10"].Launch.Speed *= 1.5;
});

stage.Impacts is a RegistryEntries<ImpactEntry> (Kind an ImpactKind, read-only; Lifetime a TimeSpan; PushBack an ImpactPushBack; Radius and Gravity doubles). The complete mod: SpellRegistry sample.

Views

RegistryViews.Find("impacts") is the stable view (863 impacts on the current server build: 339 projectiles, 524 areas). The advanced view template lists every template 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.Impacts["game:projectile_player_staff_fireball_1"].Template.Get<double>("components[staticGravityModifier].modifier"); 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

Fireball I's bolt flies 1.5 times as fast for two thirds of its time, so it reaches as far, Light Burst's first blast pushes harder, and the Fireball's explosion is half again as wide (SpellTweaks' collider radius edit):

{
  "format": 1,
  "registry": {
    "alter": [
      { "registry": "items", "select": { "id": "game:ammo_t1_spell_fire_ball_lvl10" }, "field": "launch.speed", "op": { "mul": 1.5 } },
      { "registry": "impacts", "select": { "id": "game:projectile_player_staff_fireball_1" }, "field": "lifetime", "op": { "mul": 0.6667 } },
      { "registry": "impacts", "select": { "id": "game:explosion_player_spell_lightburst_explosion1" }, "field": "pushBack", "op": "veryBig" },
      { "registry": "impacts", "select": { "id": "game:explosion_player_spell_fireball_1" }, "field": "radius", "op": { "mul": 1.5 } }
    ]
  }
}

This is part of mods/samples/SpellRegistry's pack.

In multiplayer

Impact fields are the server's (serverOnly): the server spawns and ends the impacts and applies their push-back. A pack of impact edits is clients: none (choosing clients); items.launch.* follows the content sync like the other item fields.

Known limits

  • Only impacts whose own data carries a value can take an edit of it; the others keep their program's default.
  • A cast that sets its own spawn speed (the Lightning Ball spells) ignores items.launch.*.
  • Not yet seen in a real game: a projectile living for its new lifetime, a hit pushing by the new push-back, an explosion of the new radius hitting what it reaches, a projectile falling by its new gravity, what a vanilla client shows of a changed projectile.

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