Posts: 952
Threads: 16
Joined: May 2013
Thanks: 66
Given 105 thank(s) in 89 post(s)
Because Minecraft uses NBT.
Posts: 16
Threads: 1
Joined: May 2016
Thanks: 0
Given 4 thank(s) in 4 post(s)
05-25-2016, 12:30 AM
(This post was last modified: 05-25-2016, 12:32 AM by Seyaku.)
I don't think the fact that minecraft uses NBT is relevant in this matter. Fact is we need a generic solution for storing any kind of metadata for items, which can be converted to both NBT and Json.
Some ways of doing that are:
-Add a storage class (like I did before)
-Use Json::Value (like I'm doing now)
-Add new fields for all items that have extra metadata (like what is done with fireworks, but personally I think this is a really bad design and is more of a quick hack)
-Store as raw data (could be NBT data or a struct)
Posts: 952
Threads: 16
Joined: May 2013
Thanks: 66
Given 105 thank(s) in 89 post(s)
I mentioned NBT to discourage further use of JSON in on-disk storage, as per FS#359. I agree that in memory, adding fields to cItem which does not bear relevance to most items is unsustainable.
I propose that, for the latter, some form of native method (i.e. not JSON or NBT) should be used (preferably a class containing member variables and a ToNBT function, see cFireworkItem), since methods of serialisation or encoding for storage is unsuitable for working data.
Posts: 952
Threads: 16
Joined: May 2013
Thanks: 66
Given 105 thank(s) in 89 post(s)
Nevertheless, I would argue that it would be strange to be accessing, manipulating, and working with a data structure represented in JSON when it can be effectively done in a pure C++ way.
I would suggest that the class inheritance proposed by Seyaku would work well, though I don't think the To/FromJSON functions will be used anywhere.
Posts: 16
Threads: 1
Joined: May 2016
Thanks: 0
Given 4 thank(s) in 4 post(s)
05-25-2016, 07:33 AM
(This post was last modified: 05-25-2016, 08:02 AM by Seyaku.)
Ok, did some final testing and tweaking and everything appears to work properly. Once a decision has been made regarding the metadata, I will implement that and make it ready for a pull request.