Class DynamicEventCallbackSource<T extends CodecAware>

java.lang.Object
org.quiltmc.qsl.data.callback.api.DynamicEventCallbackSource<T>
Type Parameters:
T - the type of the event callback

public class DynamicEventCallbackSource<T extends CodecAware> extends Object
Provides a single callback per phase for an event that collects both callbacks with identifiers provided in code and callbacks provided by datapacks. Additionally, contains logic to load callbacks from a resource manager. This tool keeps information about event phases alongside registered callbacks, so that a given identifier uniquely identifies a callback even across phases.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final @NotNull Class<T>
     
    protected final @NotNull CodecMap<T>
     
    protected final Function<Supplier<T[]>,T>
     
    protected final Event<T>
     
    protected final @NotNull net.minecraft.util.Identifier
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DynamicEventCallbackSource(@NotNull net.minecraft.util.Identifier resourcePath, @NotNull CodecMap<T> codecs, @NotNull Class<T> callbackClass, Event<T> event, Function<Supplier<T[]>,T> combiner)
    Creates a new callback source that listens to a given event and loads from a provided resource path.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull com.mojang.serialization.Codec<com.mojang.datafixers.util.Pair<net.minecraft.util.Identifier,T>>
    Returns the codec used to decode resources; can be used to re-encode callbacks.
    void
    register(net.minecraft.util.Identifier id, T listener)
    Listens to the event in a way that data can replace.
    void
    register(net.minecraft.util.Identifier id, T listener, net.minecraft.util.Identifier phase)
    Listens to the event in a way that data can replace.
    void
    update(net.minecraft.resource.ResourceManager resourceManager)
    Updates the listeners with callbacks loaded from data.
    void
    update(net.minecraft.resource.ResourceManager resourceManager, com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> ops)
    Updates the listeners with callbacks loaded from data, using custom DynamicOps.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • DynamicEventCallbackSource

      public DynamicEventCallbackSource(@NotNull @NotNull net.minecraft.util.Identifier resourcePath, @NotNull @NotNull CodecMap<T> codecs, @NotNull @NotNull Class<T> callbackClass, Event<T> event, Function<Supplier<T[]>,T> combiner)
      Creates a new callback source that listens to a given event and loads from a provided resource path. For instance, if the resource path is "quilt:my_callbacks", then callbacks will be loaded under the identifier "<namespace>:<path>" from "<namespace>/quilt/my_callbacks/<path>.json".
      Parameters:
      resourcePath - the path to the resource directory containing callbacks
      codecs - delegates codecs to decode callbacks with
      callbackClass - the class of the event callback
      event - the event to listen to
      combiner - a function for combining multiple callbacks registered to this and loaded from data to a single callback
  • Method Details

    • register

      public void register(net.minecraft.util.Identifier id, T listener, net.minecraft.util.Identifier phase)
      Listens to the event in a way that data can replace. A given identifier can only have one callback associated with it for any given callback source.
      Parameters:
      id - the identifier of the callback, to be used when replacing it in data
      listener - the callback to listen with
      phase - the phase to register the callback in
    • register

      public void register(net.minecraft.util.Identifier id, T listener)
      Listens to the event in a way that data can replace.
      Parameters:
      id - the identifier of the callback, to be used when replacing it in data
      listener - the callback to listen with
    • update

      public void update(net.minecraft.resource.ResourceManager resourceManager)
      Updates the listeners with callbacks loaded from data.
      Parameters:
      resourceManager - the resource manager to load data from
    • update

      public void update(net.minecraft.resource.ResourceManager resourceManager, com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> ops)
      Updates the listeners with callbacks loaded from data, using custom DynamicOps. This is useful when loading using codecs that want a RegistryOps or similar.
      Parameters:
      resourceManager - the resource manager to load data from
      ops - the dynamic ops to use to decode data
    • getCodec

      @NotNull public @NotNull com.mojang.serialization.Codec<com.mojang.datafixers.util.Pair<net.minecraft.util.Identifier,T>> getCodec()
      Returns the codec used to decode resources; can be used to re-encode callbacks.
      Returns:
      the codec used to decode resources; can be used to re-encode callbacks