mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 01:24:53 +01:00
world: distinguish pre-v1.18 biome data structures
This commit is contained in:
parent
e62e19796c
commit
f2b7808e84
2 changed files with 33 additions and 4 deletions
|
@ -24,14 +24,14 @@ pub enum Chunk<'a> {
|
||||||
/// block IDs
|
/// block IDs
|
||||||
V1_13 {
|
V1_13 {
|
||||||
section_map: BTreeMap<SectionY, (SectionV1_13<'a>, BlockLight<'a>)>,
|
section_map: BTreeMap<SectionY, (SectionV1_13<'a>, BlockLight<'a>)>,
|
||||||
biomes: &'a de::BiomesV0,
|
biomes: BiomesV0<'a>,
|
||||||
},
|
},
|
||||||
/// Original pre-1.13 chunk
|
/// Original pre-1.13 chunk
|
||||||
///
|
///
|
||||||
/// The original chunk format with fixed 8-bit numeric block IDs
|
/// The original chunk format with fixed 8-bit numeric block IDs
|
||||||
V0 {
|
V0 {
|
||||||
section_map: BTreeMap<SectionY, (SectionV0<'a>, BlockLight<'a>)>,
|
section_map: BTreeMap<SectionY, (SectionV0<'a>, BlockLight<'a>)>,
|
||||||
biomes: &'a de::BiomesV0,
|
biomes: BiomesV0<'a>,
|
||||||
},
|
},
|
||||||
/// Unpopulated chunk without any block data
|
/// Unpopulated chunk without any block data
|
||||||
Empty,
|
Empty,
|
||||||
|
@ -158,8 +158,7 @@ impl<'a> Chunk<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Check biomes length
|
let biomes = BiomesV0::new(level.biomes.as_ref());
|
||||||
let biomes = level.biomes.as_ref().context("Invalid biome data");
|
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
match (section_map_v1_13.is_empty(), section_map_v0.is_empty()) {
|
match (section_map_v1_13.is_empty(), section_map_v0.is_empty()) {
|
||||||
|
|
|
@ -202,6 +202,36 @@ impl<'a> BiomesV18<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pre-v1.18 section biome data
|
||||||
|
///
|
||||||
|
/// There are a 3 formats for biome data that were used in
|
||||||
|
/// different pre-v1.18 Minecraft versions
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum BiomesV0<'a> {
|
||||||
|
IntArrayV15(&'a fastnbt::IntArray),
|
||||||
|
IntArrayV0(&'a fastnbt::IntArray),
|
||||||
|
ByteArray(&'a fastnbt::ByteArray),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> BiomesV0<'a> {
|
||||||
|
/// Constructs a new [BiomesV0] from deserialized data structures
|
||||||
|
pub fn new(biomes: Option<&'a de::BiomesV0>) -> Result<Self> {
|
||||||
|
const N: usize = BLOCKS_PER_CHUNK;
|
||||||
|
const MAXY: usize = 256;
|
||||||
|
const BN: usize = N >> 2;
|
||||||
|
const BMAXY: usize = MAXY >> 2;
|
||||||
|
|
||||||
|
Ok(match biomes {
|
||||||
|
Some(de::BiomesV0::IntArray(data)) if data.len() == BN * BN * BMAXY => {
|
||||||
|
BiomesV0::IntArrayV15(data)
|
||||||
|
}
|
||||||
|
Some(de::BiomesV0::IntArray(data)) if data.len() == N * N => BiomesV0::IntArrayV0(data),
|
||||||
|
Some(de::BiomesV0::ByteArray(data)) if data.len() == N * N => BiomesV0::ByteArray(data),
|
||||||
|
_ => bail!("Invalid biome data"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct BlockLight<'a>(Option<&'a [i8]>);
|
pub struct BlockLight<'a>(Option<&'a [i8]>);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue