Interface MachineContext


@NonExtendable public interface MachineContext
Everything a MachineBehavior may touch (ARCHITECTURE.md §12). Owner thread only.

Scheduling: after MachineBehavior.tick(MachineContext) the machine stays SchedulerState.ACTIVE unless the behavior called one of sleep(), waitForInput(), block(MachineError, long), wakeIn(long) during that tick.

  • Method Details

    • machine

      @NotNull @NotNull MachineInstance machine()
      This machine.
    • type

      @NotNull default @NotNull MachineType type()
      This machine's type.
    • storage

      @NotNull @NotNull ResourceHandler storage(@NotNull @NotNull String id)
      Full access to one of this machine's own storages, bypassing port rules.
    • get

      @NotNull <T> T get(@NotNull @NotNull MachineDataKey<T> key)
      The current value of one of the data keys the machine's type declares.
    • set

      <T> void set(@NotNull @NotNull MachineDataKey<T> key, @NotNull T value)
      Stores a new (immutable) value; persisted with the machine.
    • gameTime

      long gameTime()
      Current game time of the machine's world.
    • elapsedTicks

      long elapsedTicks()
      Ticks since the machine last ticked, excluding time spent unloaded (D4). 1 for a machine that ticks every tick.
    • transactions

      @NotNull @NotNull TransactionManager transactions()
      Opens transactions (§9).
    • tags

      @NotNull @NotNull ResourceTags tags()
      Resource tags: named sets of resource types.
    • registries

      @NotNull @NotNull RegistryAccess registries()
      Read access to the engine's registries.
    • recipes

      @NotNull @NotNull RecipeLookup recipes()
      Looks recipes up by type and by what a machine holds.
    • process

      @NotNull @NotNull ProcessControl process()
      The machine's timed process: start, advance, cancel (D15).
    • modified

      long modified(@NotNull @NotNull ModifierType type, long base)
      Returns:
      base with this machine's upgrade modifiers of type applied (D16)
    • modifiedCost

      default long modifiedCost(@NotNull @NotNull ResourceType type, long amount)
      A per-tick process cost after upgrades: StandardModifiers.PROCESS_COST, then the cost modifier of the resource's category (StandardModifiers.processCost).
    • random

      @NotNull @NotNull RandomGenerator random()
      Deterministic per-machine randomness (§19).
    • sleep

      void sleep()
      Sleep until any signal.
    • waitForInput

      void waitForInput()
      Sleep until something is inserted or inputs change.
    • block

      void block(@NotNull @NotNull MachineError reason, long retryTicks)
      Sleep until something is extracted or output space frees up.
      Parameters:
      retryTicks - also wake after this many ticks; 0 for no retry
    • wakeIn

      void wakeIn(long ticks)
      Sleep for ticks ticks.
    • error

      void error(@Nullable @Nullable MachineError error)
      Records an error shown in inspection; null clears it.
    • setActive

      void setActive(boolean active)
      Whether the machine is visibly working (e.g. a lit furnace front). Hosts show it on the block (a CraftEngine active property); saved with the machine.
    • environment

      @NotNull @NotNull MachineEnvironment environment()
      What the machine's block sees of the world: sky, daytime, weather (E3).
    • setPortDirection

      void setPortDirection(@NotNull @NotNull String port, @NotNull @NotNull PortDirection direction)
      Changes how one of this machine's ports works, e.g. a machine whose mode turns an input into an output. Not saved: a behavior sets it again from its own data in MachineBehavior.onLoad(MachineContext).
      Parameters:
      port - a PortDefinition.id() of this machine's type
    • portDirection

      @NotNull @NotNull PortDirection portDirection(@NotNull @NotNull String port)
      The port's current direction (setPortDirection(String, PortDirection), or the type's).
    • setPortSides

      void setPortSides(@NotNull @NotNull String port, @NotNull @NotNull Set<RelativeSide> sides)
      Side configuration (E2): the faces port is exposed on, relative to the facing. Saved with the machine; neighbors, networks and hoppers see the change at once.
    • portSides

      @NotNull @NotNull Set<RelativeSide> portSides(@NotNull @NotNull String port)
      The port's current sides (setPortSides(String, Set), or the type's).
    • setStorageCapacity

      void setStorageCapacity(@NotNull @NotNull String storage, long capacity)
      Sizes one of this machine's storages at runtime, per slot (e.g. a multiblock's tank, sized by its volume). Saved with the machine; -1 goes back to the type's capacity. What a storage already holds beyond a smaller capacity stays, and nothing more fits until it is below again.
    • options

      @NotNull @NotNull BlockOptions options()
      The numbers this machine's block config gives it (D34): its options:, read with the machine's own ConfigKeys. Its storages: capacities already size the storages.
    • exposeHandler

      void exposeHandler(@Nullable @Nullable ResourceHandler handler)
      Makes every side of this machine show handler instead of its ports (e.g. a multiblock's valve passing through to the structure's storage); null goes back to the ports. Not saved: a behavior sets it again in MachineBehavior.onLoad(MachineContext).
    • world

      @NotNull @NotNull MachineWorld world()
      The blocks, fluids, redstone and effects around this machine.
    • machines

      @NotNull @NotNull OtherMachines machines()
      Other machines by position.
    • neighbor

      @NotNull <T> @NotNull Optional<T> neighbor(@NotNull @NotNull RelativeSide side, @NotNull @NotNull CapabilityType<T> type)
      A capability of the neighboring machine on side, facing back at this machine. Empty if there is none or if the neighbor is owned by another region (use push(RelativeSide, String, Predicate, long) then).
    • push

      @NotNull @NotNull PushResult push(@NotNull @NotNull RelativeSide side, @NotNull @NotNull String storage, @NotNull @NotNull Predicate<ResourceVariant> filter, long maxAmount)
      Moves up to maxAmount matching filter from one of this machine's storages into the port of the neighbor on side. Same region: a direct transfer. Another region: a handoff through escrow (§16.3).