MODDING INSTRUCTIONSCreate your first pack →

Inventory, work and construction

The Mod API connects ColonyContext.inventory() and work() to the running settlement. The Colony Planner example compiles against the API-only JAR and has no dependencies on other mods or engine implementation classes.

Scoped commands and detached results

Use these services inside update, onConversation, or onWorkFinished. Service instances expire when that callback returns and reject another thread. Stock, Job, their lists and resource maps are detached values that can be retained. Query again after a command to observe current state. Inventory/work mutations share 128 calls per callback, including rejected commands. The earlier citizen modifier API retains its existing behavior and is not subject to this new command budget.

Commands execute synchronously at the callback boundary; an accepted job joins the normal worker queue. It does not promise a worker, resources or a reachable route. No mod may supply a cost override, worker executor, mutable inventory, blueprint object or internal manager through this API. Expected gameplay rejection returns false or null. Invalid argument ranges and expired service access throw exceptions. These results are machine values, not localized player messages.

Physical inventory

Operation Contract
stores() Concrete settlement stockpile-zone and storage-placeable keys, including empty stores; one category scan
stock(key) Current immutable quantities and capacity in stack slots; null for a missing/ineligible store
transfer(from, to, resource, amount) Move exactly 1–4096 units, or change neither store

Storage keys are opaque values returned by stores(). A query never creates a phantom inventory. Transfers require live eligible stores, a known resource, enough source stock, a compatible destination filter (including disabled per-item storage policies) and enough physical stack capacity. Books and other single-slot items use their native stack sizes. Transfers preserve aging batches, discovered identity, aggregate quantity and native revisions. Oldest units move first. The source and destination must differ; partial transfers are not performed.

This is an immediate scripted transfer, without travel time or a hauling worker. It is useful for explicit mod mechanics, not a replacement for ordinary hauling. Actor inventories, carts, loot, workstation buffers, abstract overflow stores and custom hauling jobs are not exposed yet.

Work requests and construction

var work = context.work();
var target = new ColonyContext.Position(x, y, supportZ);
var order = work.queue(ColonyWork.Action.DIGGING, target, 0);
var plan = work.planPlaceable("my_mod:workbench", anotherTarget,
        ColonyWork.Facing.SOUTH, 1);

queue supports gathering, mining, digging, woodcutting and harvesting. It reuses interactive designation's feature anchors, harvestability and protected-support rules, and requires explored terrain. It never replaces a different work type. Repeating an identical request returns the existing identity; use setPriority explicitly to change its priority.

planPlaceable accepts existing or mod-registered placeable IDs. It uses authored dimensions, logical facing, costs, discovery/progression gates, room/support/occupancy checks, campaign target restrictions, required preparation stations and unreserved crafted-item checks. The viewport shares the placement, blueprint and crafted-item logic. Raw-material plans can wait for materials; crafted furniture needs its unreserved crafted item before planning. No resources are granted or consumed by submission: native builders handle acquisition, preparation and consumption.

Coordinates use engine tile units, with z increasing downward. Provide the exact construction support level. Coffins use the buried construction support level, one above their visual support in coordinate value (visualSupportZ = constructionSupportZ + 1). Facings are logical cardinal values, not sprite indices. Definitions resolve supported facings themselves.

get(queue, id) looks up an active job. at(position) uses native indexes for work anchored at that tile and blueprints occupying it. Construction queries and commands exclude foreign-owned plans. setPriority accepts −1, 0 or 1. cancel uses native reservation release and linked-plan semantics: canceling an indivisible bridge can cancel its whole plan and refund delivered materials. These management operations also work on player-created jobs; mods must choose their scope deliberately.

The Mod API provides the following requests through these same scoped services:

  • craftingRequest(recipeId, batches) adds 1-4096 batches to a native bill after the normal biome, discovery and station checks. crafting(recipeId) reads outstanding batches, minimum stock and infinite production. Requests are additive; save a receipt before retrying. Workers still need reachable, correctly furnished stations and ingredients. Completion uses ordinary crafting events.
  • planZone(zoneId, tiles, priority) plans up to 256 supports on one layer through shared player/mod zone construction. Discovery, progression, exploration, support and conflicts are checked before any blueprint is created. Duplicate tiles collapse; an entirely repeated pending plan returns its existing jobs, while a partial overlap rejects the entire request. Native workers clear vegetation and pay the normal floor/stockpile costs. Cancel each returned tile job when cancelling a whole painted footprint; completed tiles remain real zones.
  • haulPlaceable(placeableId, storeKey, priority) requests physical furniture pickup into a worker's inventory and native delivery to an exact physical store. Ownership, pickup eligibility, filters, capacity and conflicts are checked. Repeated pending requests return the same job. The terminal event describes pickup, not final stock delivery; inspect storage when final delivery matters. Capacity can change while work is pending, so delivery still follows native fallback/wait rules.

These additions use native job/bill persistence and the existing cancellation/accounting pipeline. Colony Planner demonstrates their panel actions. Structural blocks, bridges, crop plans, general loose-item/store-to-store hauling and entirely new work executors remain outside typed submission. Existing jobs can still be observed and managed where supported by the generic queue interface.

Completion, cancellation and saves

@Override
public void onWorkFinished(ColonyContext context, ColonyWork.Job job) {
    if (job.queue() == ColonyWork.Queue.CONSTRUCTION && job.id() == savedPlanId) {
        savedOutcome = job.status(); // COMPLETED or CANCELLED
    }
}

The host queues terminal snapshots after native queue removal. It delivers callbacks after the simulation tick, before a refresh, or before any part of a save snapshot is captured. Callbacks run after the native operation returns, with the crafting-bill completion listener preserved. Each event is delivered to the active extensions in load order. Events caused by callbacks wait until the next boundary, preventing recursive execution inside a cancellation. Saving drains these later generations first, up to 128 generations; a self-perpetuating chain fails explicitly instead of losing notifications.

Events cover all observed native work, including player-created jobs. They start when the world's mod runtime attaches; existing completed history is not replayed. get returns null for terminal jobs. That alone cannot distinguish completion from cancellation: keep the outcome in your own saved state when it matters. Treat unknown future kind strings as unsupported values, not fatal errors.

Persist the queue plus ID, request state and handled outcome in ColonyExtension.save(). Native plans and mod receipts are captured together before the background writer starts, and removed job IDs are not reused after reload. Terminal events are not replayed on load. Do not resubmit completed requests unconditionally from update or restore. See saves and updates.

Forgotten Towns · Modding reference