Class InteractionEventDispatcher

java.lang.Object
com.pixelmonmod.pixelmon.api.npc.interaction.event.InteractionEventDispatcher

public final class InteractionEventDispatcher extends Object
Dispatches interaction-event consumers through a trigger-key index.

This is intended for datapack-backed registries whose entries each declare the InteractionEvents that should trigger them. Instead of scanning an entire registry for every interaction event, callers provide a registry, a trigger extractor, and a handler. The dispatcher builds and caches an index from interaction event key to matching registry values.

  • Method Details

    • dispatchRegistry

      public static <T> void dispatchRegistry(net.minecraft.resources.ResourceKey<net.minecraft.core.Registry<T>> registryKey, net.minecraft.core.Holder<InteractionEvent> event, StoredContext context, Function<T,Collection<net.minecraft.resources.ResourceKey<InteractionEvent>>> triggers, InteractionEventDispatcher.RegistryHandler<T> handler)
      Dispatches a registry-backed interaction consumer to entries that are registered for the fired interaction event.

      The index is created lazily per registry key and reused while the same backing registry instance is active. If datapacks reload and the registry instance changes, the index is rebuilt on the next dispatch.

      Type Parameters:
      T - the registry value type
      Parameters:
      registryKey - the registry containing interaction consumers
      event - the interaction event that fired
      context - the context collected for the interaction event
      triggers - extracts the interaction event keys each registry value listens to
      handler - handles a matching registry value
    • clear

      public static void clear()
      Clears every cached registry index.

      This is normally not required because indexes rebuild automatically when the backing registry instance changes. It exists for tests and for lifecycle hooks that want to force a cold rebuild.