fabric icon indicating copy to clipboard operation
fabric copied to clipboard

Add a tracked data handler registry

Open haykam821 opened this issue 2 years ago • 4 comments

This pull request introduces a new API for registering tracked data handlers, which reduces conflicts between mods registering tracked data handlers in an order that is inconsistent between clients and servers.

To use the API, simply replace usages of the vanilla method:

- TrackedDataHandlerRegistry.register(TRACKED_DATA_HANDLER);
+ FabricTrackedDataRegistry.registerHandler(TRACKED_DATA_HANDLER_ID, TRACKED_DATA_HANDLER);

An example of a mod introducing tracked data handlers is provided within the test mod. This entity uses tracked data handlers for global positions, items, and optional item groups, all of which are not available as one of the vanilla tracked data handlers.

A few remarks regarding the implementation of this API:

  • Documentation has not been written yet.
  • Note that the class name is FabricTrackedDataRegistry rather than FabricTrackedDataHandlerRegistry so that tracked data support can be added in the future within the same class; see #1049 for more information.
  • Each registration recomputes the map used by vanilla. I'm not sure whether optimizing this behavior is worthwhile; the work required to delay computation until the map is accessed would be more invasive than the current setup.
  • Mods that do not switch to this API will still work as before. Said mods will not gain the benefits of using this API and will still lack a guarantee of tracked data handlers matching between clients and servers.
  • There isn't any guard against registering a tracked data handler after mod initialization. Should one be added? Currently, the unspoken idea is that mods will only use this API during mod initialization.
  • Mods assuming that tracked data handler IDs are stable during mod initialization (or possibly later, per the last remark) will be broken. I assume this breakage is fine, as I doubt many mods interact with tracked data handlers in this way.

Fixes #3482

haykam821 avatar Feb 11 '24 00:02 haykam821

would it be beneficial to add a warning if a non-vanilla handler is registered? (outside of the api)

Linguardium avatar Feb 17 '24 23:02 Linguardium

@Linguardium A warning already will be logged in that scenario.

haykam821 avatar Feb 18 '24 00:02 haykam821

Yep, i missed that

Linguardium avatar Feb 18 '24 00:02 Linguardium

@haykam821 are you intrested in finishing this off? I dont think there was anything too crazy left to do on it.

modmuss50 avatar Apr 04 '24 14:04 modmuss50

Superseded by #4599.

PepperCode1 avatar May 06 '25 13:05 PepperCode1