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 Summary
Modifier and TypeMethodDescriptionvoidblock(@NotNull MachineError reason, long retryTicks) Sleep until something is extracted or output space frees up.longTicks since the machine last ticked, excluding time spent unloaded (D4).@NotNull MachineEnvironmentWhat the machine's block sees of the world: sky, daytime, weather (E3).voiderror(@Nullable MachineError error) Records an error shown in inspection;nullclears it.voidexposeHandler(@Nullable ResourceHandler handler) Makes every side of this machine showhandlerinstead of its ports (e.g.longgameTime()Current game time of the machine's world.<T> Tget(@NotNull MachineDataKey<T> key) The current value of one of the data keys the machine's type declares.@NotNull MachineInstancemachine()This machine.@NotNull OtherMachinesmachines()Other machines by position.longmodified(@NotNull ModifierType type, long base) default longmodifiedCost(@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).<T> @NotNull Optional<T> neighbor(@NotNull RelativeSide side, @NotNull CapabilityType<T> type) A capability of the neighboring machine onside, facing back at this machine.@NotNull BlockOptionsoptions()The numbers this machine's block config gives it (D34): itsoptions:, read with the machine's ownConfigKeys.@NotNull PortDirectionportDirection(@NotNull String port) The port's current direction (setPortDirection(String, PortDirection), or the type's).@NotNull Set<RelativeSide> The port's current sides (setPortSides(String, Set), or the type's).@NotNull ProcessControlprocess()The machine's timed process: start, advance, cancel (D15).@NotNull PushResultpush(@NotNull RelativeSide side, @NotNull String storage, @NotNull Predicate<ResourceVariant> filter, long maxAmount) Moves up tomaxAmountmatchingfilterfrom one of this machine's storages into the port of the neighbor onside.@NotNull RandomGeneratorrandom()Deterministic per-machine randomness (§19).@NotNull RecipeLookuprecipes()Looks recipes up by type and by what a machine holds.@NotNull RegistryAccessRead access to the engine's registries.<T> voidset(@NotNull MachineDataKey<T> key, T value) Stores a new (immutable) value; persisted with the machine.voidsetActive(boolean active) Whether the machine is visibly working (e.g.voidsetPortDirection(@NotNull String port, @NotNull PortDirection direction) Changes how one of this machine's ports works, e.g.voidsetPortSides(@NotNull String port, @NotNull Set<RelativeSide> sides) Side configuration (E2): the facesportis exposed on, relative to the facing.voidsetStorageCapacity(@NotNull String storage, long capacity) Sizes one of this machine's storages at runtime, per slot (e.g.voidsleep()Sleep until any signal.@NotNull ResourceHandlerFull access to one of this machine's own storages, bypassing port rules.@NotNull ResourceTagstags()Resource tags: named sets of resource types.@NotNull TransactionManagerOpens transactions (§9).default @NotNull MachineTypetype()This machine's type.voidSleep until something is inserted or inputs change.voidwakeIn(long ticks) Sleep forticksticks.@NotNull MachineWorldworld()The blocks, fluids, redstone and effects around this machine.
-
Method Details
-
machine
This machine. -
type
This machine's type. -
storage
Full access to one of this machine's own storages, bypassing port rules. -
get
The current value of one of the data keys the machine's type declares. -
set
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
Opens transactions (§9). -
tags
Resource tags: named sets of resource types. -
registries
Read access to the engine's registries. -
recipes
Looks recipes up by type and by what a machine holds. -
process
The machine's timed process: start, advance, cancel (D15). -
modified
- Returns:
basewith this machine's upgrade modifiers oftypeapplied (D16)
-
modifiedCost
A per-tick process cost after upgrades:StandardModifiers.PROCESS_COST, then the cost modifier of the resource's category (StandardModifiers.processCost). -
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
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 forticksticks. -
error
Records an error shown in inspection;nullclears 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 CraftEngineactiveproperty); saved with the machine. -
environment
What the machine's block sees of the world: sky, daytime, weather (E3). -
setPortDirection
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 inMachineBehavior.onLoad(MachineContext).- Parameters:
port- aPortDefinition.id()of this machine's type
-
portDirection
The port's current direction (setPortDirection(String, PortDirection), or the type's). -
setPortSides
Side configuration (E2): the facesportis exposed on, relative to the facing. Saved with the machine; neighbors, networks and hoppers see the change at once. -
portSides
The port's current sides (setPortSides(String, Set), or the type's). -
setStorageCapacity
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;-1goes 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
The numbers this machine's block config gives it (D34): itsoptions:, read with the machine's ownConfigKeys. Itsstorages:capacities already size the storages. -
exposeHandler
Makes every side of this machine showhandlerinstead of its ports (e.g. a multiblock's valve passing through to the structure's storage);nullgoes back to the ports. Not saved: a behavior sets it again inMachineBehavior.onLoad(MachineContext). -
world
The blocks, fluids, redstone and effects around this machine. -
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 onside, facing back at this machine. Empty if there is none or if the neighbor is owned by another region (usepush(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 tomaxAmountmatchingfilterfrom one of this machine's storages into the port of the neighbor onside. Same region: a direct transfer. Another region: a handoff through escrow (§16.3).
-