anvil-region

Crates.ioanvil-region
lib.rsanvil-region
version0.8.1
sourcesrc
created_at2019-10-05 20:15:05.689182
updated_at2022-01-15 18:44:06.796481
descriptionRegion file format storage for chunks.
homepagehttps://github.com/eihwaz/anvil-region
repositoryhttps://github.com/eihwaz/anvil-region
max_upload_size
id170202
size1,920,104
(vagola)

documentation

README

anvil-region

crates.io Build Status codecov

Region file format storage for chunks

Usage

Add this to your Cargo.toml:

[dependencies]
anvil-region = "0.8"

Example

Read

use anvil_region::provider::{FolderRegionProvider, RegionProvider};
use anvil_region::position::{RegionPosition, RegionChunkPosition};

let provider = FolderRegionProvider::new("test/region");

let region_position = RegionPosition::from_chunk_position(4, 2);
let region_chunk_position = RegionChunkPosition::from_chunk_position(4, 2);

let mut region = provider.get_region(region_position).unwrap();

let chunk_compound_tag = region.read_chunk(region_chunk_position).unwrap();
let level_compound_tag = chunk_compound_tag.get_compound_tag("Level").unwrap();

assert_eq!(level_compound_tag.get_i32("xPos").unwrap(), 4);
assert_eq!(level_compound_tag.get_i32("zPos").unwrap(), 2);

Write

use anvil_region::provider::{FolderRegionProvider, RegionProvider};
use nbt::CompoundTag;
use anvil_region::position::{RegionPosition, RegionChunkPosition};

let provider = FolderRegionProvider::new("test/region");

let region_position = RegionPosition::from_chunk_position(31, 16);
let region_chunk_position = RegionChunkPosition::from_chunk_position(31, 16);

let mut region = provider.get_region(region_position).unwrap();

let mut chunk_compound_tag = CompoundTag::new();
let mut level_compound_tag = CompoundTag::new();

// To simplify example we add only coordinates.
// Full list of required tags https://minecraft.gamepedia.com/Chunk_format.
level_compound_tag.insert_i32("xPos", 31);
level_compound_tag.insert_i32("zPos", 16);

chunk_compound_tag.insert_compound_tag("Level", level_compound_tag);

region.write_chunk(region_chunk_position, chunk_compound_tag);
Commit count: 46

cargo fmt