world/section: move biome_types field out of BiomesV0 enum

This commit is contained in:
Matthias Schiffer 2023-04-08 10:48:00 +02:00
parent 3ea93296d7
commit aa2edc3d13
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C

View file

@ -217,24 +217,22 @@ impl<'a> BiomesV1_18<'a> {
}
}
/// Pre-v1.18 section biome data
/// Pre-v1.18 section biome data variants
///
/// 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 {
data: &'a fastnbt::IntArray,
biome_types: &'a BiomeTypes,
},
IntArrayV0 {
data: &'a fastnbt::IntArray,
biome_types: &'a BiomeTypes,
},
ByteArray {
data: &'a fastnbt::ByteArray,
biome_types: &'a BiomeTypes,
},
enum BiomesV0Data<'a> {
IntArrayV15(&'a fastnbt::IntArray),
IntArrayV0(&'a fastnbt::IntArray),
ByteArray(&'a fastnbt::ByteArray),
}
/// Pre-v1.18 section biome data
#[derive(Debug)]
pub struct BiomesV0<'a> {
data: BiomesV0Data<'a>,
biome_types: &'a BiomeTypes,
}
impl<'a> BiomesV0<'a> {
@ -245,18 +243,19 @@ impl<'a> BiomesV0<'a> {
const BN: usize = N >> 2;
const BMAXY: usize = MAXY >> 2;
Ok(match biomes {
let data = match biomes {
Some(de::BiomesV0::IntArray(data)) if data.len() == BN * BN * BMAXY => {
BiomesV0::IntArrayV15 { data, biome_types }
BiomesV0Data::IntArrayV15(data)
}
Some(de::BiomesV0::IntArray(data)) if data.len() == N * N => {
BiomesV0::IntArrayV0 { data, biome_types }
BiomesV0Data::IntArrayV0(data)
}
Some(de::BiomesV0::ByteArray(data)) if data.len() == N * N => {
BiomesV0::ByteArray { data, biome_types }
BiomesV0Data::ByteArray(data)
}
_ => bail!("Invalid biome data"),
})
};
Ok(BiomesV0 { data, biome_types })
}
}