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:
EventFactory
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static net.minecraft.util.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.util.Identifier firstPhase, net.minecraft.util.Identifier secondPhase)
    Request that listeners registered for one phase be executed before listeners registered for another phase.
    Returns the invoker instance.
    void
    register​(net.minecraft.util.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 java.lang.Object

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

  • 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(net.minecraft.util.Identifier, net.minecraft.util.Identifier) for an explanation of event phases.
      Parameters:
      listener - The desired listener.
    • register

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