Posted November 15, 20177 yr I have items.json file where are storing data about different itemstack (name, metadata, amount, enchants and nbt) All works nice, but nbt format is not correct: example: items.json "name": "groupofitems", "items": [{ "item": "IC2:itemToolChainsaw", "metadata": 27, "amount": 1, "enchantments": {}, "nbt": { "charge": 30000.0d } }] //next groups and items.... and result is - {"charge":"30000.0d",} - this is wrong and not working, it have to be {charge:30000.0d} How to solve this problem? Edited November 17, 20177 yr by RealNight
November 15, 20177 yr Author On 16.11.2017 at 0:42 AM, diesieben07 said: Please show the source of NBTSerializer. Edited November 17, 20177 yr by RealNight
November 15, 20177 yr Author 11 minutes ago, diesieben07 said: And how do you serialize the JSON again? You must have an NBTSerializer then, too, right? No, new NBTDeserializer() is the name of the class file where it adapts minecraft NBTBase file (it is option for gson building like a string) example: nbt:{"charge":"30000.0d"} (that is without adapting) , with adapting - nbt: {"charge":"30000.0d",} (comma is added in the end) After that i apply settings that i made for gson for taking data from file.json and place data in the ItemConfig class Edited November 15, 20177 yr by RealNight
November 15, 20177 yr Author On 16.11.2017 at 1:06 AM, diesieben07 said: No. NBTDeserializer is a json deserializer. It takes in JSON and produces an NBTBase instance. maybe you meant NBTDeserializer that implements json deserializer<ObjectName> (in our case NBTBase). In this class it turn to string everything that is found under nbt:{ } Edited November 17, 20177 yr by RealNight
November 15, 20177 yr Author 1 minute ago, diesieben07 said: Everything you are talking about until now is about taking JSON and turning it into java objects (NBTBase). But your issue (as I understand it, please correct me if I am wrong) lies with the opposite direction, going from the Java objects (NBTBase, etc.) to JSON. Sorry, however i am really stupid... return (json != null) ? JsonToNBT.func_150315_a(json.toString().replaceAll("\"", "")) : null; and it works, wasted so many time and yours...
November 15, 20177 yr Author 4 minutes ago, diesieben07 said: No, this is terrible and will break. Your JSON should not contain these quotes. I read that it is rule of form of json & gson Edited November 15, 20177 yr by RealNight
November 15, 20177 yr Author 12 minutes ago, diesieben07 said: What? Please, for once, clarify what you are actually talking about. You keep saying things get replaced. Where exactly? When? if we do in json file - charge: 30000.0d instead of "charge": "30000.0d" it means that we are trying to ask json library to generate invalid json. In gson part corrects this mistake and add quotes. About a replaceall func: that is not the final version, i know that string can contain tree of nbt, so i need to check and figure all of them. Now, for 1 lvl tree of nbt it is more than enough. Edited November 15, 20177 yr by RealNight
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.