Skip to main content

Tag Stream

Information

Rtag has the option to save any NBTTagCompound into different ways:

  • File
  • Base64
  • Bytes (byte[])
  • Maps (Map<String, Object>)
  • String (SNBT format, also compatible with Json)
  • Readable Map (Only for items)

Including compatibility with serializable objects.

Supported serialization formats

Any byte array serialization (probably saved as Base64) is compatible if it's made by the following methods:

  1. Using BukkitObjectInputStream to save objects as type object or byte[].
  2. Using NBTCompressedStreamTools to save objects as NBTTagCompound, NBTTagList or NBTTagByteArray inside bytes.
  3. NBT objects saved with GZIP format.
  4. NBT objects saved inside other NBT object (like nbt list or byte array).

TagCompound Data

The TagCompound class includes the "DATA" interface, an easy way to convert any NBTTagCompound into File, Base64, Bytes, Map and String.

// NBTTagCompound from anywhere
Object compound = ...;

// Convert into File
File file TStream.COMPOUND.toFile(compound, new File("file.nbt"));

// Get from file
Object tagCompound = TStream.COMPOUND.fromFile(file);

ItemTagStream

Rtag includes an easy way to convert any ItemStack into File, Base64, Bytes, Map, String and Readable Map, useful to save items in a database.

info

The "readable map" format convert item name and lore into colored strings, instead of chat component format introduced for items nbt on Minecraft 1.13, useful to save items in files and make them editable by the user without understanding chat components.

ItemStack item = ...;

// Convert into File
File file = ItemTagStream.INSTANCE.toFile(item, new File("file.nbt"));

// Get from File
ItemStack sameItem = ItemTagStream.INSTANCE.fromFile(file);

Including cross-version support! Save an item on any version and get on any version without compatibility problems. Materials, enchantments, potions... etc, all will be converted!

It also detects items serialized by Bukkit or Paper that adds data version tag as DataVersion or v to apply the conversion.

Current limitations

The default ItemTagStream instance it's only compatible with Bukkit items, if your server uses Forge it is suggested to use your own instance of ItemTagStream with Forge compatibility.