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
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 -
Constructor Summary
ConstructorsConstructorDescriptionDynamicEventCallbackSource(@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 TypeMethodDescription@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.voidListens to the event in a way that data can replace.voidListens to the event in a way that data can replace.voidupdate(net.minecraft.resource.ResourceManager resourceManager) Updates the listeners with callbacks loaded from data.voidupdate(net.minecraft.resource.ResourceManager resourceManager, com.mojang.serialization.DynamicOps<com.google.gson.JsonElement> ops) Updates the listeners with callbacks loaded from data, using customDynamicOps.
-
Field Details
-
resourcePath
@NotNull protected final @NotNull net.minecraft.util.Identifier resourcePath -
codecs
-
callbackClass
-
event
-
combiner
-
-
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 callbackscodecs- delegates codecs to decode callbacks withcallbackClass- the class of the event callbackevent- the event to listen tocombiner- 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 datalistener- the callback to listen withphase- the phase to register the callback in
-
register
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 datalistener- 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 customDynamicOps. This is useful when loading using codecs that want aRegistryOpsor similar.- Parameters:
resourceManager- the resource manager to load data fromops- 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
-