resource: rename BlockTypeMap to BlockTypes

The block_types() function it turned into a Default implementation.
This commit is contained in:
Matthias Schiffer 2023-03-01 22:45:56 +01:00
parent 95e4e45974
commit 4c2fd6c1a9
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
3 changed files with 18 additions and 15 deletions

View file

@ -53,21 +53,24 @@ impl BlockType {
}
}
pub struct BlockTypeMap(HashMap<String, BlockType>);
#[derive(Debug)]
pub struct BlockTypes(HashMap<String, BlockType>);
impl BlockTypeMap {
impl Default for BlockTypes {
fn default() -> Self {
BlockTypes(
block_types::BLOCK_TYPES
.iter()
.map(|(k, v)| (String::from(*k), *v))
.collect(),
)
}
}
impl BlockTypes {
#[inline]
pub fn get(&self, id: &str) -> Option<BlockType> {
let suffix = id.strip_prefix("minecraft:")?;
self.0.get(suffix).copied()
}
}
pub fn block_types() -> BlockTypeMap {
BlockTypeMap(
block_types::BLOCK_TYPES
.iter()
.map(|(k, v)| (String::from(*k), *v))
.collect(),
)
}