Class InteractionEvent
java.lang.Object
com.pixelmonmod.pixelmon.api.npc.interaction.event.InteractionEvent
- Direct Known Subclasses:
EmptyInteractionEvent
,HitWithPokeBallInteractionEvent
,LeftClickEntityInteractionEvent
,RightClickEntityInteractionEvent
This represents an entry point for the NPC logic flow.
Implementations of this class should not dictate when the logic executes, just pass the relevant context through to the NPC involved in the event and allow the data defined conditions to handle the rest.
To pass the interaction to the NPC use {@link this#triggerInteraction(InteractionContext)}
All contexts should be created using the {@link this#createContext(NPC)} as it provides a set of default contexts from the
To register interaction events look at the
Implementations of this class should not dictate when the logic executes, just pass the relevant context through to the NPC involved in the event and allow the data defined conditions to handle the rest.
To pass the interaction to the NPC use {@link this#triggerInteraction(InteractionContext)}
All contexts should be created using the {@link this#createContext(NPC)} as it provides a set of default contexts from the
NPC
that will likely be used
later in the control flow.
To register interaction events look at the
PixelmonRegistry
class.-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionInteractionEvent
(Class<A> eventClass, BiConsumer<InteractionEvent, A> eventHandler, net.minecraftforge.eventbus.api.IEventBus... buses) Constructor allowing a lambda to be used as the event handler rather than creating your own class extending theInteractionEvent
This constructor will register the lambda to the event buses provided as aEventPriority.NORMAL
and receiving canceled events.protected
InteractionEvent
(net.minecraftforge.eventbus.api.IEventBus... buses) Default constructor taking the registry ID of the interaction event along with the buses to register the class to for simplicity -
Method Summary
Modifier and TypeMethodDescriptioncreateContext
(NPC npc) Creates a basicInteractionContext
using the provided NPCnet.minecraft.resources.ResourceLocation
id()
First attempts to get the registry ID of this interaction event from thePixelmonRegistry.getInteractionEvents()
, to cache and return laterboolean
triggerInteraction
(InteractionContext context) Triggers the interaction using the provided context for the NPC found in the context
-
Field Details
-
CODEC
-
-
Constructor Details
-
InteractionEvent
protected InteractionEvent(net.minecraftforge.eventbus.api.IEventBus... buses) Default constructor taking the registry ID of the interaction event along with the buses to register the class to for simplicity- Parameters:
buses
- the event buses
-
InteractionEvent
public InteractionEvent(Class<A> eventClass, BiConsumer<InteractionEvent, A> eventHandler, net.minecraftforge.eventbus.api.IEventBus... buses) Constructor allowing a lambda to be used as the event handler rather than creating your own class extending theInteractionEvent
This constructor will register the lambda to the event buses provided as aEventPriority.NORMAL
and receiving canceled events.- Type Parameters:
A
- The event type- Parameters:
eventClass
- The class to listen foreventHandler
- The handling fo the eventbuses
- The bus to listen on
-
-
Method Details
-
id
public net.minecraft.resources.ResourceLocation id()First attempts to get the registry ID of this interaction event from thePixelmonRegistry.getInteractionEvents()
, to cache and return later- Returns:
- The registry ID
-
createContext
Creates a basicInteractionContext
using the provided NPC- Parameters:
npc
- the NPC- Returns:
- the created context
-
triggerInteraction
Triggers the interaction using the provided context for the NPC found in the context- Parameters:
context
- The interaction context
-