From c6843cfb9c0af41fa93fe5168f4cce33a28d2dcf Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 7 Apr 2023 09:38:31 +0200 Subject: [PATCH] world: resolve biome palette entries for v1.18 biome data --- src/world/section.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/world/section.rs b/src/world/section.rs index f960d16..5d2781a 100644 --- a/src/world/section.rs +++ b/src/world/section.rs @@ -5,7 +5,7 @@ use num_integer::div_rem; use super::de; use crate::{ - resource::{BiomeTypes, BlockType, BlockTypes}, + resource::{Biome, BiomeTypes, BlockType, BlockTypes}, types::*, }; @@ -177,7 +177,7 @@ impl<'a> Section for SectionV0<'a> { #[derive(Debug)] pub struct BiomesV1_18<'a> { _biomes: Option<&'a [i64]>, - _palette: &'a [String], + _palette: Vec>, _bits: u8, } @@ -186,7 +186,7 @@ impl<'a> BiomesV1_18<'a> { pub fn new( biomes: Option<&'a [i64]>, palette: &'a [String], - _biome_types: &'a BiomeTypes, + biome_types: &'a BiomeTypes, ) -> Result { let bits = palette_bits(palette.len(), 1, 6).context("Unsupported block palette size")?; @@ -198,9 +198,20 @@ impl<'a> BiomesV1_18<'a> { } } + let palette_types = palette + .iter() + .map(|entry| { + let biome_type = biome_types.get(entry); + if biome_type.is_none() { + eprintln!("Unknown biome type: {}", entry); + } + biome_type + }) + .collect(); + Ok(BiomesV1_18 { _biomes: biomes, - _palette: palette, + _palette: palette_types, _bits: bits, }) }