mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
world/layer: return None from top_layer() for empty chunks
Allow ignoring these chunks for the light map as well.
This commit is contained in:
parent
202364bfca
commit
4fd316f3fc
3 changed files with 24 additions and 5 deletions
12
src/main.rs
12
src/main.rs
|
@ -98,7 +98,10 @@ impl<'a> RegionProcessor<'a> {
|
|||
}
|
||||
|
||||
/// Processes a single chunk
|
||||
fn process_chunk(&self, data: world::de::Chunk) -> Result<Box<world::layer::BlockInfoArray>> {
|
||||
fn process_chunk(
|
||||
&self,
|
||||
data: world::de::Chunk,
|
||||
) -> Result<Option<Box<world::layer::BlockInfoArray>>> {
|
||||
let chunk = world::chunk::Chunk::new(&data, &self.block_types)?;
|
||||
world::layer::top_layer(&chunk)
|
||||
}
|
||||
|
@ -127,9 +130,12 @@ impl<'a> RegionProcessor<'a> {
|
|||
|
||||
minedmap::io::region::from_file(path)?.foreach_chunk(
|
||||
|chunk_coords, data: world::de::Chunk| {
|
||||
let processed_chunk = self
|
||||
let Some(processed_chunk) = self
|
||||
.process_chunk(data)
|
||||
.with_context(|| format!("Failed to process chunk {:?}", chunk_coords))?;
|
||||
.with_context(|| format!("Failed to process chunk {:?}", chunk_coords))?
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
processed_region[chunk_coords] = Some(processed_chunk);
|
||||
Ok(())
|
||||
},
|
||||
|
|
|
@ -179,6 +179,15 @@ impl<'a> Chunk<'a> {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
match self {
|
||||
Chunk::V1_18 { section_map } => section_map.is_empty(),
|
||||
Chunk::V1_13 { section_map, .. } => section_map.is_empty(),
|
||||
Chunk::V0 { section_map, .. } => section_map.is_empty(),
|
||||
Chunk::Empty => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an interator over the chunk's sections and their Y coordinates
|
||||
pub fn sections(&self) -> SectionIter {
|
||||
use SectionIterInner::*;
|
||||
|
|
|
@ -91,9 +91,13 @@ pub type BlockInfoArray = LayerBlockArray<Option<BlockInfo>>;
|
|||
/// determined as the block that should be visible on the rendered
|
||||
/// map. For water blocks, the height of the first non-water block
|
||||
/// is additionally filled in as the water depth.
|
||||
pub fn top_layer(chunk: &Chunk) -> Result<Box<BlockInfoArray>> {
|
||||
pub fn top_layer(chunk: &Chunk) -> Result<Option<Box<BlockInfoArray>>> {
|
||||
use BLOCKS_PER_CHUNK as N;
|
||||
|
||||
if chunk.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let mut done = 0;
|
||||
let mut ret = Box::<BlockInfoArray>::default();
|
||||
|
||||
|
@ -129,5 +133,5 @@ pub fn top_layer(chunk: &Chunk) -> Result<Box<BlockInfoArray>> {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(ret)
|
||||
Ok(Some(ret))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue