mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 01:24:53 +01:00
world/layer: add biome data to returned layer
This commit is contained in:
parent
0d2c99dacf
commit
e912f60ba3
2 changed files with 18 additions and 6 deletions
|
@ -126,7 +126,10 @@ impl<'a> RegionProcessor<'a> {
|
||||||
data: world::de::Chunk,
|
data: world::de::Chunk,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
Option<(
|
Option<(
|
||||||
Box<world::layer::BlockInfoArray>,
|
(
|
||||||
|
Box<world::layer::BlockInfoArray>,
|
||||||
|
Box<world::layer::BiomeArray>,
|
||||||
|
),
|
||||||
Box<world::layer::BlockLightArray>,
|
Box<world::layer::BlockLightArray>,
|
||||||
)>,
|
)>,
|
||||||
> {
|
> {
|
||||||
|
@ -192,7 +195,7 @@ impl<'a> RegionProcessor<'a> {
|
||||||
|
|
||||||
minedmap::io::region::from_file(path)?.foreach_chunk(
|
minedmap::io::region::from_file(path)?.foreach_chunk(
|
||||||
|chunk_coords, data: world::de::Chunk| {
|
|chunk_coords, data: world::de::Chunk| {
|
||||||
let Some((processed_chunk, block_light)) = self
|
let Some(((processed_chunk, _), block_light)) = self
|
||||||
.process_chunk(data)
|
.process_chunk(data)
|
||||||
.with_context(|| format!("Failed to process chunk {:?}", chunk_coords))?
|
.with_context(|| format!("Failed to process chunk {:?}", chunk_coords))?
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::chunk::{Chunk, SectionIterItem};
|
use super::chunk::{Chunk, SectionIterItem};
|
||||||
use crate::{
|
use crate::{
|
||||||
resource::{BlockFlag, BlockType},
|
resource::{Biome, BlockFlag, BlockType},
|
||||||
types::*,
|
types::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ impl OptionBlockInfoExt for Option<BlockInfo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type BlockInfoArray = LayerBlockArray<Option<BlockInfo>>;
|
pub type BlockInfoArray = LayerBlockArray<Option<BlockInfo>>;
|
||||||
|
pub type BiomeArray = LayerBlockArray<Option<Biome>>;
|
||||||
pub type BlockLightArray = LayerBlockArray<u8>;
|
pub type BlockLightArray = LayerBlockArray<u8>;
|
||||||
|
|
||||||
/// Fills in a [BlockInfoArray] with the information of the chunk's top
|
/// Fills in a [BlockInfoArray] with the information of the chunk's top
|
||||||
|
@ -92,7 +93,9 @@ pub type BlockLightArray = LayerBlockArray<u8>;
|
||||||
/// determined as the block that should be visible on the rendered
|
/// determined as the block that should be visible on the rendered
|
||||||
/// map. For water blocks, the height of the first non-water block
|
/// map. For water blocks, the height of the first non-water block
|
||||||
/// is additionally filled in as the water depth.
|
/// is additionally filled in as the water depth.
|
||||||
pub fn top_layer(chunk: &Chunk) -> Result<Option<(Box<BlockInfoArray>, Box<BlockLightArray>)>> {
|
pub fn top_layer(
|
||||||
|
chunk: &Chunk,
|
||||||
|
) -> Result<Option<((Box<BlockInfoArray>, Box<BiomeArray>), Box<BlockLightArray>)>> {
|
||||||
use BLOCKS_PER_CHUNK as N;
|
use BLOCKS_PER_CHUNK as N;
|
||||||
|
|
||||||
if chunk.is_empty() {
|
if chunk.is_empty() {
|
||||||
|
@ -101,12 +104,13 @@ pub fn top_layer(chunk: &Chunk) -> Result<Option<(Box<BlockInfoArray>, Box<Block
|
||||||
|
|
||||||
let mut done = 0;
|
let mut done = 0;
|
||||||
let mut blocks = Box::<BlockInfoArray>::default();
|
let mut blocks = Box::<BlockInfoArray>::default();
|
||||||
|
let mut block_biomes = Box::<BiomeArray>::default();
|
||||||
let mut light = Box::<BlockLightArray>::default();
|
let mut light = Box::<BlockLightArray>::default();
|
||||||
|
|
||||||
for SectionIterItem {
|
for SectionIterItem {
|
||||||
y: section_y,
|
y: section_y,
|
||||||
section,
|
section,
|
||||||
biomes: _,
|
biomes,
|
||||||
block_light,
|
block_light,
|
||||||
} in chunk.sections().rev()
|
} in chunk.sections().rev()
|
||||||
{
|
{
|
||||||
|
@ -133,6 +137,11 @@ pub fn top_layer(chunk: &Chunk) -> Result<Option<(Box<BlockInfoArray>, Box<Block
|
||||||
done += 1;
|
done += 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let biome_entry = &mut block_biomes[xz];
|
||||||
|
if !entry.is_none() && biome_entry.is_none() {
|
||||||
|
*biome_entry = biomes.biome_at(section_y, coords)?.copied();
|
||||||
|
}
|
||||||
|
|
||||||
if entry.is_none() {
|
if entry.is_none() {
|
||||||
light[xz] = block_light.block_light_at(coords);
|
light[xz] = block_light.block_light_at(coords);
|
||||||
}
|
}
|
||||||
|
@ -144,5 +153,5 @@ pub fn top_layer(chunk: &Chunk) -> Result<Option<(Box<BlockInfoArray>, Box<Block
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Some((blocks, light)))
|
Ok(Some(((blocks, block_biomes), light)))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue