Skip to content

Instantly share code, notes, and snippets.

@Machine-Maker
Created June 17, 2024 02:15
Show Gist options
  • Save Machine-Maker/2bc29c2d5468a276ceab1d8c10925d0f to your computer and use it in GitHub Desktop.
Save Machine-Maker/2bc29c2d5468a276ceab1d8c10925d0f to your computer and use it in GitHub Desktop.
Lifecycle Tag Modification API

The need to modify tags within the game is increasing every update as more functionality is controlled by them.

Tags are registered after all registries have been frozen but before the JavaPlugin system has been initialized which requires, then, hooking into it with our Lifecycle Event API. Tags are then reloaded on a /minecraft:reload. Tags can also be changed at runtime with updating the client to these changes as simple as sending an update tags packet. For now, we will just focus on the event for handling regisration, and focus on modifcatons at any time later.

There are at least 3 spots that plugins might want to hook into tag loading and I'm not sure which combination should have specific events.

Per Tag

There could be an event that is fired per tag per registry. The only context available in this event would be the specific tag key of the tag being loaded, and the elements in the tag (which can be tags themselves). This would provide the simplest way to add/remove either specific elements or nested tags from that tag, but you lose out on the context of what a nested tag itself might contain.

Pre-flattening

After all the tags for a specific registry are loaded, they are stored in a structure like Map<TagKey, Collection<TagOrResourceLocation>>. Firing an event at this point would let plugins add/remove elements knowing the full context, but there is at least one thing they can't do which is remove a specific element that is added via a nested tag.

Post-flattening

After the tags have been "flattened", that is all nested tags have had their elements added directly to each tag, we have a Map<TagKey, Collection<ResourceLocation>. An event here has full control over the exact final outcome of tag loading, but you don't know what, if any, nested tags where used to create the final collection for the tags.

Notes

The registry API has 2 events, one fired for each "entry" being added to the registry, and another after all have been added which provides a mechanism to add entierly new entries. It may be desirable to keep some similarity to this system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment