Package forgottentowns.mod.api
Interface ColonyExtension
public interface ColonyExtension
One mod-owned simulation instance per world, created through
ModContext.registerColonyExtension(java.util.function.Supplier<forgottentowns.mod.api.ColonyExtension>).
Callbacks execute on the simulation thread. Never retain a context or use engine implementation classes.
State is a bounded string map inside the atomic save, so loading never deserializes mod classes.
Startup validation creates disposable instances and exercises empty-state restore and save/restore.
Constructors and persistence callbacks must therefore be free of external side effects.-
Method Summary
Modifier and TypeMethodDescriptiondefault List<ColonyAffinity> affinities(ColonyContext.View world) Projects directed citizen feelings into the native roster, after all extensions update.default List<ColonyContext.Mood> moods(ColonyContext.View world, ColonyContext.Person citizen) Supplies current happiness modifiers after all extensions have updated their citizen modifiers.default voidonConversation(ColonyContext context, int first, int second) Observes one newly started social exchange, independent of audio admission, muting or camera position.default voidonEvent(ColonyContext context, ColonyEvent event) Observes a committed native change, after native accounting finishes.default voidonPanelAction(ColonyContext context, String panelId, String actionId) Handles an enabled button from this extension's latest panel projection.default voidonWorkFinished(ColonyContext context, ColonyWork.Job job) Observes completed or cancelled settlement work, including player-created jobs.default List<ColonyPanel> panels(ColonyContext.View world) Projects up to eight localized native information/action panels.default booleanDeclares that this extension supplies affinity presentation, even before relationships exist.default voidRestores this mod's state before its first refresh.save()Captures persistent values; include a schema version when publishing persistent behavior.voidupdate(ColonyContext context) Rebuilds derived citizen modifiers on first attachment, after load, and once per game minute.
-
Method Details
-
restore
Restores this mod's state before its first refresh. An empty map is supplied for a newly enabled mod and may also be a prior intentionally empty save.- Parameters:
state- detached, immutable, mod-owned save values- Throws:
IllegalArgumentException- if a stored schema cannot be restored
-
save
Captures persistent values; include a schema version when publishing persistent behavior.- Returns:
- nonnull string map with no null entries, at most 16384 entries and one MiB of UTF-8 key/value data; the host makes an immutable copy
-
update
Rebuilds derived citizen modifiers on first attachment, after load, and once per game minute. This callback may also run after conversations, committed events, or paused content changes; keep calendar actions idempotent by saved day.- Parameters:
context- current bounded world queries and validated commands
-
onConversation
Observes one newly started social exchange, independent of audio admission, muting or camera position.- Parameters:
context- scoped colony queries and commandsfirst- first participant's stable citizen identitysecond- second participant's stable citizen identity
-
onWorkFinished
Observes completed or cancelled settlement work, including player-created jobs. Delivery occurs after a simulation tick, before the next refresh, or before any save data is captured. Native mutation and resource accounting have finished before this callback. Events are not replayed after load; save owned job IDs and any handled outcome in this extension's state. Events caused by callbacks are delivered at the next boundary.- Parameters:
context- scoped colony servicesjob- immutable terminal job snapshot
-
onEvent
Observes a committed native change, after native accounting finishes. Events generated by a callback wait until the next delivery boundary. Pending events and their effects are drained before saving; notifications are not replayed after loading. Ignore event types the mod does not use. No callback can cancel the native change.- Parameters:
context- scoped colony servicesevent- detached typed event
-
panels
Projects up to eight localized native information/action panels. Called at simulation refresh boundaries and immediately before a panel action, never while drawing. This query must not change persistent state. Return an empty list to hide this mod's panels.- Parameters:
world- current callback-scoped read-only view- Returns:
- nonnull list of at most eight nonnull panel descriptions with unique mod-local identities; the host copies the list
-
onPanelAction
Handles an enabled button from this extension's latest panel projection. Recheck gameplay prerequisites through the scoped services; other mods may have changed the world. Keep durable action outcomes in the ordinary extension save map. Drawing never calls this method.- Parameters:
context- scoped world queries and commands, with the usual shared command budgetpanelId- stable mod-local panel identityactionId- stable mod-local action identity
-
providesAffinities
default boolean providesAffinities()Declares that this extension supplies affinity presentation, even before relationships exist. The host snapshots this capability at simulation refresh boundaries and never calls it while drawing. The default leaves the panel hidden unless the extension returns affinity data, allowing data-only providers.- Returns:
- whether this world should expose the affinity panel while this extension is active
-
affinities
Projects directed citizen feelings into the native roster, after all extensions update. Called at simulation refresh boundaries, never during drawing. Return at most 16384 unique directed pairs per extension; different providers remain separate. Neutral values and pairs involving missing, dead, or deserting citizens are omitted. Keep persistent relationship state in this mod's save.- Parameters:
world- current read-only colony view, valid only during this callback- Returns:
- nonnull detached list of nonnull directed affinities, or an empty list when this mod supplies none
-
moods
Supplies current happiness modifiers after all extensions have updated their citizen modifiers. Effects with the same nonempty stacking key use the greatest absolute value instead of adding. Equal absolute values retain the earlier provider's contribution. Only living, non-deserting recipients are queried; return at most 32 moods for one recipient.- Parameters:
world- current read-only colony viewcitizen- recipient snapshot- Returns:
- nonnull list of nonnull localized, finite happiness rates per in-game minute
-