Sponge
Sponge copied to clipboard
Custom Data - Key with Registry value doesn't serialize correctly
Issue Description
Registering a data.Key<Value<Foo>>
where Foo
is some registry value type doesn't serialize correctly without manually specifying the serializer and deserializer.
That is, this doesn't work:
class Foo {}
RegistryType<Foo> fooRegistry;
@Listener
public void onRegisterRegistry(RegisterRegistryEvent event) {
fooRegistry = event.register(ResourceKey.sponge("foo"), false);
}
@Listener
public void onRegisterRegistryValue(RegisterRegistryValueEvent event) {
event.registry(fooRegistry).register(ResourceKey.of("foo", "foo"), new Foo());
}
@Listener
public void onRegisterData(RegisterDataEvent event) {
Key<Value<Foo>> myKey = Key.of(ResourceKey.of("foo", "foo"), new TypeToken<Foo>() {});
event.register(DataRegistration.of(myKey, Player.class));
}
Error output, using Key<Value<Kit>>
in my case
https://gist.github.com/ItsDoot/045be7301b4e3c08dfc013864688f5c3
How can the NBTTranslator know how to serialize your value? It does not know that it belongs to a registry.
Well, the MemoryDataView seems like it should know how to serialize, but doesn't work properly: https://github.com/SpongePowered/Sponge/blob/5a0778bc25a66ea96b6799e6c347b65aa4473592/src/main/java/org/spongepowered/common/data/MemoryDataView.java#L271-L281
Did...did you read the commented lines?
No it isn't working at all............
This works for types registered in SpongeDataManager#findRegistryTypeFor