#minecraft #region #io #anvil

anvil-region

Region file format storage for chunks

11 releases (7 breaking)

0.8.1 Jan 15, 2022
0.8.0 Mar 21, 2021
0.7.0 Jan 31, 2021
0.4.0 Oct 3, 2020
0.3.0 Oct 27, 2019

#308 in Encoding

Download history 50/week @ 2022-06-07 6/week @ 2022-06-14 10/week @ 2022-06-21 4/week @ 2022-06-28 29/week @ 2022-07-05 27/week @ 2022-07-12 13/week @ 2022-07-19 27/week @ 2022-07-26 22/week @ 2022-08-02 18/week @ 2022-08-09 6/week @ 2022-08-16 25/week @ 2022-08-23 2/week @ 2022-08-30 27/week @ 2022-09-06 37/week @ 2022-09-13 15/week @ 2022-09-20

82 downloads per month

MIT license

1MB
733 lines

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);

Dependencies