Skip to content

Conversion between NBTs and Strings losslesslyΒ #1854

@ustc-zzzz

Description

@ustc-zzzz

Is there any way to convert between NBTTagCompounds (maybe DataContainers in SpongeAPI) and Strings losslessly? For example, in forge mods we can use net.minecraft.nbt.JsonToNBT#getTagFromJson and net.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, and Object) while the number of NBT types is much greater (for example, there are six number types for NBT: Byte, Short, Int, Long, Float, and Double, 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions