-
-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversion between NBTs and Strings losslessly #1854
Comments
Converting |
@Cybermaxke well, |
We should consider having a 'mojangson' option for outputting and parsing, DataContainers to NBT, to string left up to the implementation to implement. This would be the most portable and well recognized option in the MC community. Or are there still ambiguous serialization cases with it? @Cybermaxke Lantern et all, could either recreate it, or use their own format when using this serializer? |
@ryantheleach I don't really have a true mojangson parser in lantern atm, but I will try to implement it and then port it over to sponge. |
@Cybermaxke my suspicion, at least for SpongeCommon is that it would be easier to just go to NBT then let Minecraft turn it into Mojangson. My hesitations about adding it to the API were:
We could say it's just a format that has the same capabilities, retaining types for the primitives that are supported by NBT. E.g. A NBTText format, that can differ by implementation. Then, as long as you can always round-trip it to text, then you satisfy the requirement? |
Plugin devs may not expect different output types when using a specific data format. This is something that should be consistent across implementations, if you want a different format, provide a new one. Another option is to provide the same parser across implementations and make it compatible with mojangson, but we can add our own custom parsing capabilities (if desired). I am also directly parsing the mojangson data into a DataView to reduce overhead of converting the data twice. |
I'd shy away from adding customized parsing capabilities, I'm keen to see something that's portable from vanilla communities. I'm not sure of the maturity of the projects, but they may be a starting point as they are MIT Licensed. https://github.com/momothereal/Mojangson Edit: Just realized I might be coming off a bit unrespectful of the existing code in LanternNBT. That wasn't my intention. |
LanternNBT doesn't have any Mojangson parsing capabilities, at least not atm. If I support it for LanternNBT, I am going to add custom parsing capabilities to support all its data types, while retaining vanilla compatibility if the data gets serialized. |
@ryantheleach The parser I was working is mostly done, maybe more error handling. And I need to do more testing, you can checkout my progress here: |
Other options are SNBT (Mojang) or NBTT (MinecraftDev IntelliJ plugin) |
For lack of a better place to organize this, I'm putting it under Commands due to Vanilla commands and Brigadier having support for parsing SNBT in 1.13 |
This is very much a data question, not a command one. I'm not sure if this is possible in 1.16+ builds yet though... |
Is there any way to convert between
NBTTagCompound
s (maybeDataContainer
s in SpongeAPI) andString
s losslessly? For example, in forge mods we can usenet.minecraft.nbt.JsonToNBT#getTagFromJson
andnet.minecraft.nbt.NBTTagCompound#toString
to complete the conversion between those two types, but in SpongeAPI I could not find methods which look like they could do these things.I have considered converting an NBT to JSON, HOCON, or something else, but both JSON and HOCON only have six types (
String
,Number
,Boolean
,Null
,Array
, andObject
) while the number of NBT types is much greater (for example, there are six number types for NBT:Byte
,Short
,Int
,Long
,Float
, andDouble
, so I cannot recognize what the type is when I try to deserialize a number in a JSON). What I need is lossless conversion by using SpongeAPI.The text was updated successfully, but these errors were encountered: