So I’m trying to create an item stack with metadata i.e. wood type, durability, glass type, etc.
When the item information is given to the method I’m using to transform it, I don’t necessarily know the type, I know that each use of metadata (e.g. wood type, glass type, wool type, etc) has its own data, but is there a way to set the internal metadata to an integer? Or do I really have to handle every type of data myself?
There is no magic integer number that represents the data in the API.
Even if there was, you still would have to know the meaning of than number. If I tell you this item has a meta value of 3, what does that mean?
You will have to interpret the meaning anyway, so might as well make it easier by using the data types.
Although it would be lovely to have each data type specified, the problem I have is that it is loaded from a configuration, with a ‘meta data’ value. Although I could have a zillion different keys, it still doesn’t fix the problem that I have: needing to write a large method to determine the type of the item, and then use it to find the appropriate data, although it seems that’s what I’m going to have to do.
You can serialize an item stack to a configuration file and back again. There’s ItemStack.toContainer() and ItemStack.Builder.fromContainer() which will convert to/from a DataContainer.
You can then use ConfigurateTranslator to convert to/from config nodes
But the user is meant to enter the variables…
(also, out of curiosity, what does that actually look like? config wise. How does it know it was a serialized object?)
Oooh… Could I create a config node in memory that looks lime that and deserialize it to an itemstack? That way I could continue using the metadata as an int.
Just FYI though, damage values may soon become a thing of the past, and ContentVersions are VERY important for deserialization since any updates can potentially be handled by the implementation in SpongeCommon.
Yes, so long as the content version stays the same, if Sponge’s implementations dictate that the content version upgrades, then it’ll provide a content updater by default.