Interface MachineInstance


@NonExtendable public interface MachineInstance
A machine in the world (ARCHITECTURE.md ยง12). Owner thread only, except inspect() snapshots which are immutable once taken.
  • Method Details

    • type

      @NotNull @NotNull MachineType type()
    • position

      @NotNull @NotNull WorldPosition position()
    • facing

      @NotNull @NotNull Direction facing()
    • schedulerState

      @NotNull @NotNull SchedulerState schedulerState()
    • lastWakeReason

      @Nullable @Nullable WakeReason lastWakeReason()
    • lastError

      @Nullable @Nullable MachineError lastError()
    • isActive

      boolean isActive()
      Whether the machine is visibly working, see MachineContext.setActive(boolean).
    • capability

      @NotNull <T> @NotNull Optional<T> capability(@NotNull @NotNull CapabilityType<T> type, @Nullable @Nullable Direction side)
      A capability exposed on an absolute face, as another machine or transport sees it. side == null asks for unsided capabilities.
    • upgrades

      @NotNull @NotNull List<InstalledUpgrade> upgrades()
    • installUpgrade

      @NotNull @NotNull Result<InstalledUpgrade> installUpgrade(@NotNull @NotNull UpgradeType type, int count)
      Installs count units of an upgrade.
      Returns:
      an error if the type is not accepted, the slots are full, or the stack limit is reached
    • upgradeRoom

      @NotNull @NotNull Result<Integer> upgradeRoom(@NotNull @NotNull UpgradeType type)
      How many more units of type the machine takes now.
      Returns:
      at least 1, or an error saying why none fit: not registered, not accepted, every upgrade slot used by other types, or already at UpgradeType.maxStack()
    • removeUpgrade

      int removeUpgrade(@NotNull @NotNull UpgradeType type, int count)
      Removes up to count units; returns how many were removed.
    • runAction

      @NotNull MachineAction.Outcome runAction(@NotNull @NotNull String id, @NotNull MachineAction.Click click)
      Runs one of the type's menu actions (D40, MachineType.action(String)). Owner thread. An unknown id, a machine no longer valid, or an action that throws is refused; a run that did something posts MachineEvents.ACTION.
    • list

      @NotNull @NotNull List<Map<String,String>> list(@NotNull @NotNull String id)
      The rows of one of the type's lists (D40, MachineType.list(String)); empty for an unknown id.
    • wake

      void wake(@NotNull @NotNull WakeReason reason)
      Signals an external event (owner thread). Wakes the machine if its state accepts it.
    • inspect

      @NotNull @NotNull MachineInspection inspect()
    • context

      @NotNull @NotNull MachineContext context()
      The same context the machine's behavior gets, for code outside its tick (listeners, commands, tools): its data, storages and world. Owner thread only.