#minecraft #nbt #serde #litematic #litematica

rustmatica

A Rust library for reading, editing, and writing Minecraft litematic files

7 releases (4 breaking)

0.5.0 May 12, 2024
0.4.0 May 9, 2024
0.3.1 May 8, 2024
0.2.0 Apr 26, 2024
0.1.1 Mar 3, 2023

#831 in Encoding

Download history 29/week @ 2024-07-25 7/week @ 2024-08-01 5/week @ 2024-09-19 7/week @ 2024-09-26 9/week @ 2024-10-03

395 downloads per month

GPL-3.0-only

49KB
847 lines

rustmatica

Crates.io

A rust crate for working with Minecraft litematica files.

Overview

The two main types of this crate are Litematic and Region. See their documentation for more info.

The examples directory contains a few basic examples for how to use this crate.

Usage with mcdata

rustmatica is tightly coupled with mcdata and makes use of its traits for block states, entities, and block entities. By default, schematics will use mcdatas "generic" types which store most of their data using fastnbt::Values.

use rustmatica::Litematic;
use mcdata::util::UVec3;

// type must be declared explicitly for Rust to use the default generics
let schem: Litematic = Litematic::read_file("test_files/axolotl.litematic")?;

// block has type `mcdata::GenericBlockState`
let block = schem.regions[0].get_block(UVec3::new(1, 0, 1));
assert_eq!(block.name, "minecraft:water");
// properties aren't typed
assert_eq!(block.properties["level"], "0");
# Ok::<(), rustmatica::Error>(())

But mcdata also offers more concrete types when enabling certain cargo features. To use these, add a custom dependency on mcdata similar to this:

mcdata = { version = "<version>", features = ["latest", "block-states"] }

Then you can use the mcdata::latest::BlockState type instead:

use rustmatica::Litematic;
use mcdata::{util::UVec3, latest::BlockState};
use bounded_integer::BoundedU8;

let schem: Litematic<BlockState> = Litematic::read_file("test_files/axolotl.litematic")?;

// block has type `BlockState`
let block = schem.regions[0].get_block(UVec3::new(1, 0, 1));
assert_eq!(block, &BlockState::Water {
    level: BoundedU8::new(0).unwrap(),
});
# Ok::<(), rustmatica::Error>(())

Dependencies

~7MB
~123K SLoC