resource, world: implement fallback to plains for unknown biomes

Closes #63
This commit is contained in:
Matthias Schiffer 2025-02-11 22:39:11 +01:00
parent d7fc95c950
commit a10151a4f3
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
5 changed files with 37 additions and 18 deletions

View file

@ -247,6 +247,8 @@ pub struct BiomeTypes {
biome_map: HashMap<String, &'static Biome>,
/// Array used to look up old numeric biome IDs
legacy_biomes: Box<[&'static Biome; 256]>,
/// Fallback for unknown (new/modded) biomes
fallback_biome: &'static Biome,
}
impl Default for BiomeTypes {
@ -273,9 +275,12 @@ impl Default for BiomeTypes {
.try_into()
.unwrap();
let fallback_biome = *biome_map.get("plains").expect("Plains biome undefined");
Self {
biome_map,
legacy_biomes,
fallback_biome,
}
}
}
@ -293,4 +298,10 @@ impl BiomeTypes {
pub fn get_legacy(&self, id: u8) -> Option<&Biome> {
Some(self.legacy_biomes[id as usize])
}
/// Returns the fallback for unknown (new/modded) biomes
#[inline]
pub fn get_fallback(&self) -> &Biome {
self.fallback_biome
}
}