Multiverse-Inventories

878k Downloads

Help with converting shulker box NBT -> json

NQNStudios opened this issue ยท 3 comments

commented

My situation is similar to the one described in issue #88. I have a server with several player inventories saved in the vanilla NBT format, and need to migrate those players' inventories/stats/enderchests to Multiverse-Inventories json format.

To do this, I've started writing a python script which uses an nbt library to load the player nbt files and manually write out a json file containing the info I parse out of the nbt. I've been reverse-engineering the MVI json format in order to do this, and so far I've successfully converted an NBT file for a player with items and ender items.

I ran into a problem converting shulker boxes, though. Every other item I've needed to convert has been straightforwardly represented in MVI Json, but I see that the MVI output for a shulker box is something like this:

{
    "==": "org.bukkit.inventory.ItemStack",
    "type": "PURPLE_SHULKER_BOX",
    "meta": {
        "==": "ItemMeta",
        "meta-type": "TILE_ENTITY",
        "display-name": "b box",
        "internal":
 "H4sIAAAAAAAAAE3LsQ4BQRAG4P+WlbMFjUrlOVTiKDQaetm7G5uN3ZnEzSW8vUsQvv5zgMNsm6S57VmjPs8+lHBV36nko88EW69qeUxhD0q5cwBMgfEpiaKEiS3mOTI1d3\/V9ZCYCthKetaNwWTnsw80nE9ZvsviV4Kk9hI5iH7f6P8BL3trGk+iAAAA",
        "blockMaterial": "PURPLE_SHULKER_BOX"
    }
}

Unlike with inventory, armorContents, and enderChestContents, I have no idea how this json is representing the shulker box's contents. Is that long string somehow a compressed representation? Is it a base-64 representation of the ShulkerBox BlockState?

commented

This is a rather old issue, but it still comes up from time to time.

As mentioned above, the "internal" string is indeed Base64, and it is a representation of the Shulker ItemMeta NBT.

So, to get the contents of the Shulker Box, all you have to do is convert that Base64 string into a file, and then open it up using an NBT viewer. I used https://base64.guru/converter/decode/file and https://github.com/jaquadro/NBTExplorer with success.

Note that when using the Base64 string on any site (or anywhere for that matter), the backslashes must be removed as they are not valid characters in Base64. They're most likely only there as an escape character.

How did you manage to do this? I'm not particularly adept in coding or anything, and all I have is the internal strings for quite a few shulkerboxes which i've lost in attempting to update a multiverse server from 1.17 to 1.18

@nicegamer7

commented

Bukkit is doing the serialization. If I remember correctly it IS base 64 but I don't know exactly what it's representing. I seem to remember that if you add any custom NBT tags to an ItemStack they will be converted encoded in base 64 or something.

commented

This is a rather old issue, but it still comes up from time to time.

As mentioned above, the "internal" string is indeed Base64, and it is a representation of the Shulker ItemMeta NBT.

So, to get the contents of the Shulker Box, all you have to do is convert that Base64 string into a file, and then open it up using an NBT viewer. I used https://base64.guru/converter/decode/file and https://github.com/jaquadro/NBTExplorer with success.

Note that when using the Base64 string on any site (or anywhere for that matter), the backslashes must be removed as they are not valid characters in Base64. They're most likely only there as an escape character.