Class RegistryTracker
java.lang.Object
org.moddingx.libx.registration.tracking.RegistryTracker
Provides a way to track the values of fields with a registry object. That means if the registry object is
replaced, the field is updated.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> void
run
(net.minecraftforge.registries.IForgeRegistry<T> registry, Consumer<T> action, Object instance, net.minecraft.resources.ResourceLocation id) Add an action that is invoked whenever the object with the given id changes in the registry.static <T> void
track
(net.minecraftforge.registries.IForgeRegistry<T> registry, Field field, Object instance, net.minecraft.resources.ResourceLocation id) Add an instance field to the list of tracked fields.static <T> void
track
(net.minecraftforge.registries.IForgeRegistry<T> registry, Field field, net.minecraft.resources.ResourceLocation id) Add a static field to the list of tracked fields.
-
Constructor Details
-
RegistryTracker
public RegistryTracker()
-
-
Method Details
-
track
public static <T> void track(net.minecraftforge.registries.IForgeRegistry<T> registry, Field field, net.minecraft.resources.ResourceLocation id) Add a static field to the list of tracked fields. It will then be updated whenever the registry value changes. This will not ensure the field holds the value matching the registry at the time, the method is called.- Parameters:
registry
- The registry used to track the field.field
- The field to track.id
- TheResourceLocation
used for registered the object
-
track
public static <T> void track(net.minecraftforge.registries.IForgeRegistry<T> registry, Field field, Object instance, net.minecraft.resources.ResourceLocation id) Add an instance field to the list of tracked fields. It will then be updated whenever the registry value changes. This will not ensure the field holds the value matching the registry at the time, the method is called. If the object instance is garbage collected, the tracking will be removed. If a field is tracked inRegisterable.initTracking(RegistrationContext, Registerable.TrackingCollector)
and the tracking of theRegisterable
is initialised because the parent object changed due to registry tracking, it will be ensured, that the field is updated as soon as possible to reflect the current registry change. This does not hold true if the tracking is initialised during first registering.- Parameters:
registry
- The registry used to track the field.field
- The field to track.instance
- The object instance on which the field is updated.id
- TheResourceLocation
used for registered the object
-
run
public static <T> void run(net.minecraftforge.registries.IForgeRegistry<T> registry, Consumer<T> action, Object instance, net.minecraft.resources.ResourceLocation id) Add an action that is invoked whenever the object with the given id changes in the registry. The action is tied to an instance object and won't be called any longer if the instance object is garbage collected. hold true if the tracking is initialised during first registering.- Parameters:
registry
- The registry used to track the field.action
- The action to run when the object updates in the registry.instance
- The object instance to which the action is tied.id
- TheResourceLocation
used for registered the object
-