Class Event<T>

java.lang.Object
net.fabricmc.fabric.api.event.Event<T>
Type Parameters:
T - The listener type.

@NonExtendable public abstract class Event<T> extends Object
Base class for Fabric's event implementations.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final net.minecraft.resources.Identifier
    The identifier of the default phase.
    protected T
    The invoker field.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    final T
    Returns the invoker instance.
    void
    register(net.minecraft.resources.Identifier phase, T listener)
    Register a listener to the event for the specified phase.
    abstract void
    register(T listener)
    Register a listener to the event, in the default phase.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • invoker

      protected volatile T 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_PHASE
      The identifier of the default phase. Have a look at EventFactory.createWithPhases(Class, Function, Identifier...) for an explanation of event phases.
  • Constructor Details

    • Event

      public Event()
  • Method Details

    • invoker

      public final T 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

      public abstract void register(T listener)
      Register a listener to the event, in the default phase. Have a look at addPhaseOrdering(Identifier, Identifier) for an explanation of event phases.
      Parameters:
      listener - The desired listener.
    • register

      public void register(net.minecraft.resources.Identifier phase, T listener)
      Register a listener to the event for the specified phase. Have a look at EventFactory.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 to EventFactory.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.