[API Bug] WrappedRegistrable `getKey` returns incorrect key
diogotcorreia opened this issue ยท 0 comments
- This issue is not solved in a development build
Describe the bug
When using WrappedRegistrable
, the MinecraftKey
returned by getKey
always corresponds to the default key of the registry (i.e., for BlockEntityType
this is always minecraft:furnance
).
In my case, I'm trying to do the following:
MinecraftKey tileEntityTypeKey = packet.getPacket().getBlockEntityTypeModifier().readSafely(0).getKey();
To Reproduce
assert WrappedRegistrable.blockEntityType("sign").getKey().getFullKey() == "minecraft:sign"
^^ this fails
Expected behavior
getKey
should return the key corresponding to the object in the registry.
Version Info
Probably not relevant, but here's the dump: https://bin.diogotc.com/erumyjodof.kt
I've tested this with the latest ProtocolLib dev build as of yesterday, in versions ranging from Paper/Spigot 1.18 to 1.20.6.
Additional context
Workaround:
Object tileEntityType = packet.getPacket().getBlockEntityTypeModifier().readSafely(0).getHandle();
MinecraftKey tileEntityTypeKey = WrappedRegistry.getRegistry(MinecraftReflection.getBlockEntityTypeClass()).getKey(tileEntityType);
I've already managed to fix this locally and I'll be submitting a PR soon, once I make sure I don't break anything.
It seems like this issue has been here since this class was added in #2111, and the root cause is the fieldAccessor
in the WrappedRegistrable.Factory
class, which doesn't seem to be needed.
There doesn't seem to exist any tests related to this class.