Class InteractionEvent

java.lang.Object
com.pixelmonmod.pixelmon.api.npc.interaction.event.InteractionEvent
Direct Known Subclasses:
HitWithPokeBallInteractionEvent, LeftClickEntityInteractionEvent, RightClickEntityInteractionEvent

public class InteractionEvent extends Object
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 NPC that will likely be used later in the control flow.
To register interaction events look at the PixelmonRegistry class.
  • Field Details

    • CODEC

      public static final com.mojang.serialization.Codec<InteractionEvent> 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 the InteractionEvent
      This constructor will register the lambda to the event buses provided as a EventPriority.NORMAL and receiving canceled events.
      Type Parameters:
      A - The event type
      Parameters:
      eventClass - The class to listen for
      eventHandler - The handling fo the event
      buses - 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 the PixelmonRegistry.getInteractionEvents(), to cache and return later
      Returns:
      The registry ID
    • createContext

      public InteractionContext createContext(NPC npc)
      Creates a basic InteractionContext using the provided NPC
      Parameters:
      npc - the NPC
      Returns:
      the created context
    • triggerInteraction

      public boolean triggerInteraction(InteractionContext context)
      Triggers the interaction using the provided context for the NPC found in the context
      Parameters:
      context - The interaction context