use get_state_id instead of get_state when loading Chunks
This commit is contained in:
parent
a18d399ad1
commit
c19e6135d3
@ -10,6 +10,8 @@ use pumpkin_data::{
|
|||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
pub use state::RawBlockState;
|
pub use state::RawBlockState;
|
||||||
|
|
||||||
|
use crate::BlockStateId;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub struct BlockStateCodec {
|
pub struct BlockStateCodec {
|
||||||
@ -42,6 +44,12 @@ where
|
|||||||
|
|
||||||
impl BlockStateCodec {
|
impl BlockStateCodec {
|
||||||
pub fn get_state(&self) -> Option<&'static BlockState> {
|
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 block = self.name;
|
||||||
|
|
||||||
let mut state_id = block.default_state.id;
|
let mut state_id = block.default_state.id;
|
||||||
@ -54,8 +62,7 @@ impl BlockStateCodec {
|
|||||||
let block_properties = block.from_properties(props).unwrap();
|
let block_properties = block.from_properties(props).unwrap();
|
||||||
state_id = block_properties.to_state_id(block);
|
state_id = block_properties.to_state_id(block);
|
||||||
}
|
}
|
||||||
|
state_id
|
||||||
get_state_by_state_id(state_id)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -298,7 +298,7 @@ impl BiomePalette {
|
|||||||
|
|
||||||
Self::from_palette_and_packed_data(
|
Self::from_palette_and_packed_data(
|
||||||
&palette,
|
&palette,
|
||||||
nbt.data.as_ref().unwrap_or(&vec![].into_boxed_slice()),
|
nbt.data.as_ref().unwrap_or(&Box::default()),
|
||||||
BIOME_DISK_MIN_BITS,
|
BIOME_DISK_MIN_BITS,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -398,22 +398,12 @@ impl BlockPalette {
|
|||||||
let palette = nbt
|
let palette = nbt
|
||||||
.palette
|
.palette
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|entry| {
|
.map(|entry| entry.get_state_id())
|
||||||
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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Self::from_palette_and_packed_data(
|
Self::from_palette_and_packed_data(
|
||||||
&palette,
|
&palette,
|
||||||
nbt.data.as_ref().unwrap_or(&vec![].into_boxed_slice()),
|
nbt.data.as_ref().unwrap_or(&Box::default()),
|
||||||
BLOCK_DISK_MIN_BITS,
|
BLOCK_DISK_MIN_BITS,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,7 +138,8 @@ impl<'a> ProtoChunk<'a> {
|
|||||||
let sampler = FluidLevelSampler::Chunk(Box::new(StandardChunkFluidLevelSampler::new(
|
let sampler = FluidLevelSampler::Chunk(Box::new(StandardChunkFluidLevelSampler::new(
|
||||||
FluidLevel::new(
|
FluidLevel::new(
|
||||||
settings.sea_level,
|
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
|
FluidLevel::new(-54, &LAVA_BLOCK), // this is always the same for every dimension
|
||||||
)));
|
)));
|
||||||
|
|||||||
@ -12,6 +12,6 @@ pub struct RandomBlockStateMatchRuleTest {
|
|||||||
|
|
||||||
impl RandomBlockStateMatchRuleTest {
|
impl RandomBlockStateMatchRuleTest {
|
||||||
pub fn test(&self, state: &BlockState, random: &mut RandomGenerator) -> bool {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user