Package net.fabricmc.fabric.api.event
Class Event<T>
java.lang.Object
net.fabricmc.fabric.api.event.Event<T>
- Type Parameters:
T- The listener type.
Base class for Fabric's event implementations.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IdentifierThe identifier of the default phase.protected TThe invoker field. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPhaseOrdering(Identifier firstPhase, Identifier secondPhase) Request that listeners registered for one phase be executed before listeners registered for another phase.final Tinvoker()Returns the invoker instance.voidregister(Identifier phase, T listener) Register a listener to the event for the specified phase.abstract voidRegister a listener to the event, in the default phase.
-
Field Details
-
invoker
The invoker field. This should be updated by the implementation to always refer to an instance containing all code that should be executed upon event emission. -
DEFAULT_PHASE
The identifier of the default phase. Have a look atEventFactory.createWithPhases(java.lang.Class<? super T>, java.util.function.Function<T[], T>, net.minecraft.util.Identifier...)for an explanation of event phases.
-
-
Constructor Details
-
Event
public Event()
-
-
Method Details
-
invoker
Returns the invoker instance.An "invoker" is an object which hides multiple registered listeners of type T under one instance of type T, executing them and leaving early as necessary.
- Returns:
- The invoker instance.
-
register
Register a listener to the event, in the default phase. Have a look ataddPhaseOrdering(net.minecraft.util.Identifier, net.minecraft.util.Identifier)for an explanation of event phases.- Parameters:
listener- The desired listener.
-
register
Register a listener to the event for the specified phase. Have a look atEventFactory.createWithPhases(java.lang.Class<? super T>, java.util.function.Function<T[], T>, net.minecraft.util.Identifier...)for an explanation of event phases.- Parameters:
phase- Identifier of the phase this listener should be registered for. It will be created if it didn't exist yet.listener- The desired listener.
-
addPhaseOrdering
Request that listeners registered for one phase be executed before listeners registered for another phase. Relying on the default phases supplied toEventFactory.createWithPhases(java.lang.Class<? super T>, java.util.function.Function<T[], T>, net.minecraft.util.Identifier...)should be preferred over manually registering phase ordering dependencies.Incompatible ordering constraints such as cycles will lead to inconsistent behavior: some constraints will be respected and some will be ignored. If this happens, a warning will be logged.
- Parameters:
firstPhase- The identifier of the phase that should run before the other. It will be created if it didn't exist yet.secondPhase- The identifier of the phase that should run after the other. It will be created if it didn't exist yet.
-