Sponge icon indicating copy to clipboard operation
Sponge copied to clipboard

Custom Data - Key with Registry value doesn't serialize correctly

Open ItsDoot opened this issue 3 years ago • 4 comments

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

ItsDoot avatar Mar 01 '21 03:03 ItsDoot

How can the NBTTranslator know how to serialize your value? It does not know that it belongs to a registry.

Faithcaio avatar Mar 04 '21 17:03 Faithcaio

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

ItsDoot avatar Mar 04 '21 20:03 ItsDoot

Did...did you read the commented lines?

No it isn't working at all............

Zidane avatar Mar 04 '21 20:03 Zidane

This works for types registered in SpongeDataManager#findRegistryTypeFor

Faithcaio avatar May 08 '22 14:05 Faithcaio