zuri_nbt

Crates.iozuri_nbt
lib.rszuri_nbt
version0.4.0
created_at2023-07-14 10:26:36.665804+00
updated_at2025-04-21 19:16:26.853354+00
descriptionRead and write minecraft NBT data
homepage
repositoryhttps://github.com/zuri-mc/zuri_nbt/
max_upload_size
id915958
size112,930
(AndreasHGK)

documentation

README

Overview

Read and write NBT data.

Named Binary Tag (NBT) is a structured binary format used throughout Minecraft for a multitude of things. This crate mainly focuses on Minecraft: Bedrock Edition, and supports the little endian and network little endian encoding. Big endian, which is more commonly used in Minecraft: Java Edition, is also supported, however.

Feature flags

  • serde - Allows rust types to be serialized and deserialized into NBT using serde.

Examples

NBT data can be constructed and written as follows:

use zuri_nbt::encoding::LittleEndian;
use zuri_nbt::NBTTag;
use zuri_nbt::tag;

let nbt = tag::Compound::builder()
  .with_string("name", "Zuri")
  .with_int("age", 18)
  .build();

let mut buf = Vec::new();
nbt.write(&mut buf, LittleEndian).expect("Something went wrong while writing nbt");

Reading NBT data can be done as follows:

use zuri_nbt::encoding::LittleEndian;
use zuri_nbt::NBTTag;

let mut bytes: &[u8] = &[
   0x08, 0x00, 0x00, 0x0c,
   0x00, 0x48, 0x65, 0x6c,
   0x6c, 0x6f, 0x20, 0x57,
   0x6f, 0x72, 0x6c, 0x64,
   0x21, 0x00, 0x00, 0x00,
];

let value = NBTTag::read(bytes, LittleEndian).expect("Something went wrong while reading nbt");

assert_eq!(value, NBTTag::String("Hello World!".to_string().into()));
Commit count: 18

cargo fmt