Class InteractionEventDispatcher
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.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()Clears every cached registry index.static <T> voiddispatchRegistry(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.
-
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 consumersevent- the interaction event that firedcontext- the context collected for the interaction eventtriggers- extracts the interaction event keys each registry value listens tohandler- 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.
-