11 breaking releases

0.21.0 Jul 17, 2021
0.19.0 Jul 4, 2021
0.16.0 Mar 19, 2021
0.14.1 Nov 27, 2020

#8 in Games

Download history 39/week @ 2021-06-21 22/week @ 2021-06-28 40/week @ 2021-07-05 30/week @ 2021-07-12 35/week @ 2021-07-19 29/week @ 2021-07-26 50/week @ 2021-08-02 76/week @ 2021-08-09 22/week @ 2021-08-16 9/week @ 2021-08-23 1/week @ 2021-08-30 8/week @ 2021-09-06 10/week @ 2021-09-13 5/week @ 2021-09-20 14/week @ 2021-09-27 10/week @ 2021-10-04

90 downloads per month
Used in fastnbt-tools

MIT/Apache

250KB
6.5K SLoC

fastnbt project

Latest Version docs-shield Build Status

Serde deserializer for Minecraft: Java Edition's NBT format, and in-browser Rust-to-WASM powered Minecraft map renderer. Supports 1.17.

Demo

Demo of Hermitcraft season 7 and more at owengage.com/anvil

alt rendered map

This repository contains multiple related projects.

  • fastnbt: Fast serde deserializer for Minecraft: Java Edition's NBT data format.
  • fastanvil: For rendering Minecraft worlds to maps.
  • fastnbt-tools: Various tools for NBT/Anvil, notably a map renderer.

Aim to support only the latest version of Minecraft. Works with 1.17 worlds and 1.16 worlds at the moment. Might work for more. Endevour to support old chunks in worlds, but not extracting textures from older versions due to the added complexity it would require.

The anvil binary from fastnbt-tools can render your world leveraging all of your CPU.

See fastnbt's README for performance comparison.

Serde deserializer example

This example demonstrates printing out a players inventory and ender chest contents from the player dat files found in worlds. We

  • use serde's renaming attribute to have rustfmt conformant field names,
  • use lifetimes to save on string allocations, and
  • use the Value type to deserialize a field we don't specify the exact structure of.
use fastnbt::error::Result;
use fastnbt::{de::from_bytes, Value};
use flate2::read::GzDecoder;
use serde::Deserialize;
use std::io::Read;

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct PlayerDat<'a> {
    data_version: i32,

    #[serde(borrow)]
    inventory: Vec<InventorySlot<'a>>,
    ender_items: Vec<InventorySlot<'a>>,
}

#[derive(Deserialize, Debug)]
struct InventorySlot<'a> {
    id: &'a str,        // We avoid allocating a string here.
    tag: Option<Value>, // Also get the less structured properties of the object.

    // We need to rename fields a lot.
    #[serde(rename = "Count")]
    count: i8,
}

fn main() {
    let args: Vec<_> = std::env::args().skip(1).collect();
    let file = std::fs::File::open(args[0].clone()).unwrap();

    // Player dat files are compressed with GZip.
    let mut decoder = GzDecoder::new(file);
    let mut data = vec![];
    decoder.read_to_end(&mut data).unwrap();

    let player: Result<PlayerDat> = from_bytes(data.as_slice());

    println!("{:#?}", player);
}

Development priorities

These are the proirities for the project when it comes to development. Ideally we never sacrifice an earlier priority for the sake of a later one.

  1. Correctness. Worlds are rendered as accurately as possible.
  2. Speed. Worlds are rendered as fast as possible.
  3. Memory. Worlds are rendered without sucking up RAM.

Usage

For the libraries

[dependencies]
fastnbt = "1"
fastanvil = "0.20"

For the anvil executable

cargo install fastnbt-tools

Dependencies

~5.5MB
~90K SLoC