remove redundant test classes
5 files changed
tree: 2714ef91ce59a53fade9c038bc836630a9a3b28d
  1. .gitignore
  2. .travis.yml
  3. LICENSE
  4. README.md
  5. build.gradle
  6. gradle/wrapper/
  7. gradlew
  8. gradlew.bat
  9. settings.gradle
  10. src/
README.md

NBT

Build Status

A java implementation of the NBT protocol, including a way to implement custom tags.


Specification

According to the specification, there are currently 12 different types of tags:

Tag classSuperclassIDPayload
EndTagTag0None
ByteTagNumberTag11 byte / 8 bits, signed
ShortTagNumberTag22 bytes / 16 bits, signed, big endian
IntTagNumberTag34 bytes / 32 bits, signed, big endian
LongTagNumberTag48 bytes / 64 bits, signed, big endian
FloatTagNumberTag54 bytes / 32 bits, signed, big endian, IEEE 754-2008, binary32
DoubleTagNumberTag68 bytes / 64 bits, signed, big endian, IEEE 754-2008, binary64
ByteArrayTagArrayTag7IntTag‘s payload size, then size ByteTag’s payloads
StringTagTag8ShortTag's payload length, then a UTF-8 string with size length
ListTagTag9ByteTag‘s payload tagId, then IntTag’s payload size, then size tags' payloads, all of type tagId
CompoundTagTag10Fully formed tags, followed by an EndTag
IntArrayTagArrayTag11IntTag‘s payload size, then size IntTag’s payloads
LongArrayTagArrayTag12IntTag‘s payload size, then size LongTag’s payloads
  • The EndTag is only used to mark the end of a CompoundTag in its serialized state or an empty ListTag.

  • The maximum depth of the NBT structure is 512. If the depth exceeds this restriction during serialization, deserialization or String conversion, a MaxDepthReachedException is thrown. This usually happens when a circular reference exists in the NBT structure. The NBT specification does not allow circular references, as there is no tag to represent this.


Example usage:

ByteTag bt = new ByteTag("8bitNumber", (byte) 1);
DoubleTag dt = new DoubleTag("64bitFloatingPointNumber", 1.234);

CompoundTag ct = new CompoundTag("compound");

ct.set(bt);
ct.set(dt);
ct.setString("string", "stringValue");

Utility

There are several utility classes that make your life easier using this library.

NBTFileWriter

The NBTFileWriter lets you write a Tag into a gzip compressed or uncompressed file in one line. Files are gzip compressed by default. Example usage:

new NBTFileWriter("filename.dat").write(tag);

NBTFileReader

The NBTFileReader reads any file containing NBT data. No worry about compression, it will automatically uncompress gzip compressed files. Example usage:

Tag tag = new NBTFileReader("filename.dat").read();

Playing Minecraft?

Each tag can be converted into a JSON-like NBT String used in Minecraft commands. Example usage:

CompoundTag c = new CompoundTag("compound");
c.setByte("byte", (byte) 5);
c.setString("string", "test");
String s = c.toTagString();

//output: compound:{byte:5b,string:"test"}

Custom tags

Interested in more advanced features, and the default NBT protocol just isn't enough? Simply create your own tags! There are 4 example classes in net.querz.nbt.custom that show how to implement custom tags:

ClassIDDescription
ObjectTag90A Wrapper Tag that serializes and deserializes any object using the default java serialization.
ShortArrayTag100In addition to the already existing ByteArrayTag, IntArrayTag and LongArrayTag.
CharTag110Character (char) tag.
StructTag120Similar to the ListTag, but with the ability to store multiple types.

To be able to use a custom tag, it must be registered during runtime with TagType#registerCustomTag(int, Class).