Only store state id in RawBlockState

This theoretically cuts the internal memory usage of chunk data in half since we no longer save the block id
This commit is contained in:
Alexander Medvedev
2025-04-12 12:57:09 +02:00
parent 7180ea69ee
commit aedb29f3fc
12 changed files with 238 additions and 350 deletions

View File

@@ -2,28 +2,24 @@ use pumpkin_data::block::Block;
use quote::quote;
pub(crate) fn block_state_impl(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
pub(crate) fn default_block_state_impl(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input_string = item.to_string();
let registry_id = input_string.trim_matches('"');
let state = Block::from_registry_key(registry_id).expect("Invalid registry id");
let default_state_id = state.default_state_id;
let block_id = state.id;
if std::env::var("CARGO_PKG_NAME").unwrap() == "pumpkin-world" {
quote! {
crate::block::ChunkBlockState {
crate::block::RawBlockState {
state_id: #default_state_id,
block_id: #block_id,
}
}
.into()
} else {
quote! {
pumpkin_world::block::ChunkBlockState {
pumpkin_world::block::RawBlockState {
state_id: #default_state_id,
block_id: #block_id,
}
}
.into()

View File

@@ -340,8 +340,8 @@ pub fn block_property(input: TokenStream, item: TokenStream) -> TokenStream {
mod block_state;
#[proc_macro]
pub fn block_state(item: TokenStream) -> TokenStream {
block_state::block_state_impl(item)
pub fn default_block_state(item: TokenStream) -> TokenStream {
block_state::default_block_state_impl(item)
}
mod block;
#[proc_macro]

View File

@@ -7,7 +7,7 @@ use pumpkin_data::block::{Axis, Facing, HorizontalFacing};
use pumpkin_util::math::vector3::Vector3;
use serde::Deserialize;
pub use state::ChunkBlockState;
pub use state::RawBlockState;
#[derive(FromPrimitive, PartialEq, Clone, Copy, Debug, Hash, Eq)]
pub enum BlockDirection {

View File

@@ -1,31 +1,27 @@
use crate::chunk::format::PaletteBlockEntry;
use super::registry::{get_block, get_state_by_state_id};
use super::registry::{get_block, get_block_by_state_id, get_state_by_state_id};
/// Instead of using a memory heavy normal BlockState This is used for internal representation in chunks to save memory
#[derive(Clone, Copy, Debug, Eq)]
pub struct ChunkBlockState {
pub struct RawBlockState {
pub state_id: u16,
pub block_id: u16,
}
impl PartialEq for ChunkBlockState {
impl PartialEq for RawBlockState {
fn eq(&self, other: &Self) -> bool {
self.state_id == other.state_id
}
}
impl ChunkBlockState {
pub const AIR: ChunkBlockState = ChunkBlockState {
state_id: 0,
block_id: 0,
};
impl RawBlockState {
pub const AIR: RawBlockState = RawBlockState { state_id: 0 };
/// Get a Block from the Vanilla Block registry at Runtime
pub fn new(registry_id: &str) -> Option<Self> {
let block = get_block(registry_id);
block.map(|block| Self {
state_id: block.default_state_id,
block_id: block.id,
})
}
@@ -44,10 +40,7 @@ impl ChunkBlockState {
state_id = block_properties.to_state_id(&block);
}
return Some(Self {
state_id,
block_id: block.id,
});
return Some(Self { state_id });
}
None
@@ -57,30 +50,28 @@ impl ChunkBlockState {
self.state_id
}
#[inline]
pub fn is_air(&self) -> bool {
get_state_by_state_id(self.state_id).unwrap().air
pub fn to_state(&self) -> pumpkin_data::block::BlockState {
get_state_by_state_id(self.state_id).unwrap()
}
#[inline]
pub fn of_block(&self, block_id: u16) -> bool {
self.block_id == block_id
pub fn to_block(&self) -> pumpkin_data::block::Block {
get_block_by_state_id(self.state_id).unwrap()
}
}
#[cfg(test)]
mod tests {
use super::ChunkBlockState;
use super::RawBlockState;
#[test]
fn not_existing() {
let result = ChunkBlockState::new("this_block_does_not_exist");
let result = RawBlockState::new("this_block_does_not_exist");
assert!(result.is_none());
}
#[test]
fn does_exist() {
let result = ChunkBlockState::new("dirt");
let result = RawBlockState::new("dirt");
assert!(result.is_some());
}
}

View File

@@ -5,10 +5,9 @@ use std::{
};
use pumpkin_data::{block::Block, chunk::Biome};
use pumpkin_macros::block_state;
use pumpkin_util::encompassing_bits;
use crate::block::ChunkBlockState;
use crate::block::{RawBlockState, registry::get_state_by_state_id};
use super::format::{
ChunkSectionBiomes, ChunkSectionBlockStates, PaletteBiomeEntry, PaletteBlockEntry,
@@ -17,16 +16,6 @@ use super::format::{
/// 3d array indexed by y,z,x
type AbstractCube<T, const DIM: usize> = [[[T; DIM]; DIM]; DIM];
// TODO: Verify the default state for these blocks is the only state
const AIR: ChunkBlockState = block_state!("air");
const CAVE_AIR: ChunkBlockState = block_state!("cave_air");
const VOID_AIR: ChunkBlockState = block_state!("void_air");
#[inline]
fn is_not_air_block(state_id: u16) -> bool {
state_id != AIR.state_id && state_id != CAVE_AIR.state_id && state_id != VOID_AIR.state_id
}
#[derive(Debug)]
pub struct HeterogeneousPaletteData<V: Hash + Eq + Copy, const DIM: usize> {
cube: Box<AbstractCube<V, DIM>>,
@@ -384,7 +373,7 @@ impl BlockPalette {
pub fn non_air_block_count(&self) -> u16 {
match self {
Self::Homogeneous(registry_id) => {
if is_not_air_block(*registry_id) {
if !get_state_by_state_id(*registry_id).unwrap().air {
Self::VOLUME as u16
} else {
0
@@ -394,7 +383,7 @@ impl BlockPalette {
.counts
.iter()
.map(|(registry_id, count)| {
if is_not_air_block(*registry_id) {
if !get_state_by_state_id(*registry_id).unwrap().air {
*count
} else {
0
@@ -409,7 +398,7 @@ impl BlockPalette {
.palette
.into_iter()
.map(|entry| {
if let Some(block_state) = ChunkBlockState::from_palette(&entry) {
if let Some(block_state) = RawBlockState::from_palette(&entry) {
block_state.get_id()
} else {
log::warn!(

View File

@@ -4,7 +4,7 @@ use pumpkin_util::{
random::{RandomDeriver, RandomDeriverImpl, RandomImpl},
};
use crate::block::ChunkBlockState;
use crate::block::RawBlockState;
use super::{
chunk_noise::{LAVA_BLOCK, WATER_BLOCK},
@@ -22,11 +22,11 @@ use super::{
#[derive(Clone)]
pub struct FluidLevel {
max_y: i32,
state: ChunkBlockState,
state: RawBlockState,
}
impl FluidLevel {
pub fn new(max_y: i32, state: ChunkBlockState) -> Self {
pub fn new(max_y: i32, state: RawBlockState) -> Self {
Self { max_y, state }
}
@@ -34,11 +34,11 @@ impl FluidLevel {
self.max_y
}
fn get_block_state(&self, y: i32) -> ChunkBlockState {
fn get_block_state(&self, y: i32) -> RawBlockState {
if y < self.max_y {
self.state
} else {
ChunkBlockState::AIR
RawBlockState::AIR
}
}
}
@@ -51,11 +51,11 @@ pub enum FluidLevelSampler {
pub struct StaticFluidLevelSampler {
y: i32,
state: ChunkBlockState,
state: RawBlockState,
}
impl StaticFluidLevelSampler {
pub fn new(y: i32, state: ChunkBlockState) -> Self {
pub fn new(y: i32, state: RawBlockState) -> Self {
Self { y, state }
}
}
@@ -196,13 +196,11 @@ impl WorldAquiferSampler {
level_2: FluidLevel,
) -> f64 {
let y = pos.y();
let block_state1 = level_1.get_block_state(y);
let block_state2 = level_2.get_block_state(y);
let block_state1 = level_1.get_block_state(y).to_block();
let block_state2 = level_2.get_block_state(y).to_block();
if (!block_state1.of_block(LAVA_BLOCK.block_id)
|| !block_state2.of_block(WATER_BLOCK.block_id))
&& (!block_state1.of_block(WATER_BLOCK.block_id)
|| !block_state2.of_block(LAVA_BLOCK.block_id))
if (block_state1 != LAVA_BLOCK.to_block() || block_state2 != WATER_BLOCK.to_block())
&& (block_state1 != WATER_BLOCK.to_block() || block_state2 != LAVA_BLOCK.to_block())
{
let level_diff = (level_1.max_y - level_2.max_y).abs();
if level_diff == 0 {
@@ -289,7 +287,7 @@ impl WorldAquiferSampler {
let bl3 = j > o;
if bl3 || bl2 {
let fluid_level = self.fluid_level.get_fluid_level(x, o, z);
if !fluid_level.get_block_state(o).is_air() {
if !fluid_level.get_block_state(o).to_state().air {
if bl2 {
bl = true;
}
@@ -413,10 +411,10 @@ impl WorldAquiferSampler {
level: i32,
router: &mut ChunkNoiseRouter,
sample_options: &ChunkNoiseFunctionSampleOptions,
) -> ChunkBlockState {
) -> RawBlockState {
if level <= -10
&& level != MIN_HEIGHT_CELL
&& !default_level.state.of_block(LAVA_BLOCK.block_id)
&& default_level.state.to_block() != LAVA_BLOCK.to_block()
{
let x = floor_div(block_x, 64);
let y = floor_div(block_y, 40);
@@ -439,7 +437,7 @@ impl WorldAquiferSampler {
sample_options: &ChunkNoiseFunctionSampleOptions,
height_estimator: &mut SurfaceHeightEstimateSampler,
density: f64,
) -> Option<ChunkBlockState> {
) -> Option<RawBlockState> {
if density > 0f64 {
None
} else {
@@ -448,7 +446,7 @@ impl WorldAquiferSampler {
let k = pos.z();
let fluid_level = self.fluid_level.get_fluid_level(i, j, k);
if fluid_level.get_block_state(j).of_block(LAVA_BLOCK.block_id) {
if fluid_level.get_block_state(j).to_block() == LAVA_BLOCK.to_block() {
Some(LAVA_BLOCK)
} else {
let scaled_x = floor_div(i - 5, 16);
@@ -509,12 +507,13 @@ impl WorldAquiferSampler {
// TODO: Handle fluid tick
Some(block_state)
} else if block_state.of_block(WATER_BLOCK.block_id)
} else if block_state.to_block() == WATER_BLOCK.to_block()
&& self
.fluid_level
.get_fluid_level(i, j - 1, k)
.get_block_state(j - 1)
.of_block(LAVA_BLOCK.block_id)
.to_block()
== LAVA_BLOCK.to_block()
{
Some(block_state)
} else {
@@ -595,7 +594,7 @@ impl AquiferSamplerImpl for WorldAquiferSampler {
pos: &impl NoisePos,
sample_options: &ChunkNoiseFunctionSampleOptions,
height_estimator: &mut SurfaceHeightEstimateSampler,
) -> Option<ChunkBlockState> {
) -> Option<RawBlockState> {
let density = router.final_density(pos, sample_options);
self.apply_internal(router, pos, sample_options, height_estimator, density)
}
@@ -618,7 +617,7 @@ impl AquiferSamplerImpl for SeaLevelAquiferSampler {
pos: &impl NoisePos,
sample_options: &ChunkNoiseFunctionSampleOptions,
_height_estimator: &mut SurfaceHeightEstimateSampler,
) -> Option<ChunkBlockState> {
) -> Option<RawBlockState> {
let sample = router.final_density(pos, sample_options);
//log::debug!("Aquifer sample {:?}: {}", &pos, sample);
if sample > 0f64 {
@@ -641,7 +640,7 @@ pub trait AquiferSamplerImpl {
pos: &impl NoisePos,
sample_options: &ChunkNoiseFunctionSampleOptions,
height_estimator: &mut SurfaceHeightEstimateSampler,
) -> Option<ChunkBlockState>;
) -> Option<RawBlockState>;
}
#[cfg(test)]
@@ -652,7 +651,7 @@ mod test {
use pumpkin_util::math::vector2::Vector2;
use crate::{
block::ChunkBlockState,
block::RawBlockState,
generation::{
GlobalRandomConfig, biome_coords,
chunk_noise::{
@@ -1654,51 +1653,42 @@ mod test {
((112, 60, 74, 0.20387997189913717), None),
(
(112, 80, 64, -0.28931054817132484),
Some(ChunkBlockState::AIR),
),
(
(112, 80, 66, -0.2808098154769529),
Some(ChunkBlockState::AIR),
),
(
(112, 80, 68, -0.2806908647477032),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((112, 80, 66, -0.2808098154769529), Some(RawBlockState::AIR)),
((112, 80, 68, -0.2806908647477032), Some(RawBlockState::AIR)),
(
(112, 80, 70, -0.28068300576359284),
Some(ChunkBlockState::AIR),
),
(
(112, 80, 72, -0.2805878392398348),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((112, 80, 72, -0.2805878392398348), Some(RawBlockState::AIR)),
(
(112, 80, 74, -0.27824504138444317),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(112, 100, 64, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(112, 100, 66, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(112, 100, 68, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(112, 100, 70, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(112, 100, 72, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(112, 100, 74, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((114, -100, 64, 0.037482421875), None),
((114, -100, 66, 0.037482421875), None),
@@ -1754,53 +1744,38 @@ mod test {
((114, 60, 70, 0.10529675531043547), None),
((114, 60, 72, 0.1261191394093652), None),
((114, 60, 74, 0.15323465023530602), None),
(
(114, 80, 64, -0.3135251519473628),
Some(ChunkBlockState::AIR),
),
(
(114, 80, 66, -0.3092766951165722),
Some(ChunkBlockState::AIR),
),
(
(114, 80, 68, -0.3063751991759311),
Some(ChunkBlockState::AIR),
),
(
(114, 80, 70, -0.3004342091280733),
Some(ChunkBlockState::AIR),
),
((114, 80, 64, -0.3135251519473628), Some(RawBlockState::AIR)),
((114, 80, 66, -0.3092766951165722), Some(RawBlockState::AIR)),
((114, 80, 68, -0.3063751991759311), Some(RawBlockState::AIR)),
((114, 80, 70, -0.3004342091280733), Some(RawBlockState::AIR)),
(
(114, 80, 72, -0.29703745590700253),
Some(ChunkBlockState::AIR),
),
(
(114, 80, 74, -0.2920638815250855),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((114, 80, 74, -0.2920638815250855), Some(RawBlockState::AIR)),
(
(114, 100, 64, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(114, 100, 66, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(114, 100, 68, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(114, 100, 70, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(114, 100, 72, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(114, 100, 74, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((116, -100, 64, 0.037482421875), None),
((116, -100, 66, 0.037482421875), None),
@@ -1847,11 +1822,11 @@ mod test {
((116, 40, 64, -0.009355588931802767), None),
(
(116, 40, 66, -0.006094366713842806),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(116, 40, 68, -0.0027537988904787606),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((116, 40, 70, 6.165942717199293E-4), None),
((116, 40, 72, 0.00396682662711753), None),
@@ -1862,53 +1837,44 @@ mod test {
((116, 60, 70, 0.053305618429865455), None),
((116, 60, 72, 0.06694547220363958), None),
((116, 60, 74, 0.08711813973093903), None),
(
(116, 80, 64, -0.3326652310213258),
Some(ChunkBlockState::AIR),
),
((116, 80, 64, -0.3326652310213258), Some(RawBlockState::AIR)),
(
(116, 80, 66, -0.32962834810938174),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(116, 80, 68, -0.32236370014057947),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(116, 80, 70, -0.31670491006554574),
Some(ChunkBlockState::AIR),
),
(
(116, 80, 72, -0.3130639601887072),
Some(ChunkBlockState::AIR),
),
(
(116, 80, 74, -0.3124769234268471),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((116, 80, 72, -0.3130639601887072), Some(RawBlockState::AIR)),
((116, 80, 74, -0.3124769234268471), Some(RawBlockState::AIR)),
(
(116, 100, 64, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(116, 100, 66, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(116, 100, 68, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(116, 100, 70, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(116, 100, 72, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(116, 100, 74, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((118, -100, 64, 0.037482421875), None),
((118, -100, 66, 0.037482421875), None),
@@ -1955,23 +1921,23 @@ mod test {
((118, 40, 64, -0.016298811685686653), None),
(
(118, 40, 66, -0.016656636719901533),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 40, 68, -0.01330299024830442),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 40, 70, -0.009864486324034218),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 40, 72, -0.006380723268648157),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 40, 74, -0.002886835272463701),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((118, 60, 64, 0.006086790713922152), None),
((118, 60, 66, 0.006014479808113486), None),
@@ -1979,53 +1945,47 @@ mod test {
((118, 60, 70, 0.011915636473415587), None),
((118, 60, 72, 0.01001192490238903), None),
((118, 60, 74, 0.0075500927486281426), None),
(
(118, 80, 64, -0.3462118919745469),
Some(ChunkBlockState::AIR),
),
((118, 80, 64, -0.3462118919745469), Some(RawBlockState::AIR)),
(
(118, 80, 66, -0.34419241078645835),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 80, 68, -0.33580861045450133),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 80, 70, -0.33008534054566163),
Some(ChunkBlockState::AIR),
),
(
(118, 80, 72, -0.333649815109498),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((118, 80, 72, -0.333649815109498), Some(RawBlockState::AIR)),
(
(118, 80, 74, -0.33771329428807284),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 100, 64, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 100, 66, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 100, 68, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 100, 70, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 100, 72, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(118, 100, 74, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((120, -100, 64, 0.037482421875), None),
((120, -100, 66, 0.037482421875), None),
@@ -2072,23 +2032,23 @@ mod test {
((120, 40, 64, -0.017456523705167773), None),
(
(120, 40, 66, -0.020044623482270124),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(120, 40, 68, -0.022372181411266172),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(120, 40, 70, -0.020228945291907708),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(120, 40, 72, -0.01664436674077766),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(120, 40, 74, -0.013001583733654043),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((120, 60, 64, -0.010805185122555435), Some(WATER_BLOCK)),
((120, 60, 66, -0.011684313707812422), Some(WATER_BLOCK)),
@@ -2096,53 +2056,41 @@ mod test {
((120, 60, 70, -0.012326309226980426), Some(WATER_BLOCK)),
((120, 60, 72, -0.019043795741958334), Some(WATER_BLOCK)),
((120, 60, 74, -0.023185441889689514), Some(WATER_BLOCK)),
(
(120, 80, 64, -0.3611328625547435),
Some(ChunkBlockState::AIR),
),
(
(120, 80, 66, -0.3586517592327399),
Some(ChunkBlockState::AIR),
),
(
(120, 80, 68, -0.3524534485283812),
Some(ChunkBlockState::AIR),
),
((120, 80, 64, -0.3611328625547435), Some(RawBlockState::AIR)),
((120, 80, 66, -0.3586517592327399), Some(RawBlockState::AIR)),
((120, 80, 68, -0.3524534485283812), Some(RawBlockState::AIR)),
(
(120, 80, 70, -0.35323218454039057),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(120, 80, 72, -0.36213549677301105),
Some(ChunkBlockState::AIR),
),
(
(120, 80, 74, -0.3684474143996314),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((120, 80, 74, -0.3684474143996314), Some(RawBlockState::AIR)),
(
(120, 100, 64, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(120, 100, 66, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(120, 100, 68, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(120, 100, 70, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(120, 100, 72, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(120, 100, 74, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((122, -100, 64, 0.037482421875), None),
((122, -100, 66, 0.037482421875), None),
@@ -2189,19 +2137,19 @@ mod test {
((122, 40, 64, -0.013498316953033454), None),
(
(122, 40, 66, -0.016896390550754353),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(122, 40, 68, -0.01994683889106233),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(122, 40, 70, -0.022658183924480487),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(122, 40, 72, -0.02460705550987633),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((122, 40, 74, -0.02133677750482264), None),
((122, 60, 64, -0.02580014098083049), Some(WATER_BLOCK)),
@@ -2212,51 +2160,39 @@ mod test {
((122, 60, 74, -0.04490159197647781), Some(WATER_BLOCK)),
(
(122, 80, 64, -0.37247525946547166),
Some(ChunkBlockState::AIR),
),
(
(122, 80, 66, -0.3727266378002749),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((122, 80, 66, -0.3727266378002749), Some(RawBlockState::AIR)),
(
(122, 80, 68, -0.36804742745663505),
Some(ChunkBlockState::AIR),
),
(
(122, 80, 70, -0.3736723706537362),
Some(ChunkBlockState::AIR),
),
(
(122, 80, 72, -0.3860951288334311),
Some(ChunkBlockState::AIR),
),
(
(122, 80, 74, -0.3923721309133264),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((122, 80, 70, -0.3736723706537362), Some(RawBlockState::AIR)),
((122, 80, 72, -0.3860951288334311), Some(RawBlockState::AIR)),
((122, 80, 74, -0.3923721309133264), Some(RawBlockState::AIR)),
(
(122, 100, 64, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(122, 100, 66, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(122, 100, 68, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(122, 100, 70, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(122, 100, 72, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(122, 100, 74, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((124, -100, 64, 0.037482421875), None),
((124, -100, 66, 0.037482421875), None),
@@ -2312,53 +2248,44 @@ mod test {
((124, 60, 70, -0.04106936165998065), Some(WATER_BLOCK)),
((124, 60, 72, -0.048715160337165046), Some(WATER_BLOCK)),
((124, 60, 74, -0.053817378732386144), Some(WATER_BLOCK)),
(
(124, 80, 64, -0.378513110274629),
Some(ChunkBlockState::AIR),
),
((124, 80, 64, -0.378513110274629), Some(RawBlockState::AIR)),
(
(124, 80, 66, -0.37887533037235366),
Some(ChunkBlockState::AIR),
),
(
(124, 80, 68, -0.3755672366866089),
Some(ChunkBlockState::AIR),
),
(
(124, 80, 70, -0.3806264904596738),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((124, 80, 68, -0.3755672366866089), Some(RawBlockState::AIR)),
((124, 80, 70, -0.3806264904596738), Some(RawBlockState::AIR)),
(
(124, 80, 72, -0.39139114552312176),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(124, 80, 74, -0.39905004304932734),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(124, 100, 64, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(124, 100, 66, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(124, 100, 68, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(124, 100, 70, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(124, 100, 72, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(124, 100, 74, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((126, -100, 64, 0.037482421875), None),
((126, -100, 66, 0.037482421875), None),
@@ -2416,51 +2343,42 @@ mod test {
((126, 60, 74, -0.05663750895047857), Some(WATER_BLOCK)),
(
(126, 80, 64, -0.37931742687180287),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(126, 80, 66, -0.38265481838544235),
Some(ChunkBlockState::AIR),
),
(
(126, 80, 68, -0.3808041835281554),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((126, 80, 68, -0.3808041835281554), Some(RawBlockState::AIR)),
(
(126, 80, 70, -0.38160238129796925),
Some(ChunkBlockState::AIR),
),
(
(126, 80, 72, -0.387746448733821),
Some(ChunkBlockState::AIR),
),
(
(126, 80, 74, -0.3990668807989283),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
((126, 80, 72, -0.387746448733821), Some(RawBlockState::AIR)),
((126, 80, 74, -0.3990668807989283), Some(RawBlockState::AIR)),
(
(126, 100, 64, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(126, 100, 66, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(126, 100, 68, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(126, 100, 70, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(126, 100, 72, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
(
(126, 100, 74, -0.4583333333333333),
Some(ChunkBlockState::AIR),
Some(RawBlockState::AIR),
),
];

View File

@@ -1,7 +1,7 @@
use pumpkin_macros::block_state;
use pumpkin_macros::default_block_state;
use pumpkin_util::math::{floor_div, floor_mod, vector2::Vector2, vector3::Vector3};
use crate::{block::ChunkBlockState, generation::section_coords};
use crate::{block::RawBlockState, generation::section_coords};
use super::{
GlobalRandomConfig,
@@ -24,8 +24,8 @@ use super::{
settings::GenerationShapeConfig,
};
pub const LAVA_BLOCK: ChunkBlockState = block_state!("lava");
pub const WATER_BLOCK: ChunkBlockState = block_state!("water");
pub const LAVA_BLOCK: RawBlockState = default_block_state!("lava");
pub const WATER_BLOCK: RawBlockState = default_block_state!("water");
pub const CHUNK_DIM: u8 = 16;
@@ -42,7 +42,7 @@ impl BlockStateSampler {
pos: &impl NoisePos,
sample_options: &ChunkNoiseFunctionSampleOptions,
height_estimator: &mut SurfaceHeightEstimateSampler,
) -> Option<ChunkBlockState> {
) -> Option<RawBlockState> {
match self {
Self::Aquifer(aquifer) => aquifer.apply(router, pos, sample_options, height_estimator),
Self::Ore(ore) => ore.sample(router, pos, sample_options),
@@ -66,7 +66,7 @@ impl ChainedBlockStateSampler {
pos: &impl NoisePos,
sample_options: &ChunkNoiseFunctionSampleOptions,
height_estimator: &mut SurfaceHeightEstimateSampler,
) -> Option<ChunkBlockState> {
) -> Option<RawBlockState> {
self.samplers
.iter_mut()
.map(|sampler| sampler.sample(router, pos, sample_options, height_estimator))
@@ -369,7 +369,7 @@ impl<'a> ChunkNoiseGenerator<'a> {
start_pos: Vector3<i32>,
cell_pos: Vector3<i32>,
height_estimator: &mut SurfaceHeightEstimateSampler,
) -> Option<ChunkBlockState> {
) -> Option<RawBlockState> {
//TODO: Fix this when Blender is added
let pos = UnblendedNoisePos::new(
start_pos.x + cell_pos.x,

View File

@@ -3,9 +3,7 @@ use pumpkin_util::{
random::{RandomDeriver, RandomDeriverImpl, RandomImpl},
};
use crate::{
block::ChunkBlockState, generation::noise_router::chunk_noise_router::ChunkNoiseRouter,
};
use crate::{block::RawBlockState, generation::noise_router::chunk_noise_router::ChunkNoiseRouter};
use super::noise_router::{
chunk_density_function::ChunkNoiseFunctionSampleOptions, density_function::NoisePos,
@@ -25,7 +23,7 @@ impl OreVeinSampler {
router: &mut ChunkNoiseRouter,
pos: &impl NoisePos,
sample_options: &ChunkNoiseFunctionSampleOptions,
) -> Option<ChunkBlockState> {
) -> Option<RawBlockState> {
let vein_toggle = router.vein_toggle(pos, sample_options);
let vein_type: &VeinType = if vein_toggle > 0f64 {
&vein_type::COPPER
@@ -73,29 +71,29 @@ impl OreVeinSampler {
}
pub struct VeinType {
ore: ChunkBlockState,
raw_ore: ChunkBlockState,
stone: ChunkBlockState,
ore: RawBlockState,
raw_ore: RawBlockState,
stone: RawBlockState,
min_y: i32,
max_y: i32,
}
// One of the victims of removing compile time blocks
pub mod vein_type {
use pumpkin_macros::block_state;
use pumpkin_macros::default_block_state;
use super::*;
pub const COPPER: VeinType = VeinType {
ore: block_state!("copper_ore"),
raw_ore: block_state!("raw_copper_block"),
stone: block_state!("granite"),
ore: default_block_state!("copper_ore"),
raw_ore: default_block_state!("raw_copper_block"),
stone: default_block_state!("granite"),
min_y: 0,
max_y: 50,
};
pub const IRON: VeinType = VeinType {
ore: block_state!("deepslate_iron_ore"),
raw_ore: block_state!("raw_iron_block"),
stone: block_state!("tuff"),
ore: default_block_state!("deepslate_iron_ore"),
raw_ore: default_block_state!("raw_iron_block"),
stone: default_block_state!("tuff"),
min_y: -60,
max_y: -8,
};

View File

@@ -1,10 +1,10 @@
use pumpkin_data::chunk::Biome;
use pumpkin_macros::block_state;
use pumpkin_data::{block::BlockState, chunk::Biome};
use pumpkin_macros::default_block_state;
use pumpkin_util::math::{vector2::Vector2, vector3::Vector3};
use crate::{
biome::{BiomeSupplier, MultiNoiseBiomeSupplier, hash_seed},
block::{ChunkBlockState, registry::get_state_by_state_id},
block::RawBlockState,
chunk::CHUNK_AREA,
generation::{biome, positions::chunk_pos},
};
@@ -28,9 +28,7 @@ use super::{
surface::{MaterialRuleContext, estimate_surface_height, terrain::SurfaceTerrainBuilder},
};
const AIR_BLOCK: ChunkBlockState = block_state!("air");
const CAVE_AIR_BLOCK: ChunkBlockState = block_state!("cave_air");
const VOID_AIR_BLOCK: ChunkBlockState = block_state!("void_air");
const AIR_BLOCK: RawBlockState = default_block_state!("air");
pub struct StandardChunkFluidLevelSampler {
top_fluid: FluidLevel,
@@ -95,10 +93,10 @@ pub struct ProtoChunk<'a> {
pub surface_height_estimate_sampler: SurfaceHeightEstimateSampler<'a>,
random_config: &'a GlobalRandomConfig,
settings: &'a GenerationSettings,
default_block: ChunkBlockState,
default_block: RawBlockState,
biome_mixer_seed: i64,
// These are local positions
flat_block_map: Box<[ChunkBlockState]>,
flat_block_map: Box<[RawBlockState]>,
flat_biome_map: Box<[&'static Biome]>,
/// Top block that is not air
flat_height_map: Box<[i32]>,
@@ -163,7 +161,7 @@ impl<'a> ProtoChunk<'a> {
let surface_height_estimate_sampler =
SurfaceHeightEstimateSampler::generate(&base_router.surface_estimator, &surface_config);
let default_block = ChunkBlockState::new(&settings.default_block.name).unwrap();
let default_block = RawBlockState::new(&settings.default_block.name).unwrap();
Self {
chunk_pos,
settings,
@@ -172,7 +170,7 @@ impl<'a> ProtoChunk<'a> {
noise_sampler: sampler,
multi_noise_sampler,
surface_height_estimate_sampler,
flat_block_map: vec![ChunkBlockState::AIR; CHUNK_AREA * height as usize]
flat_block_map: vec![RawBlockState::AIR; CHUNK_AREA * height as usize]
.into_boxed_slice(),
flat_biome_map: vec![
&Biome::PLAINS;
@@ -249,7 +247,7 @@ impl<'a> ProtoChunk<'a> {
}
#[inline]
pub fn get_block_state(&self, local_pos: &Vector3<i32>) -> ChunkBlockState {
pub fn get_block_state(&self, local_pos: &Vector3<i32>) -> RawBlockState {
let local_pos = Vector3::new(
local_pos.x & 15,
local_pos.y - self.bottom_y() as i32,
@@ -259,11 +257,8 @@ impl<'a> ProtoChunk<'a> {
self.flat_block_map[index]
}
pub fn set_block_state(&mut self, local_pos: &Vector3<i32>, block_state: ChunkBlockState) {
if !(block_state.of_block(AIR_BLOCK.block_id)
|| block_state.of_block(CAVE_AIR_BLOCK.block_id)
|| block_state.of_block(VOID_AIR_BLOCK.block_id))
{
pub fn set_block_state(&mut self, local_pos: &Vector3<i32>, block_state: BlockState) {
if !block_state.air {
self.maybe_update_height_map(local_pos);
}
@@ -273,7 +268,9 @@ impl<'a> ProtoChunk<'a> {
local_pos.z & 15,
);
let index = self.local_pos_to_block_index(&local_pos);
self.flat_block_map[index] = block_state;
self.flat_block_map[index] = RawBlockState {
state_id: block_state.id,
};
}
#[inline]
@@ -413,7 +410,7 @@ impl<'a> ProtoChunk<'a> {
.unwrap_or(self.default_block);
self.set_block_state(
&Vector3::new(block_x, block_y, block_z),
block_state,
block_state.to_state(),
);
}
}
@@ -486,8 +483,7 @@ impl<'a> ProtoChunk<'a> {
let mut fluid_height = i32::MIN;
for y in (min_y as i32..top_block).rev() {
let pos = Vector3::new(x, y, z);
let state = self.get_block_state(&pos);
let state = get_state_by_state_id(state.state_id).unwrap();
let state = self.get_block_state(&pos).to_state();
if state.air {
stone_depth_above = 0;
fluid_height = i32::MIN;
@@ -509,13 +505,14 @@ impl<'a> ProtoChunk<'a> {
break;
}
let state =
self.get_block_state(&Vector3::new(local_x, search_y, local_z));
let state = self
.get_block_state(&Vector3::new(local_x, search_y, local_z))
.to_block();
// TODO: Is there a better way to check that its not a fluid?
if !(!state.of_block(AIR_BLOCK.block_id)
&& !state.of_block(WATER_BLOCK.block_id)
&& !state.of_block(LAVA_BLOCK.block_id))
if !(state != AIR_BLOCK.to_block()
&& state != WATER_BLOCK.to_block()
&& state != LAVA_BLOCK.to_block())
{
min = search_y + 1;
break;
@@ -534,7 +531,7 @@ impl<'a> ProtoChunk<'a> {
let new_state = self.settings.surface_rule.try_apply(self, &mut context);
if let Some(state) = new_state {
self.set_block_state(&pos, state);
self.set_block_state(&pos, state.to_state());
}
}
}

View File

@@ -5,7 +5,7 @@ use serde::Deserialize;
use super::{MaterialCondition, MaterialRuleContext};
use crate::{
ProtoChunk,
block::{BlockStateCodec, ChunkBlockState},
block::{BlockStateCodec, RawBlockState},
};
#[derive(Deserialize)]
@@ -26,7 +26,7 @@ impl MaterialRule {
&self,
chunk: &mut ProtoChunk,
context: &mut MaterialRuleContext,
) -> Option<ChunkBlockState> {
) -> Option<RawBlockState> {
match self {
MaterialRule::Badlands(badlands) => badlands.try_apply(context),
MaterialRule::Block(block) => block.try_apply(),
@@ -40,7 +40,7 @@ impl MaterialRule {
pub struct BadLandsMaterialRule;
impl BadLandsMaterialRule {
pub fn try_apply(&self, context: &mut MaterialRuleContext) -> Option<ChunkBlockState> {
pub fn try_apply(&self, context: &mut MaterialRuleContext) -> Option<RawBlockState> {
Some(
context
.terrain_builder
@@ -53,14 +53,14 @@ impl BadLandsMaterialRule {
pub struct BlockMaterialRule {
result_state: BlockStateCodec,
#[serde(skip)]
block_state: OnceLock<Option<ChunkBlockState>>,
block_state: OnceLock<Option<RawBlockState>>,
}
impl BlockMaterialRule {
pub fn try_apply(&self) -> Option<ChunkBlockState> {
pub fn try_apply(&self) -> Option<RawBlockState> {
*self
.block_state
.get_or_init(|| ChunkBlockState::new(&self.result_state.name))
.get_or_init(|| RawBlockState::new(&self.result_state.name))
}
}
@@ -74,7 +74,7 @@ impl SequenceMaterialRule {
&self,
chunk: &mut ProtoChunk,
context: &mut MaterialRuleContext,
) -> Option<ChunkBlockState> {
) -> Option<RawBlockState> {
for seq in &self.sequence {
if let Some(state) = seq.try_apply(chunk, context) {
return Some(state);
@@ -95,7 +95,7 @@ impl ConditionMaterialRule {
&self,
chunk: &mut ProtoChunk,
context: &mut MaterialRuleContext,
) -> Option<ChunkBlockState> {
) -> Option<RawBlockState> {
if self.if_true.test(chunk, context) {
return self.then_run.try_apply(chunk, context);
}

View File

@@ -1,5 +1,5 @@
use pumpkin_data::chunk::Biome;
use pumpkin_macros::block_state;
use pumpkin_macros::default_block_state;
use pumpkin_util::{
math::vector3::Vector3,
random::{RandomDeriver, RandomDeriverImpl, RandomGenerator, RandomImpl},
@@ -7,7 +7,7 @@ use pumpkin_util::{
use crate::{
ProtoChunk,
block::ChunkBlockState,
block::RawBlockState,
generation::{
chunk_noise::WATER_BLOCK, height_limit::HeightLimitView,
noise::perlin::DoublePerlinNoiseSampler,
@@ -17,7 +17,7 @@ use crate::{
pub struct SurfaceTerrainBuilder {
// Badlands stuff
terracotta_bands: Box<[ChunkBlockState]>,
terracotta_bands: Box<[RawBlockState]>,
terracotta_bands_offset_noise: DoublePerlinNoiseSampler,
badlands_pillar_noise: DoublePerlinNoiseSampler,
badlands_surface_noise: DoublePerlinNoiseSampler,
@@ -50,15 +50,15 @@ impl SurfaceTerrainBuilder {
}
}
const ORANGE_TERRACOTTA: ChunkBlockState = block_state!("orange_terracotta");
const YELLOW_TERRACOTTA: ChunkBlockState = block_state!("yellow_terracotta");
const BROWN_TERRACOTTA: ChunkBlockState = block_state!("brown_terracotta");
const RED_TERRACOTTA: ChunkBlockState = block_state!("red_terracotta");
const WHITE_TERRACOTTA: ChunkBlockState = block_state!("white_terracotta");
const LIGHT_GRAY_TERRACOTTA: ChunkBlockState = block_state!("light_gray_terracotta");
const TERRACOTTA: ChunkBlockState = block_state!("terracotta");
const ORANGE_TERRACOTTA: RawBlockState = default_block_state!("orange_terracotta");
const YELLOW_TERRACOTTA: RawBlockState = default_block_state!("yellow_terracotta");
const BROWN_TERRACOTTA: RawBlockState = default_block_state!("brown_terracotta");
const RED_TERRACOTTA: RawBlockState = default_block_state!("red_terracotta");
const WHITE_TERRACOTTA: RawBlockState = default_block_state!("white_terracotta");
const LIGHT_GRAY_TERRACOTTA: RawBlockState = default_block_state!("light_gray_terracotta");
const TERRACOTTA: RawBlockState = default_block_state!("terracotta");
fn create_terracotta_bands(mut random: RandomGenerator) -> Box<[ChunkBlockState]> {
fn create_terracotta_bands(mut random: RandomGenerator) -> Box<[RawBlockState]> {
let mut block_states = [Self::TERRACOTTA; 192];
let mut i = 0;
@@ -99,9 +99,9 @@ impl SurfaceTerrainBuilder {
fn add_terracotta_bands(
random: &mut RandomGenerator,
terracotta_bands: &mut [ChunkBlockState],
terracotta_bands: &mut [RawBlockState],
min_band_size: i32,
state: ChunkBlockState,
state: RawBlockState,
) {
let band_count = random.next_inbetween_i32(6, 15);
@@ -125,7 +125,7 @@ impl SurfaceTerrainBuilder {
global_x: i32,
global_z: i32,
surface_y: i32,
default_state: ChunkBlockState,
default_state: RawBlockState,
) {
let surface_noise =
(self
@@ -155,31 +155,31 @@ impl SurfaceTerrainBuilder {
if surface_y <= elevation_y {
for y in (chunk.bottom_y() as i32..=elevation_y).rev() {
let pos = Vector3::new(global_x, y, global_z);
let block_state = chunk.get_block_state(&pos);
if block_state.of_block(default_state.block_id) {
let block_state = chunk.get_block_state(&pos).to_block();
if block_state == default_state.to_block() {
break;
}
if block_state.of_block(WATER_BLOCK.block_id) {
if block_state == WATER_BLOCK.to_block() {
return;
}
}
for y in (chunk.bottom_y() as i32..=elevation_y).rev() {
let pos = Vector3::new(global_x, y, global_z);
let block_state = chunk.get_block_state(&pos);
if !block_state.is_air() {
let block_state = chunk.get_block_state(&pos).to_state();
if !block_state.air {
break;
}
chunk.set_block_state(&pos, default_state);
chunk.set_block_state(&pos, default_state.to_state());
}
}
}
}
const SNOW_BLOCK: ChunkBlockState = block_state!("snow_block");
const PACKED_ICE: ChunkBlockState = block_state!("packed_ice");
const SNOW_BLOCK: RawBlockState = default_block_state!("snow_block");
const PACKED_ICE: RawBlockState = default_block_state!("packed_ice");
#[expect(clippy::too_many_arguments)]
pub fn place_iceberg(
@@ -239,25 +239,25 @@ impl SurfaceTerrainBuilder {
for y in (estimated_surface_y..=top_y).rev() {
let pos = Vector3::new(x, y, z);
let block_state = chunk.get_block_state(&pos);
if (block_state.is_air() && y < top_block && rand.next_f64() > 0.01)
|| (block_state.of_block(WATER_BLOCK.block_id)
if (block_state.to_state().air && y < top_block && rand.next_f64() > 0.01)
|| (block_state.to_block() == WATER_BLOCK.to_block()
&& y > bottom_block
&& y < sea_level
&& bottom_block != 0
&& rand.next_f64() > 0.15)
{
if snow_blocks <= snow_block_count && y > snow_bottom {
chunk.set_block_state(&pos, Self::SNOW_BLOCK);
chunk.set_block_state(&pos, Self::SNOW_BLOCK.to_state());
snow_blocks += 1;
} else {
chunk.set_block_state(&pos, Self::PACKED_ICE);
chunk.set_block_state(&pos, Self::PACKED_ICE.to_state());
}
}
}
}
}
pub fn get_terracotta_block(&self, pos: &Vector3<i32>) -> ChunkBlockState {
pub fn get_terracotta_block(&self, pos: &Vector3<i32>) -> RawBlockState {
let offset = (self
.terracotta_bands_offset_noise
.sample(pos.x as f64, 0.0, pos.z as f64)

View File

@@ -1,7 +1,6 @@
use crate::server::Server;
use async_trait::async_trait;
use pumpkin_data::damage::DamageType;
use pumpkin_macros::block_state;
use pumpkin_data::{block::Block, damage::DamageType};
use pumpkin_protocol::{
client::play::{MetaDataType, Metadata},
codec::var_int::VarInt,
@@ -42,7 +41,7 @@ impl TNTEntity {
Metadata::new(
9,
MetaDataType::BlockState,
VarInt(i32::from(block_state!("tnt").state_id)),
VarInt(i32::from(Block::TNT.default_state_id)),
),
])
.await;