pub struct Region<S> { /* private fields */ }
Expand description
A Minecraft Region, allowing reading and writing of chunk data to a stream (eg a
File). This does not concern itself with manipulating chunk data, users are
expected to use fastnbt
or other deserialization method to manipulate the
chunk data itself.
Implementations§
source§impl<S> Region<S>where
S: Read + Seek,
impl<S> Region<S>where S: Read + Seek,
sourcepub fn from_stream(stream: S) -> Result<Self>
pub fn from_stream(stream: S) -> Result<Self>
Load a region from an existing stream. Will assume a seek of zero is the start of the region. This does not load all region data into memory. Chunks are read from the underlying stream when needed.
sourcepub fn read_chunk(&mut self, x: usize, z: usize) -> Result<Option<Vec<u8>>>
pub fn read_chunk(&mut self, x: usize, z: usize) -> Result<Option<Vec<u8>>>
Read the chunk located at the chunk coordindates x
, z
. The chunk
data returned is uncompressed NBT. Ok(None)
means that the chunk does
not exist, which will be the case if that chunk has not generated. If
x
or z
are outside 0..32
, Error::InvalidOffset
is returned.
sourcepub fn into_inner(self) -> Result<S>
pub fn into_inner(self) -> Result<S>
Return the inner buffer used. The buffer is rewound to the beginning.
pub fn iter(&mut self) -> RegionIter<'_, S> ⓘ
source§impl<S> Region<S>where
S: Read + Write + Seek,
impl<S> Region<S>where S: Read + Write + Seek,
sourcepub fn new(stream: S) -> Result<Self>
pub fn new(stream: S) -> Result<Self>
Create an new empty region. The provided stream will be overwritten, and will assume a seek to 0 is the start of the region. The stream needs read, write, and seek like a file provides.
sourcepub fn write_chunk(
&mut self,
x: usize,
z: usize,
uncompressed_chunk: &[u8]
) -> Result<()>
pub fn write_chunk( &mut self, x: usize, z: usize, uncompressed_chunk: &[u8] ) -> Result<()>
Write the given uncompressed NBT chunk data to the chunk coordinates x,
z. The chunk data will be compressed with zlib by default. You can use
write_compressed_chunk if you want more control. If x
or z
are
outside 0..32
, Error::InvalidOffset
is returned.
sourcepub fn write_compressed_chunk(
&mut self,
x: usize,
z: usize,
scheme: CompressionScheme,
compressed_chunk: &[u8]
) -> Result<()>
pub fn write_compressed_chunk( &mut self, x: usize, z: usize, scheme: CompressionScheme, compressed_chunk: &[u8] ) -> Result<()>
Low level method. Write the given compressed chunk data to the stream.
It is the callers responsibility to make sure the compression scheme
matches the compression used. If x
or z
are outside 0..32
,
Error::InvalidOffset
is returned.