#Writing player inventory to config file

9 messages · Page 1 of 1 (latest)

crystal tartan
#

Hi,

I am just trying to store a 'PlayerInventory' object to a json file - or at least the contents of it all. I seem to be struggling with this a little and was hoping the broader community would have a good idea. I've been using Gson this entire time to write my objects to files as json which has been very nice and would like to keep it that way if possible. I tried using getNbt() calls on individual ItemStack's in the player inventory; however, it appears that can return null even if an item is in the stack (verified through printing out item name + getNbt == null)

Any ideas? Thanks.

bleak stream
#

why specifically json?

crystal tartan
#

I'm taking away a players inventory when they load into a dimension and storing it into a hash map and then I give it back to them when they leave the dimension

bleak stream
#

and why cant you use nbt for that?

crystal tartan
#

But the use case exists such that if the player logs out inside my dimension & the mod either crashes or server reboots then the data would be lost

#

well I tried but getNbt() was returning null on a stack of blocks

bleak stream
#

playerinventory has a method to write itself to an NbtList

crystal tartan
#

and getOrCreateNbt just produced empty maps too (it also seems like it's recommended not to use this)

#

oh does it?