NBT-API

NBT-API

98.9k Downloads

Invalid NBT from valid Json and NBT data

quiquelhappy opened this issue ยท 6 comments

commented

Hey, so I'm trying to import some items, and I'm trying to load this JSON:

{"Slot":{"type":"byte","value":14},"id":{"type":"string","value":"minecraft:white_banner"},"tag":{"type":"compound","value":{"display":{"type":"compound","value":{"Name":{"type":"string","value":"{\"extra\":[{\"bold\":true,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"black\",\"text\":\"German \"},{\"bold\":true,\"italic\":false,\"color\":\"dark_red\",\"text\":\"Pass\"},{\"bold\":true,\"italic\":false,\"color\":\"gold\",\"text\":\"port\"}],\"text\":\"\"}"}}},"BlockEntityTag":{"type":"compound","value":{"id":{"type":"string","value":"minecraft:banner"},"Patterns":{"type":"list","value":{"type":"compound","value":[{"Pattern":{"type":"string","value":"vh"},"Color":{"type":"int","value":14}},{"Pattern":{"type":"string","value":"vhr"},"Color":{"type":"int","value":14}},{"Pattern":{"type":"string","value":"rs"},"Color":{"type":"int","value":15}},{"Pattern":{"type":"string","value":"ls"},"Color":{"type":"int","value":4}}]}}}}}},"Count":{"type":"byte","value":1}}

with

                Object object = gson.fromJson(jsonItem, Object.class);
                NBTContainer container =  new NBTContainer(object); //Parse in json
                items.add(NBTItem.convertNBTtoItem(container));

and for some reason it is not recognizing the nbt when using new NBTContainer(object), despite being valid NBT and Json. What should I try next?

commented
Caused by: de.tr7zw.nbtapi.NbtApiException: The object 'class com.google.gson.internal.LinkedTreeMap' is not a valid NBT-Object!
        at de.tr7zw.nbtapi.NBTContainer.<init>(NBTContainer.java:39) ~[LegacyImport.jar:?]
        at co.purevanilla.mcplugins.legacyImport.API.getItems(API.java:45) ~[LegacyImport.jar:?]
        at co.purevanilla.mcplugins.legacyImport.Command.onCommand(Command.java:18) ~[LegacyImport.jar:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        ... 21 more
commented
                NBTContainer container =  new NBTContainer(jsonItem); //Parse in json
                items.add(NBTItem.convertNBTtoItem(container));
commented

Also noteworthy that the mojangson(note, nbt does not use json, you can't (always) parse it with gson) doesn't look like a valid item stack, so this will probably return null/an air item stack.

commented

do you happen to have an example of a valid itemstack? I've been trying to find one but I can't find any.

commented

You can generate a valid mojangson using NBTItem.convertItemtoNBT(itemstack).toString().
Example from https://minecraft.fandom.com/wiki/Tutorials/Command_NBT_tags {id:"stone",Count:3,tag:{display:{Name:"{\"text\":\"Name here\"}",Lore:["{\"text\":\"Text for lore line\"}"]}}} (I hope I copied the correct amount of {} )

commented

I managed to fix the issue; I was using the unsimplified format from prismarine nbt; I just had to simplify it by wrapping the object on a compound type obj.