NamedBinaryTag library for Java
Reading binary data:
InputStream input = // Get an input stream
CompoundTag tag = BinaryTags.readCompressed(input);
int intValue = tag.getInt("key");
String string = tag.getString("other_key");
Writing binary data:
CompoundTag tag = // Get a tag
OutputStream stream = // Create a stream
BinaryTags.writeCompressed(stream, tag);
SNBT parsing:
import net.forthecrown.nbt.string.Snbt;
String input = // Get an SNBT input
BinaryTag tag = Snbt.parse(input);
SNBT writing:
BinaryTag tag = // Get a tag
String output = Snbt.toString(tag);
Minecraft wiki: https://minecraft.wiki/w/NBT_path_format
NBT paths can be created and used like so:
import net.forthecrown.nbt.path.TagPath
TagPath path = TagPath.parse("foo.bar[]");
BinaryTag tag = // Get a tag
List<BinaryTag> results = path.get(tag);
int removed = path.remove(tag);
int changed = path.set(tag, BinaryTags.stringTag("Hello, world!"));
Paths can also be created programmatically with TagPath.builder()
, the above shown example would look like so:
TagPath path = TagPath.builder()
.addObjectNode("foo")
.addObjectNode("bar")
.addMatchAll()
.build();
Maven:
<dependencies>
<dependency>
<groupId>net.forthecrown</groupId>
<artifactId>nbt</artifactId>
<version>LATEST</version>
</dependency>
<!-- If you're using this with PaperMC, you can also include -->
<dependency>
<groupId>net.forthecrown</groupId>
<artifactId>paper-nbt</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
Gradle:
repositories {
mavenCentral()
}
dependencies {
implementation("net.forthecrown:nbt:1.5.1")
// If you're using this with PaperMC, you can also include
implementation("net.forthecrown:paper-nbt:1.7.4")
}