From 4c2fd6c1a9d89b5ede1a74b53edae8b81b2b7b93 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 1 Mar 2023 22:45:56 +0100 Subject: [PATCH] resource: rename BlockTypeMap to BlockTypes The block_types() function it turned into a Default implementation. --- src/main.rs | 4 ++-- src/resource/mod.rs | 25 ++++++++++++++----------- src/world/layer.rs | 4 ++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 30b3b18..493b54f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,14 +50,14 @@ impl Paths { /// Type with methods for processing the regions of a Minecraft save directory struct RegionProcessor<'a> { - block_types: resource::BlockTypeMap, + block_types: resource::BlockTypes, paths: &'a Paths, } impl<'a> RegionProcessor<'a> { fn new(paths: &'a Paths) -> Self { RegionProcessor { - block_types: resource::block_types(), + block_types: resource::BlockTypes::default(), paths, } } diff --git a/src/resource/mod.rs b/src/resource/mod.rs index 1664d8b..ee409e6 100644 --- a/src/resource/mod.rs +++ b/src/resource/mod.rs @@ -53,21 +53,24 @@ impl BlockType { } } -pub struct BlockTypeMap(HashMap); +#[derive(Debug)] +pub struct BlockTypes(HashMap); -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 { 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(), - ) -} diff --git a/src/world/layer.rs b/src/world/layer.rs index 2232af8..0039136 100644 --- a/src/world/layer.rs +++ b/src/world/layer.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use super::chunk::Chunk; use crate::{ - resource::{BlockFlag, BlockType, BlockTypeMap}, + resource::{BlockFlag, BlockType, BlockTypes}, types::*, }; @@ -92,7 +92,7 @@ pub type BlockInfoArray = LayerBlockArray>; /// determined as the block that should be visible on the rendered /// map. For water blocks, the height of the first non-water block /// is additionally filled in as the water depth. -pub fn top_layer(chunk: &Chunk, block_types: &BlockTypeMap) -> Result> { +pub fn top_layer(chunk: &Chunk, block_types: &BlockTypes) -> Result> { use BLOCKS_PER_CHUNK as N; let mut done = 0;