Hello! I am looking for a way to store an ItemStack or ItemStackSnapshot in MySQL so that I can later retentive it.
I have looked through the docs and older posts but I can’t seem to get anything working.
Any suggestions on how to do this are appreciated!
You would figure out how you want to serialize it, and then do so. There are mechanisms in Sponge for serializing them, but only to deep structures. An ItemStack would be extremely difficult to serialize to a finite, static series of values, because it can contain arbitrary data, both within vanilla and through plugins. But the solution to a problem with no solution is often to focus on a different problem. Thus: Why is it that you need to write an ItemStack to a SQL database?
After a few hours of testing I figured out that my best option of keeping certain data of an item stored is by either saving the itemstack itself or the ItemStackSnapshot, either works. I am doing this because there is really no other easy way. The items my plugin will work with are both vanilla and modded items.
Doesn’t really answer my question - what is it for? If you’re trying to persist item key data specifically, then there is no way you can store it properly in a relational database - it would only be able to store basic things like ID and data value, things common to every item. But I’m still wondering why this needs to be in a database. If the item doesn’t leave the server, a database is unnecessary - all custom data gets saved on the item. If it does, it would best be transferred via NBT .dat files. If you truly need some sort of database, look into MongoDB or some other nonrelational database.