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 net.minecraft.resources.IdentifierThe identifier of the default phase.protected TThe invoker field. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPhaseOrdering(net.minecraft.resources.Identifier firstPhase, net.minecraft.resources.Identifier secondPhase) Request that listeners registered for one phase be executed before listeners registered for another phase.final Tinvoker()Returns the invoker instance.voidRegister 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
public static final net.minecraft.resources.Identifier DEFAULT_PHASEThe identifier of the default phase. Have a look atEventFactory.createWithPhases(Class, Function, 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(Identifier, 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(Class, Function, 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.resources.Identifier firstPhase, net.minecraft.resources.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(Class, Function, 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.
-