- Description
- Nested Class Summary
- Method Summary
- Method Details
- fork(InteractionContext, RootInteraction, boolean)
- fork(InteractionType, InteractionContext, RootInteraction, boolean)
- fork(InteractionChainData, InteractionType, InteractionContext, RootInteraction, boolean)
- duplicate()
- getEntity()
- getOwningEntity()
- execute(RootInteraction)
- getChain()
- getEntry()
- getOperationCounter()
- setOperationCounter(int)
- jump(Label)
- getOriginalItemType()
- getHeldItemSectionId()
- getHeldItemContainer()
- getHeldItemSlot()
- getHeldItem()
- setHeldItem(ItemStack)
- createHeldItemContext()
- getInteractionVarsGetter()
- getInteractionVars()
- setInteractionVarsGetter(Function)
- getInteractionManager()
- getTargetEntity()
- getTargetBlock()
- getTargetBlockRaw()
- getMetaStore()
- getState()
- getClientState()
- getServerState()
- getInstanceStore()
- allowSkipChainOnClick()
- setLabels(Label[])
- hasLabels()
- getLabel(int)
- getSnapshot(Ref, ComponentAccessor)
- setSnapshotProvider(InteractionContext.SnapshotProvider)
- setTimeShift(float)
- getCommandBuffer()
- getRootInteractionId(InteractionType)
- toString()
- forProxyEntity(InteractionManager, Ref, Ref, ComponentAccessor)
- forInteraction(InteractionManager, Ref, InteractionType, ComponentAccessor)
- forInteraction(InteractionManager, Ref, InteractionType, int, ComponentAccessor)
- withoutEntity()
Class InteractionContext
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated.Only exists to support providing the data from the client -
Method Summary
Modifier and TypeMethodDescriptionbooleanCreates a duplicate of this interaction context.voidexecute(RootInteraction nextInteraction) Pushes the passed root interaction on to the stack and as the current root.static InteractionContextforInteraction(InteractionManager manager, Ref<EntityStore> ref, InteractionType type, int equipSlot, ComponentAccessor<EntityStore> componentAccessor) static InteractionContextforInteraction(InteractionManager manager, Ref<EntityStore> ref, InteractionType type, ComponentAccessor<EntityStore> componentAccessor) Returns an interaction context initialized with the correct held item for the given interaction type.fork(InteractionChainData data, InteractionType type, InteractionContext context, RootInteraction rootInteraction, boolean predicted) fork(InteractionType type, InteractionContext context, RootInteraction rootInteraction, boolean predicted) Forks from the current interaction into the passed interaction ids.fork(InteractionContext context, RootInteraction rootInteraction, boolean predicted) Forks from the current interaction into the passed interaction ids.static InteractionContextforProxyEntity(InteractionManager manager, Ref<EntityStore> entityRef, Ref<EntityStore> runningForEntity, ComponentAccessor<EntityStore> componentAccessor) getChain()Returns the current command buffer for this tick.getEntry()intbytegetLabel(int index) Returns the label at the given index.intReturns the current index into the operations list of the current root interaction.Returns the original item type that triggered the chainReturns the root interaction that would be run for the given interaction type.getSnapshot(Ref<EntityStore> ref, ComponentAccessor<EntityStore> componentAccessor) getState()booleanReturns whether this context currently has any labels set.voidChanges the operation counter to point to the given label so that the operation at that index will be run next.voidsetHeldItem(ItemStack heldItem) voidsetInteractionVarsGetter(Function<InteractionContext, Map<String, String>> interactionVarsGetter) voidSets the labels that will be returned fromgetLabel(int)calls.voidsetOperationCounter(int operationCounter) Sets the operation counter, changing the next operation that will be run.voidsetSnapshotProvider(InteractionContext.SnapshotProvider snapshotProvider) voidsetTimeShift(float shift) toString()static InteractionContext
-
Method Details
-
fork
@Nonnull public InteractionChain fork(@Nonnull InteractionContext context, @Nonnull RootInteraction rootInteraction, boolean predicted) Forks from the current interaction into the passed interaction ids.Calls
fork(InteractionType, InteractionContext, RootInteraction, boolean)with the type set to match the type of the currently running chain.See
InteractionManagerfor more information about how forks work.- Parameters:
context- The context to use for the forked interaction chain.rootInteraction- The interactions to run.- Returns:
- The forked chain.
- Throws:
IllegalArgumentException- If thecontextmatches the current context
-
fork
@Nonnull public InteractionChain fork(@Nonnull InteractionType type, @Nonnull InteractionContext context, @Nonnull RootInteraction rootInteraction, boolean predicted) Forks from the current interaction into the passed interaction ids.The chain will be run as if it was run by the given type. This means that input required for certain interactions (e.g. charging) will be the same as if that interaction type was run originally.
The context used cannot be the same as the current one, a new one must be created for the fork. If the type of the chain matches the current one then simply duplicating the current context is enough.
var chain = context.fork(context.duplicate(), forkInteractions, true); // Store the chain if needed // Next tick if (chain.getServerState() != InteractionState.NotFinished) { // Chain completed }If the type of interaction is different then creating new interactions via
forInteraction(InteractionManager, Ref, InteractionType, ComponentAccessor)is recommended so that the system has the correct inventory information.var contexts = Interaction.forInteraction(manager, ref, InteractionType.Secondary, componentAccessor); var chain = context.fork(InteractionType.Secondary, contexts[0], forkInteractions, true); // Store the chain if needed // Next tick if (chain.getServerState() != InteractionState.NotFinished) { // Chain completed }See
InteractionManagerfor more information about how forks work.- Parameters:
type- The interaction type that the new chain should be run ascontext- The context to use for the forked interaction chain.rootInteraction- The interactions to run.- Returns:
- The forked chain.
- Throws:
IllegalArgumentException- If thecontextmatches the current context
-
fork
@Nonnull public InteractionChain fork(@Nonnull InteractionChainData data, @Nonnull InteractionType type, @Nonnull InteractionContext context, @Nonnull RootInteraction rootInteraction, boolean predicted) -
duplicate
Creates a duplicate of this interaction context.This duplicate isn't a full clone and will only copy information that is useful for a forked interaction.
- Returns:
- The duplicate context.
-
getEntity
- Returns:
- the entity reference of the running entity
-
getOwningEntity
- Returns:
- the entity reference of the owner entity
-
execute
Pushes the passed root interaction on to the stack and as the current root.This will cause the chain execute the passed root interaction from this point onwards. Once the root interaction completes it will return back to the current root.
- Parameters:
nextInteraction- The root interaction to run.
-
getChain
- Returns:
- the interaction chain associated with this context
-
getEntry
- Returns:
- the interaction entry associated with this context
-
getOperationCounter
public int getOperationCounter()Returns the current index into the operations list of the current root interaction.- Returns:
- The index into the operations list of the current root interaction.
-
setOperationCounter
public void setOperationCounter(int operationCounter) Sets the operation counter, changing the next operation that will be run.Generally you should be either using
jump(Label)or letting the automatic incrementing set the operation counter.- Parameters:
operationCounter- The index to run next.
-
jump
Changes the operation counter to point to the given label so that the operation at that index will be run next.- Parameters:
label- The label to jump to.
-
getOriginalItemType
Returns the original item type that triggered the chain -
getHeldItemSectionId
public int getHeldItemSectionId() -
getHeldItemContainer
-
getHeldItemSlot
public byte getHeldItemSlot() -
getHeldItem
-
setHeldItem
-
createHeldItemContext
- Returns:
- an item context based on the held item of this context, if any
-
getInteractionVarsGetter
-
getInteractionVars
-
setInteractionVarsGetter
public void setInteractionVarsGetter(Function<InteractionContext, Map<String, String>> interactionVarsGetter) -
getInteractionManager
-
getTargetEntity
-
getTargetBlock
-
getTargetBlockRaw
-
getMetaStore
-
getState
-
getClientState
-
getServerState
-
getInstanceStore
-
allowSkipChainOnClick
public boolean allowSkipChainOnClick() -
setLabels
Sets the labels that will be returned fromgetLabel(int)calls.- Parameters:
labels- The labels to use.
-
hasLabels
public boolean hasLabels()Returns whether this context currently has any labels set.- Returns:
- Whether there are any labels set.
-
getLabel
Returns the label at the given index.- Parameters:
index- The index to lookup- Returns:
- The returned label.
-
getSnapshot
public EntitySnapshot getSnapshot(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor) -
setSnapshotProvider
-
setTimeShift
public void setTimeShift(float shift) -
getCommandBuffer
Returns the current command buffer for this tick.Only valid for the duration of the current interaction tick.
-
getRootInteractionId
Returns the root interaction that would be run for the given interaction type.This will look up the interaction on the currently held item or default to unarmed interactions if no item is held.
- Parameters:
type- The interaction type to lookup- Returns:
- The root interaction id or null.
-
toString
-
forProxyEntity
@Nonnull public static InteractionContext forProxyEntity(@Nonnull InteractionManager manager, @Nonnull Ref<EntityStore> entityRef, @Nonnull Ref<EntityStore> runningForEntity, @Nonnull ComponentAccessor<EntityStore> componentAccessor) -
forInteraction
@Nonnull public static InteractionContext forInteraction(@Nonnull InteractionManager manager, @Nonnull Ref<EntityStore> ref, @Nonnull InteractionType type, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Returns an interaction context initialized with the correct held item for the given interaction type.- Parameters:
ref- The entity this context is for.type- The type of interaction that this context is for.componentAccessor- The component accessor for component access- Returns:
- The created context.
-
forInteraction
@Nonnull public static InteractionContext forInteraction(@Nonnull InteractionManager manager, @Nonnull Ref<EntityStore> ref, @Nonnull InteractionType type, int equipSlot, @Nonnull ComponentAccessor<EntityStore> componentAccessor) -
withoutEntity
-