Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registry API - Tag events seems broken in 1.21.2/3 #11577

Open
MiraculixxT opened this issue Nov 4, 2024 · 6 comments · May be fixed by #11606
Open

Registry API - Tag events seems broken in 1.21.2/3 #11577

MiraculixxT opened this issue Nov 4, 2024 · 6 comments · May be fixed by #11606
Labels
status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. type: bug Something doesn't work as it was intended to. version: 1.21.3 Game version 1.21.3

Comments

@MiraculixxT
Copy link

Expected behavior

Creating a new typed key and registering it via the registerEventHandler should allow using those keys inside all further postFlatteners of the same type.

Observed/Actual behavior

Using such typed key after registering still throws startup errors on usage, that the key does not exist.

Error: https://pastes.dev/WNd63g7agt

Steps/models to reproduce

Using the following code flow triggers the error for KEY1 on enchantment example.

final var KEY1 = TypedKey.create(RegistryKey.ENCHANTMENT, Key.key("namespace:key1"))

LifecycleEventManager<BootstrapContext> manager = context.getLifecycleManager();
manager.registerEventHandler(RegistryEvents.ENCHANTMENT.freeze().newHandler(event -> 
    event.registry().register(KEY1, builder -> { ... })
)));

manager.registerEventHandler(LifecycleEvents.TAGS.postFlatten(RegistryKey.ENCHANTMENT), event -> {
    final PostFlattenTagRegistrar<Enchantment> registrar = event.registrar();
    registrar.addToTag(EnchantmentTagKeys.TRADEABLE, Set.of(KEY1)); // IllegalArgumentException thrown on startup
});

Plugin and Datapack List

None

Paper version

This server is running Paper version 1.21.3-12-master@c6aa61e (2024-11-04T17:51:59Z) (Implementing API version 1.21.3-R0.1-SNAPSHOT)
You are running the latest version

Other

Using the preFlattener seems to work as a workaround for now

@MiraculixxT MiraculixxT added status: needs triage type: bug Something doesn't work as it was intended to. labels Nov 4, 2024
@papermc-sniffer papermc-sniffer bot added the version: 1.21.3 Game version 1.21.3 label Nov 4, 2024
@papermc-projects papermc-projects bot moved this to 🕑 Needs Triage in Issues: Bugs Nov 4, 2024
@lynxplay lynxplay added status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. and removed status: needs triage labels Nov 4, 2024
@papermc-projects papermc-projects bot moved this from 🕑 Needs Triage to ✅ Accepted in Issues: Bugs Nov 4, 2024
@lynxplay
Copy link
Contributor

lynxplay commented Nov 4, 2024

Caused by mojang now flattening the tags and binding them before freezing the registries as tags are part of the freezing logic in 1.21.2+.
As such the freeze event is called after the post flatten event, which leads to this explosion.
I am unsure what our move forward here is, especially for future proofing this API to avoid something like this.
Will get some more input.

@Machine-Maker Machine-Maker changed the title Regristry API - Tag events seems broken in 1.21.2/3 Registry API - Tag events seems broken in 1.21.2/3 Nov 9, 2024
@Machine-Maker
Copy link
Member

I think the solution is to just move where we call the freeze event up a bit, and then decide on a better name for that. It was never really about the "freezing", more about the ability to add more values to the registry, so some name separate from freezing would be good. Can deprecate for removal the old event and remove in a version (since its still experimental)

@MiraculixxT
Copy link
Author

Would this new event be a pure rename or also add changes to the behavior and usage?

@Machine-Maker
Copy link
Member

Nah, just a rename really. Looking back, tying the name to "freeze" wasn't a good idea, it's just an event to add new stuff, has nothing to do with the freezing of the registries really. But this is what experimental is for. We'd keep the old event for compat for like a version or 2 while deprecated and then remove it.

@Machine-Maker Machine-Maker linked a pull request Nov 11, 2024 that will close this issue
@Machine-Maker
Copy link
Member

@MiraculixxT in a few minutes, try downloading the build provided here and running your plugin on it to make sure it fixes the issue you had.

@MiraculixxT
Copy link
Author

This fixes the issue! No errors on startup and all registries and modifications seems to be applied. Thank you very much for the quick fix!
(Sorry for the delayed response)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. type: bug Something doesn't work as it was intended to. version: 1.21.3 Game version 1.21.3
Projects
Status: ✅ Accepted
Development

Successfully merging a pull request may close this issue.

3 participants