Interface ModContext


public interface ModContext
Startup registration surface scoped to one manifest and the startup thread. Registrations close when GameMod.register(forgottentowns.mod.api.ModContext) returns. Captured settings/tables and published rule values may be retained; the registration context must not be retained or used asynchronously.
  • Method Details

    • registerManualTradeReservations

      default void registerManualTradeReservations(boolean enabled)
      Selects whether the shared Stock panel offers manual trade reservations. Any provider can opt out; native Settlement Trading opts out by default, and a mod cannot override that decision by registering true. When disabled, existing reserved cargo returns to its owning settlement through durable delivery receipts; ordinary stock remains available for direct selling and crafting.
      Parameters:
      enabled - whether this mod permits manual reservations
      Throws:
      IllegalArgumentException - if duplicated or the manifest predates API 15
      IllegalStateException - after startup registration closes
      UnsupportedOperationException - if the host predates reservation policies
    • registerTradeFilter

      default void registerTradeFilter(Predicate<String> filter)
      Registers a resource filter applied to merchant and settlement commerce in both directions. All registered filters must accept a resource, including the native packed-goods policy. Adding a trade-goods definition participates in that native policy automatically. Capture final registry identities through onRegistriesReady(java.util.function.Consumer<forgottentowns.mod.api.RegistryAccess>).
      Parameters:
      filter - predicate receiving a stable resource ID
      Throws:
      IllegalArgumentException - if null, duplicated, or the manifest predates API 15
      IllegalStateException - after startup registration closes
      UnsupportedOperationException - if the host predates resource trade filters
    • registerKeyboardShortcut

      default void registerKeyboardShortcut(KeyboardShortcut shortcut)
      Registers a mod-owned, remappable keyboard command. Defaults and legacy preference aliases belong to the pack; the host supplies the editor and dispatch.
      Parameters:
      shortcut - owned command definition with a localized label
      Throws:
      IllegalArgumentException - if null, duplicated, not owned, or unsupported by the manifest
      IllegalStateException - after startup registration closes
      UnsupportedOperationException - if the host predates shortcut registration
    • registerWorldInspection

      default void registerWorldInspection(WorldInspection inspection)
      Enables dedicated viewport inspectors for this mod.
      Parameters:
      inspection - supported inspection targets
      Throws:
      IllegalArgumentException - if null, duplicated, or unsupported by the manifest
      IllegalStateException - after startup registration closes
      UnsupportedOperationException - if the host predates inspection support
    • registerSettlementTradeCore

      default void registerSettlementTradeCore(SettlementTradeCore core)
      Publishes this mod's shared trading configuration for declared dependents. The provider must validate its production rules through onRegistriesReady(java.util.function.Consumer<forgottentowns.mod.api.RegistryAccess>).
      Parameters:
      core - immutable rule sets, also usable by the provider's own policy
      Throws:
      IllegalArgumentException - if null, duplicated or unsupported by the manifest
      IllegalStateException - after startup registration closes
      UnsupportedOperationException - if this host does not support trading cores
    • requireSettlementTradeCore

      default SettlementTradeCore requireSettlementTradeCore(String modId)
      Resolves a core already published by a directly declared dependency. Dependency order guarantees the provider registers first. No fallback rules are substituted when an older installed dependency lacks the required core. The native game supplies settlement_trading before optional mods register; a direct dependency on that ID requires no installed copy of the historical pack.
      Parameters:
      modId - provider ID declared in this mod's manifest dependencies
      Returns:
      the exact immutable core published by the provider
      Throws:
      IllegalArgumentException - if the provider ID is null, the dependency is undeclared, absent or provides no core, or the manifest does not support this registration
      IllegalStateException - after startup registration closes
      UnsupportedOperationException - if this host does not support trading cores
    • registerSettlementMap

      void registerSettlementMap(SettlementMap rules)
      Registers one location-map policy and its paid arrival offers.
      Parameters:
      rules - pure location and recruitment policy
      Throws:
      IllegalArgumentException - for a null or duplicate policy or an unsupported manifest declaration
      IllegalStateException - after startup registration closes
    • dataTable

      Object dataTable(String id)
      Reads a manifest-listed, deeply immutable JSON table.
      Parameters:
      id - nonnull table identifier declared in the manifest's tables object
      Returns:
      JSON object, list, scalar or null captured with this mod's gameplay hash
      Throws:
      IllegalArgumentException - if the table is absent or the manifest does not support this operation
      IllegalStateException - if startup registration has closed
    • registerSettlementTrading

      void registerSettlementTrading(SettlementTrading rules)
      Registers one settlement trading policy for this mod, including shared UI panels.
      Parameters:
      rules - pure policy controlling availability and economic rules
      Throws:
      IllegalArgumentException - if null, duplicated, or unsupported by the manifest
      IllegalStateException - if startup registration has closed
    • settings

      Map<String,Object> settings()
      Reads this pack's immutable manifest-listed configuration.
      Returns:
      JSON settings copied from the captured pack, or an empty map
      Throws:
      IllegalArgumentException - if the manifest does not support this operation
      IllegalStateException - if registration has closed
    • registerColonyExtension

      void registerColonyExtension(Supplier<ColonyExtension> factory)
      Registers one factory for independent, persistent per-world simulation instances. Startup validation also creates disposable instances and exercises empty restore, save, and saved-state restore. Those callbacks must not depend on an active world or external side effects.
      Parameters:
      factory - factory returning a fresh nonnull extension for each request
      Throws:
      IllegalArgumentException - if duplicated, null, or unsupported by the manifest
      IllegalStateException - if registration has closed
    • registerHousingPolicy

      void registerHousingPolicy(HousingPolicy policy)
      Adds a startup-only housing expansion policy, shared by manual and automatic assignment.
      Parameters:
      policy - bed-limited expansion policy for residential, barracks, guard_post, or tavern zones
      Throws:
      IllegalArgumentException - if policy is null, contains unsupported home zones, or the manifest does not support this operation
      IllegalStateException - if registration has closed
    • onRegistriesReady

      void onRegistriesReady(Consumer<RegistryAccess> callback)
      Registers this mod's one startup callback for the final validated definition catalog. It runs once on the startup thread after all registrations and runtime content validation, before a world/window is created, including during headless validation. The immutable snapshot may be retained. Exceptions fail startup and identify the responsible mod. This callback cannot register further hooks or mutate the catalog.
      Parameters:
      callback - consumer of frozen definitions, including host-generated trade goods and packing recipes
      Throws:
      IllegalArgumentException - if callback is null, already registered, or the manifest does not support this callback
      IllegalStateException - if registration has closed
    • registerEquipmentTransform

      void registerEquipmentTransform(String id, EquipmentTransform transform)
      Registers a pure equipment conversion invoked after reserved inputs are consumed.
      Parameters:
      id - namespaced handler identifier belonging to this mod
      transform - deterministic conversion, using only the supplied random source
      Throws:
      IllegalArgumentException - if the identifier or implementation is invalid or duplicated
      IllegalStateException - if registration has closed
    • registerParticleShape

      void registerParticleShape(String id, ParticleShape shape)
      Registers a convex particle polygon without exposing graphics state to the mod.
      Parameters:
      id - namespaced shape identifier belonging to this mod
      shape - normalized, immutable polygon
      Throws:
      IllegalArgumentException - if the identifier or shape is invalid or duplicated
      IllegalStateException - if registration has closed