diff --git a/src/world/chunk.rs b/src/world/chunk.rs index 53ee165..9285a16 100644 --- a/src/world/chunk.rs +++ b/src/world/chunk.rs @@ -112,27 +112,36 @@ impl<'a> Chunk<'a> { let mut section_map = BTreeMap::new(); for section in sections { - section_map.insert( - SectionY(section.y), - ( - SectionV1_13::new( - data_version, - section.block_states.data.as_deref(), - §ion.block_states.palette, - block_types, - ) - .with_context(|| format!("Failed to load section at Y={}", section.y))?, - BiomesV1_18::new( - section.biomes.data.as_deref(), - §ion.biomes.palette, - biome_types, - ) - .with_context(|| format!("Failed to load section biomes at Y={}", section.y))?, - BlockLight::new(section.block_light.as_deref()).with_context(|| { - format!("Failed to load section block light at Y={}", section.y) - })?, - ), - ); + match §ion.section { + de::SectionV1_18Variants::V1_18 { + block_states, + biomes, + block_light, + } => { + section_map.insert( + SectionY(section.y), + ( + SectionV1_13::new( + data_version, + block_states.data.as_deref(), + &block_states.palette, + block_types, + ) + .with_context(|| { + format!("Failed to load section at Y={}", section.y) + })?, + BiomesV1_18::new(biomes.data.as_deref(), &biomes.palette, biome_types) + .with_context(|| { + format!("Failed to load section biomes at Y={}", section.y) + })?, + BlockLight::new(block_light.as_deref()).with_context(|| { + format!("Failed to load section block light at Y={}", section.y) + })?, + ), + ); + } + de::SectionV1_18Variants::Empty {} => {} + }; } Ok(Chunk::V1_18 { section_map }) diff --git a/src/world/de.rs b/src/world/de.rs index cbedf31..5c8f84f 100644 --- a/src/world/de.rs +++ b/src/world/de.rs @@ -28,19 +28,33 @@ pub struct BiomesV1_18 { pub data: Option, } +/// Variable part of a [SectionV1_18] +#[derive(Debug, Deserialize)] +#[serde(untagged)] +pub enum SectionV1_18Variants { + /// Populated 1.18+ section + V1_18 { + /// Block type data + block_states: BlockStatesV1_18, + /// Biome data + biomes: BiomesV1_18, + /// Block light data + #[serde(rename = "BlockLight")] + block_light: Option, + }, + /// Empty section + Empty {}, +} + /// Element of the 1.18+ `sections` list found in a [Chunk] #[derive(Debug, Deserialize)] pub struct SectionV1_18 { /// Y coordinate #[serde(rename = "Y")] pub y: i32, - /// Block type data - pub block_states: BlockStatesV1_18, - /// Biome data - pub biomes: BiomesV1_18, - /// Block light data - #[serde(rename = "BlockLight")] - pub block_light: Option, + /// Variable part of section + #[serde(flatten)] + pub section: SectionV1_18Variants, } /// Version-specific part of a pre-1.18 [Section](SectionV0)