So I have just begun to try and implement some Data API stuff - and I’ve hit a block. Basically, I have no idea what to do from here. I added SpongeForge as a dependency so I can use the SpongeCommon abstractions (I’ll remove that once the API has its own abstractions), and I’ve implemented Data Manipulators, but now I don’t know what to do. I think I need DataBuilders, and I’m pretty sure I need to register them, but I don’t know how.
Note:
The object my Data stores is singular, and can be serialized to and from a String, I assume I can use this in some way.
For starters, you don’t need to make your own StarKeyRegistry since you can easily use KeyFactory.createFoo etc. The only reason why they are null in the API is because they’re not defined except in implementation.
With regards to the DataManipulatorBuilder aspect is you need to implement that and use the Sponge.getManipulatorRegistry().register() preferably during GameState.INIT.
@gabizou
I’m not quite sure if I’m doing this right. The following is my implementation of DataManipulatorBuilder:
I’m not sure I’ve implemented it right, and do I need to write an immutable one as well?
EDIT: After looking around in some implementations from SpongeCommon, I’m sure I’m implementing it wrong - but I don’t know how to implement them right. In the SpongeCommon implementations they just refer to the Vanilla data, but custom data isn’t vanilla. Also, I’ve added an ImmutableDataManipulatorBuilder as well
EDIT 2: Using AuthorData as an example, I’ve filled in some methods, and removed ImmutableDataManipulatorBuilder, however I’m still not sure what to do in the ‘createFrom’ method. In addition, were do I need a ‘write’ method that saves the data. Am I missing any classes required for serialization of the data? I’ve updated the code on GitHub, found at this link: https://github.com/SocraticPhoenix/StarAPI/tree/master/src/main/java/com/gmail/socraticphoenix/sponge/star/data