ProtocolLib

3M Downloads

Cannot get `DATA_COMPONENT_TYPE` WrappedRegistrable in 1.21

diogotcorreia opened this issue ยท 0 comments

commented
  • This issue is not solved in a development build

Describe the bug
In 1.21, the net.minecraft.core.registries.BuiltInRegistries seems to have two registries with type DataComponentType: the DATA_COMPONENT_TYPE (which already existed in 1.20.6) and the ENCHANTMENT_EFFECT_COMPONENT_TYPE.

Unfortunately for me, it seems like the logic in WrappedRegistry returns the latter when doing WrappedRegistry.getRegistry(MinecraftReflection.getMinecraftClass("core.component.DataComponentType")), as evidenced by:
image

To Reproduce
Steps to reproduce the behavior:

Class<?> DATA_COMPONENT_TYPE = MinecraftReflection.getMinecraftClass("core.component.DataComponentType");
WrappedRegistrable.fromClassAndKey(DATA_COMPONENT_TYPE, "lore");

causes exception

Exception java.lang.IllegalArgumentException: handle cannot be NULL. [in thread "Triton Async Packet Handler"]
        at ProtocolLib.jar/com.comphenix.protocol.wrappers.AbstractWrapper.setHandle(AbstractWrapper.java:29) ~[ProtocolLib.jar:?]
        at ProtocolLib.jar/com.comphenix.protocol.wrappers.WrappedRegistrable.<init>(WrappedRegistrable.java:45) ~[ProtocolLib.jar:?]
        at ProtocolLib.jar/com.comphenix.protocol.wrappers.WrappedRegistrable.fromHandle(WrappedRegistrable.java:53) ~[ProtocolLib.jar:?]
        at ProtocolLib.jar/com.comphenix.protocol.wrappers.WrappedRegistrable.fromClassAndKey(WrappedRegistrable.java:70) ~[ProtocolLib.jar:?]
        at ProtocolLib.jar/com.comphenix.protocol.wrappers.WrappedRegistrable.fromClassAndKey(WrappedRegistrable.java:78) ~[ProtocolLib.jar:?]
        at Triton.jar/com.rexcantor64.triton.wrappers.items.WrappedPatchedDataComponentMap.<clinit>(WrappedPatchedDataComponentMap.java:43) ~[Triton.jar:?]

Expected behavior
I'm not sure how to fix this. Afaik, this is the first time there are two distinct registries with the same class.
I'm going to try to find a workaround for my plugin quickly (and I'll post it here when I do), but I don't think that would be appropriate to include in ProtocolLib.
One idea I have is to use the key of the Registry (i.e., from the net.minecraft.core.registries.Registries class), but I'm not sure if that would work for old(er) Minecraft versions.

Version Info
https://pastebin.com/6kKvT0xc