Skip to main content

azalea_world/
biome_id.rs

1use std::io;
2
3use azalea_buf::BufReadError;
4use azalea_registry::{Registry, data::Biome, registry_holder::RegistryHolder};
5
6/// An unresolved biome.
7///
8/// This can be freely converted to and from a biome, as long as you have the
9/// required registries.
10#[derive(PartialEq, Eq, Default, Debug, Clone, Copy)]
11pub struct BiomeId(pub u32);
12impl From<u32> for BiomeId {
13    fn from(id: u32) -> Self {
14        Self(id)
15    }
16}
17impl From<BiomeId> for u32 {
18    fn from(b: BiomeId) -> Self {
19        b.0
20    }
21}
22
23impl BiomeId {
24    /// Resolve this ID into a proper biome.
25    pub fn into_biome(&self, registries: &RegistryHolder) -> Result<Biome, BufReadError> {
26        Biome::from_id(registries.into(), self.0)
27    }
28    /// Convert a biome into its ID.
29    pub fn from_biome(registries: &RegistryHolder, biome: Biome) -> io::Result<BiomeId> {
30        biome.to_id(registries.into()).map(BiomeId)
31    }
32}