Skip to content

📦 Crafting — Routing

📦 Folder Overview

This folder contains runtime implementations of ICraftingOutputRouter.

Routers decide where crafted outputs are delivered by resolving a destination container per output.

Routing is used during both preflight and delivery so behaviour remains consistent across normal, instant, delayed, and restored crafts.


🧩 What Lives Here

  • implementations of ICraftingOutputRouter
  • routing logic for output destination selection

🎯 Purpose

Routing provides a way to override the default output destination and support:

  • category-based containers
  • station- or recipe-aware routing
  • per-item destination rules
  • custom inventory layouts

Routing affects destination only. It does not change quantities or timing.


🧠 Usage Guidance

Resolution Order

For each output, the service resolves the destination using:

  1. Assigned router on CraftingService (if present)
  2. Default container fallback

Routers must be explicitly assigned and are not auto-discovered.


Router Input

Each call receives:

  • CraftContext ctx
  • ItemRef item
  • adjusted quantity
  • default container name

Routing is evaluated during both preflight and delivery. Implementations should be deterministic for a given context.


Writing a Router

public interface ICraftingOutputRouter
{
    bool TryResolveContainer(ref CraftContext ctx, in ItemRef item, int quantity, out string containerName);
}

Return values:

  • true → decision provided (including default)
  • false → no decision; fallback used

⚠️ Important Notes

  • routing is invoked per output add
  • logic should be lightweight
  • routing does not modify quantities or context
  • escrow crafting does not use routing

🚫 Not for Production Use

This folder does not include:

  • inventory implementation
  • quantity modification logic
  • scheduling or execution control

  • Crafting Core (execution and delivery)
  • Crafting Context (data passed to routers)

🧩 Included Routers

  • OutputToContainerRouter — routes all outputs to a single configured container

This provides a simple, ready-to-use routing option:

  • Assign it to the CraftingService
  • Set a container name (for example: Chest, CraftOutput)
  • All outputs will be delivered there

This is useful for:

  • quick setup and testing
  • simple projects with a single output destination

For more advanced behaviour, implement your own ICraftingOutputRouter.


🧠 Design Notes

  • routing is a final destination decision step
  • designed to be deterministic and composable

If additional behaviour is required, it should be implemented through custom routers or other supported extension seams.