All Projects → Querz → NBT

Querz / NBT

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

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to NBT

nason
🗜 Ultra tiny serializer / encoder with plugin-support. Useful to build binary files containing images, strings, numbers and more!
Stars: ✭ 30 (-76.56%)
Mutual labels:  serialization, compression, deserialization
MCStructureCleaner
Modded structure cleaner for Minecraft. Removes all references to non-existent structures to allow for clean error logs and chunk saving.
Stars: ✭ 22 (-82.81%)
Mutual labels:  nbt, mca-region, mca-file
Jsonapi Rb
Efficiently produce and consume JSON API documents.
Stars: ✭ 219 (+71.09%)
Mutual labels:  serialization, deserialization
Qs
Quick serialization of R objects
Stars: ✭ 225 (+75.78%)
Mutual labels:  serialization, compression
cattrs
Complex custom class converters for attrs.
Stars: ✭ 565 (+341.41%)
Mutual labels:  serialization, deserialization
Dart Json Mapper
Serialize / Deserialize Dart Objects to / from JSON
Stars: ✭ 206 (+60.94%)
Mutual labels:  serialization, deserialization
Mashumaro
Fast and well tested serialization framework on top of dataclasses
Stars: ✭ 208 (+62.5%)
Mutual labels:  serialization, deserialization
avro-serde-php
Avro Serialisation/Deserialisation (SerDe) library for PHP 7.3+ & 8.0 with a Symfony Serializer integration
Stars: ✭ 43 (-66.41%)
Mutual labels:  serialization, deserialization
Noproto
Flexible, Fast & Compact Serialization with RPC
Stars: ✭ 138 (+7.81%)
Mutual labels:  serialization, deserialization
har-rs
A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.
Stars: ✭ 25 (-80.47%)
Mutual labels:  serialization, deserialization
marshmallow-validators
Use 3rd-party validators (e.g. from WTForms and colander) with marshmallow
Stars: ✭ 24 (-81.25%)
Mutual labels:  serialization, deserialization
bytes
Work with bytes and implement network protocols
Stars: ✭ 77 (-39.84%)
Mutual labels:  serialization, deserialization
Marshmallow Jsonapi
JSON API 1.0 (https://jsonapi.org/) formatting with marshmallow
Stars: ✭ 203 (+58.59%)
Mutual labels:  serialization, deserialization
Aspjson
A fast classic ASP JSON parser and encoder for easy JSON manipulation to work with the new JavaScript MV* libraries and frameworks.
Stars: ✭ 165 (+28.91%)
Mutual labels:  serialization, deserialization
Schematics
Project documentation: https://schematics.readthedocs.io/en/latest/
Stars: ✭ 2,461 (+1822.66%)
Mutual labels:  serialization, deserialization
Orjson
Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy
Stars: ✭ 2,595 (+1927.34%)
Mutual labels:  serialization, deserialization
Jsonapi Rails
Rails gem for fast jsonapi-compliant APIs.
Stars: ✭ 242 (+89.06%)
Mutual labels:  serialization, deserialization
sexp-grammar
Invertible parsing for S-expressions
Stars: ✭ 28 (-78.12%)
Mutual labels:  serialization, deserialization
Flatsharp
Fast, idiomatic C# implementation of Flatbuffers
Stars: ✭ 133 (+3.91%)
Mutual labels:  serialization, deserialization
Deku
Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization
Stars: ✭ 136 (+6.25%)
Mutual labels:  serialization, deserialization

NBT

Build Status Coverage Status Release

A java implementation of the NBT protocol for Minecraft Java Edition.


Specification

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

Tag class Superclass ID Payload
EndTag Tag 0 None
ByteTag NumberTag 1 1 byte / 8 bits, signed
ShortTag NumberTag 2 2 bytes / 16 bits, signed, big endian
IntTag NumberTag 3 4 bytes / 32 bits, signed, big endian
LongTag NumberTag 4 8 bytes / 64 bits, signed, big endian
FloatTag NumberTag 5 4 bytes / 32 bits, signed, big endian, IEEE 754-2008, binary32
DoubleTag NumberTag 6 8 bytes / 64 bits, signed, big endian, IEEE 754-2008, binary64
ByteArrayTag ArrayTag 7 IntTag payload size, then size ByteTag payloads
StringTag Tag 8 ShortTag payload length, then a UTF-8 string with size length
ListTag Tag 9 ByteTag payload tagId, then IntTag payload size, then size tags' payloads, all of type tagId
CompoundTag Tag 10 Fully formed tags, followed by an EndTag
IntArrayTag ArrayTag 11 IntTag payload size, then size IntTag payloads
LongArrayTag ArrayTag 12 IntTag payload size, then size LongTag 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.

Add the library as a dependency using Gradle:

Add Jitpack to your repositories:

repositories {
	...
	maven { url 'https://jitpack.io/' }
}

And then add it as a dependency as usual:

dependencies {
	...
	implementation 'com.github.Querz:NBT:6.1'
}

Add the library as a dependency using Maven:

Add Jitpack:

<repositories>
	<repository>
		<id>jitpack.io</id>
		<url>https://jitpack.io</url>
	</repository>
</repositories>

Dependency:

<dependency>
	<groupId>com.github.Querz</groupId>
	<artifactId>NBT</artifactId>
	<version>6.1</version>
</dependency>

Example usage:

The following code snippet shows how to create a CompoundTag:

CompoundTag ct = new CompoundTag();

ct.put("byte", new ByteTag((byte) 1));
ct.put("double", new DoubleTag(1.234));
ct.putString("string", "stringValue");

An example how to use a ListTag:

ListTag<FloatTag> fl = new ListTag<>(FloatTag.class);

fl.add(new FloatTag(1.234f);
fl.addFloat(5.678f);

Nesting

All methods serializing instances or deserializing data track the nesting levels to prevent circular references or malicious data which could, when deserialized, result in thousands of instances causing a denial of service.

These methods have a parameter for the maximum nesting depth they are allowed to traverse. A value of 0 means that only the object itself, but no nested object may be processed.

If an instance is nested further than allowed, a MaxDepthReachedException will be thrown. A negative maximum depth will cause an IllegalArgumentException.

Some methods do not provide a parameter to specify the maximum depth, but instead use Tag.DEFAULT_MAX_DEPTH (512) which is also the maximum used in Minecraft.


Utility

There are several utility methods to make your life easier if you use this library.

NBTUtil

NBTUtil.write() lets you write a Tag into a gzip compressed or uncompressed file in one line (not counting exception handling). Files are gzip compressed by default.

Example usage:

NBTUtil.write(namedTag, "filename.dat");

NBTUtil.read() reads any file containing NBT data. No worry about compression, it will automatically uncompress gzip compressed files.

Example usage:

NamedTag namedTag = NBTUtil.read("filename.dat");

Playing Minecraft?

Each tag can be converted into an NBT String (SNBT) used in Minecraft commands.

Example usage:

CompoundTag c = new CompoundTag();
c.putByte("blah", (byte) 5);
c.putString("foo", "bär");
ListTag<StringTag> s = new ListTag<>(StringTag.class);
s.addString("test");
s.add(new StringTag("text"));
c.add("list", s);
System.out.println(SNBTUtil.toSNBT(c)); // {blah:5b,foo:"bär",list:[test,text]}

There is also a tool to read, change and write MCA files.

Here are some examples:

// This changes the InhabitedTime field of the chunk at x=68, z=81 to 0
MCAFile mcaFile = MCAUtil.readMCAFile("r.2.2.mca");
Chunk chunk = mcaFile.getChunk(68, 81);
chunk.setInhabitedTime(0);
MCAUtil.writeMCAFile("r.2.2.mca", mcaFile);

There is also an optimized api to retrieve and set block information (BlockStates) in MCA files.

Example:

// Retrieves block information from the MCA file
CompoundTag blockState = mcaFile.getBlockStateAt(1090, 25, 1301);

// Retrieves block information from a single chunk
CompoundTag blockState = chunk.getBlockStateAt(2, 25, 5);

// Set block information
CompoundTag stone = new CompoundTag();
stone.putString("Name", "minecraft:stone");
mcaFile.setBlockStateAt(1090, 25, 1301, stone, false);

To ensure good performance even when setting a lot of blocks and / or editing sections with a huge palette of block states, the size of the BlockStates array is only updated when the size of the palette requires it. This means there might be blocks in the palette that are not actually used in the BlockStates array. You can trigger a cleanup process by calling one of the following three methods, depending on the desired depth:

mcaFile.cleanupPalettesAndBlockStates();
chunk.cleanupPalettesAndBlockStates();
section.cleanupPaletteAndBlockStates();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].