Техническая документация доступна на английском языке. Имена кода и полей соответствуют текущему Mod API.
МОДИНГОВАЯ ДОКУМЕНТАЦИЯ
Events and player notifications
The Mod API provides typed native events to world-owned colony extensions and localized messages through the existing event log and alert banner. The standalone Memorials project compiles against the API-only JAR, needs no other mod and demonstrates death notices, a mourning mood and persistent state.
Listen from your colony extension
Declare "contentApi": 14 in mod.json and register a fresh extension with
context.registerColonyExtension(MyRules::new). Override onEvent for the events you need:
@Override
public void onEvent(ColonyContext context, ColonyEvent event) {
if (event instanceof ColonyEvent.CitizenDied death) {
context.notifyPlayer(new ColonyNotice("mods.my_mod.death",
List.of(death.citizen().name()), death.citizen().position(),
ColonyNotice.Tone.NEUTRAL));
}
}
This is an excerpt, not a complete class. Supply the imports, update method, entrypoint and
translations as shown in the complete source.
All thirteen runtime catalogs must contain your key, for example an English value of
"{0} has died.". Names and counts are arguments; sentences belong in translation catalogs.
| Event | Data and exact meaning |
|---|---|
CitizenArrived |
Newly created friendly actor, including civilians, recruits, heroes and scripted arrivals. The actor snapshot contains identity, archetype, captured name and position. It does not promise a permanent civilian resident. |
CitizenDied |
Citizen entered the native death sequence after immediate resurrection checks. Contains the actor, known cause (ATTACK, STARVATION, UNKNOWN) and a recorded attacker name when available. Corpse cleanup is not another death; later resurrection remains possible. |
CreatureDied |
Final creature death after automatic revival/transformation checks. Contains the actor, native credited citizen ID (zero if unavailable) and whether native bookkeeping marks the death as natural. No general attacker view is exposed. |
HomeChanged |
Citizen ID, previous and final home IDs (zero means unassigned), and an anchor position. Intermediate removal/addition steps coalesce per delivery interval. A move back to the same home produces no event. |
PlaceableRemoved |
Removed object's ID, definition, anchor, support layer and settlement ownership. Covers demolition, destruction, replacement and cleanup; it does not identify damage, cause or refund. |
Each event includes the game day at capture time. IDs are scoped to a world and object category; a creature ID and citizen ID may have the same numeric value. Event records are detached and may be retained. Positions describe the event location, not a guarantee that the object is still there.
Construction completion and work cancellation/completion use
onWorkFinished(context, job) callback; see inventory and construction.
Conversations keep their existing onConversation callback. There is no per-frame subscription.
Timing, ordering and saves
The host captures events during native changes, then delivers a detached batch at a simulation
boundary: after a tick, before a colony refresh, or before a save snapshot. Native mutation and
accounting finish before onEvent runs. Events cannot cancel the original action. Non-housing events
follow capture order; coalesced home changes follow them in first-affected citizen order.
Contexts and services expire when the callback returns and reject use from another thread. Apply
commands through the context; do not retain it. Changes made by callbacks produce a later batch,
preventing recursive event dispatch. Projections and moods refresh after event delivery on the next
colony refresh, even if the game minute has not changed. Keep update idempotent within a day.
Before saving, pending batches drain so native outcomes, callback commands, notices and your saved receipts share one atomic snapshot. A self-perpetuating chain exceeding 128 batches fails the save explicitly. Callbacks should do bounded work and avoid repeatedly creating the event they handle. Callback failures identify the responsible mod and fail the operation.
Events begin when the world's mod runtime attaches. Initial world generation, restored actors,
restored objects and historical deaths are not replayed. Read current state in update when enabling
a mod in an existing world. Persist outcomes in your extension's schema-versioned state; never rely
on a process-wide/static list. Restore state without emitting fresh player notices.
Notify the player
context.notifyPlayer(new ColonyNotice(key, arguments, focus, tone)) adds a native event-log entry
and transient banner. Clicking either can focus the optional world tile. Tones are NEUTRAL,
POSITIVE and DANGER; all use the existing general notification sound.
- Keys must exist and start with
mods.<your_id>.. The host rejects foreign, missing or blank messages. - Supply at most eight nonnull arguments, each at most 256 characters; keys are at most 256 characters and the formatted message is at most 4,096 characters.
- A nonnull focus must lie inside the current world. Coordinates are tile coordinates, with z increasing downward.
- Each mod may post eight notices per game minute. Additional valid calls return
falseand add neither log entry nor banner. Every attempt still consumes one of the context's 128 shared commands. - The rate counter is transient and resets on load. Messages are stored as rendered text in the language active when posted, like other native log entries. Loading does not reissue their banners.
If a burst of changes matters as one story, aggregate it into one summary and save that summary's receipt. A rejected/throttled notice should not cause the underlying gameplay effect to repeat.
What this enables and what remains
These hooks support mourning, arrival welcomes, population milestones, kill counters and rewards through existing commands, home-related rules, demolition tracking and useful localized feedback. Memorials deliberately keeps its behavior small: a death extends one shared mourning deadline; it neither stacks a penalty for every death nor registers a new grave/building system.
This increment does not expose cancellable damage, custom combat/AI, creature spawning, raids,
incidents, terrain generation, campaign quest registration, arbitrary windows or a live settings
editor. Citizen death causes are limited to information the native death bookkeeping knows.
Do not describe PlaceableRemoved as a combat-destruction-only event. See
the category audit and API direction for the remaining boundaries.
