diff --git a/pumpkin-world/src/block/mod.rs b/pumpkin-world/src/block/mod.rs index 1c4211bdd..ee597090e 100644 --- a/pumpkin-world/src/block/mod.rs +++ b/pumpkin-world/src/block/mod.rs @@ -10,6 +10,8 @@ use pumpkin_data::{ use serde::{Deserialize, Deserializer, Serialize, Serializer}; pub use state::RawBlockState; +use crate::BlockStateId; + #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(rename_all = "PascalCase")] pub struct BlockStateCodec { @@ -42,6 +44,12 @@ where impl BlockStateCodec { pub fn get_state(&self) -> Option<&'static BlockState> { + let state_id = self.get_state_id(); + get_state_by_state_id(state_id) + } + + /// Prefer this over `get_state` when the only the state ID is needed + pub fn get_state_id(&self) -> BlockStateId { let block = self.name; let mut state_id = block.default_state.id; @@ -54,8 +62,7 @@ impl BlockStateCodec { let block_properties = block.from_properties(props).unwrap(); state_id = block_properties.to_state_id(block); } - - get_state_by_state_id(state_id) + state_id } } diff --git a/pumpkin-world/src/chunk/palette.rs b/pumpkin-world/src/chunk/palette.rs index 4763d96e7..22e5bdd9f 100644 --- a/pumpkin-world/src/chunk/palette.rs +++ b/pumpkin-world/src/chunk/palette.rs @@ -298,7 +298,7 @@ impl BiomePalette { Self::from_palette_and_packed_data( &palette, - nbt.data.as_ref().unwrap_or(&vec![].into_boxed_slice()), + nbt.data.as_ref().unwrap_or(&Box::default()), BIOME_DISK_MIN_BITS, ) } @@ -398,22 +398,12 @@ impl BlockPalette { let palette = nbt .palette .into_iter() - .map(|entry| { - if let Some(block_state) = entry.get_state() { - block_state.id - } else { - log::warn!( - "Could not find valid block state for {}. Defaulting...", - entry.name.name - ); - 0 - } - }) + .map(|entry| entry.get_state_id()) .collect::>(); Self::from_palette_and_packed_data( &palette, - nbt.data.as_ref().unwrap_or(&vec![].into_boxed_slice()), + nbt.data.as_ref().unwrap_or(&Box::default()), BLOCK_DISK_MIN_BITS, ) } diff --git a/pumpkin-world/src/generation/proto_chunk.rs b/pumpkin-world/src/generation/proto_chunk.rs index 1f5b65a48..20fe604a9 100644 --- a/pumpkin-world/src/generation/proto_chunk.rs +++ b/pumpkin-world/src/generation/proto_chunk.rs @@ -138,7 +138,8 @@ impl<'a> ProtoChunk<'a> { let sampler = FluidLevelSampler::Chunk(Box::new(StandardChunkFluidLevelSampler::new( FluidLevel::new( settings.sea_level, - settings.default_fluid.get_state().unwrap().block(), + // Block + settings.default_fluid.name, ), FluidLevel::new(-54, &LAVA_BLOCK), // this is always the same for every dimension ))); diff --git a/pumpkin-world/src/generation/rule/random_block_state_match.rs b/pumpkin-world/src/generation/rule/random_block_state_match.rs index f7f6f16c2..b792743da 100644 --- a/pumpkin-world/src/generation/rule/random_block_state_match.rs +++ b/pumpkin-world/src/generation/rule/random_block_state_match.rs @@ -12,6 +12,6 @@ pub struct RandomBlockStateMatchRuleTest { impl RandomBlockStateMatchRuleTest { pub fn test(&self, state: &BlockState, random: &mut RandomGenerator) -> bool { - state.id == self.block_state.get_state().unwrap().id && random.next_f32() < self.probability + state.id == self.block_state.get_state_id() && random.next_f32() < self.probability } }