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
Modifier and TypeFieldDescriptionstatic final net.minecraft.util.Identifier
The identifier of the default phase.protected T
The invoker field. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPhaseOrdering
(net.minecraft.util.Identifier firstPhase, net.minecraft.util.Identifier secondPhase) Request that listeners registered for one phase be executed before listeners registered for another phase.final T
invoker()
Returns the invoker instance.void
Register a listener to the event for the specified phase.abstract void
Register 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
public static final net.minecraft.util.Identifier DEFAULT_PHASEThe 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
public void addPhaseOrdering(net.minecraft.util.Identifier firstPhase, net.minecraft.util.Identifier secondPhase) 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.
-