Skip to content

Commit 6a82e27

Browse files
committed
make it compile
1 parent ec5fec4 commit 6a82e27

File tree

6 files changed

+352
-240
lines changed

6 files changed

+352
-240
lines changed

pumpkin-world/src/chunk/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use serde::{Deserialize, Serialize};
44
use std::iter::repeat_with;
55
use thiserror::Error;
66

7-
use crate::{WORLD_HEIGHT, coordinates::ChunkRelativeBlockCoordinates};
7+
use crate::coordinates::ChunkRelativeBlockCoordinates;
88

99
pub mod format;
1010
pub mod io;
1111

12+
// TODO
13+
const WORLD_HEIGHT: usize = 384;
1214
pub const CHUNK_AREA: usize = 16 * 16;
1315
pub const SUBCHUNK_VOLUME: usize = CHUNK_AREA * 16;
1416
pub const SUBCHUNKS_COUNT: usize = WORLD_HEIGHT / 16;

pumpkin-world/src/generation/chunk_noise.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ use super::{
2727
pub const LAVA_BLOCK: ChunkBlockState = block_state!("lava");
2828
pub const WATER_BLOCK: ChunkBlockState = block_state!("water");
2929

30+
pub const CHUNK_DIM: u8 = 16;
31+
3032
pub enum BlockStateSampler {
3133
Aquifer(AquiferSampler),
3234
Ore(OreVeinSampler),

pumpkin-world/src/generation/generic_generator.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use noise::{NoiseFn, Perlin};
22
use pumpkin_util::math::vector2::Vector2;
33

44
use crate::{
5-
chunk::{ChunkData, Subchunks},
5+
chunk::{ChunkBlocks, ChunkData},
66
coordinates::{ChunkRelativeBlockCoordinates, ChunkRelativeXZBlockCoordinates},
77
};
88

@@ -33,7 +33,7 @@ impl<B: BiomeGenerator + GeneratorInit, T: PerlinTerrainGenerator + GeneratorIni
3333

3434
impl<B: BiomeGenerator, T: PerlinTerrainGenerator> WorldGenerator for GenericGenerator<B, T> {
3535
fn generate_chunk(&self, at: Vector2<i32>) -> ChunkData {
36-
let mut subchunks = Subchunks::Single(0);
36+
let mut blocks = ChunkBlocks::Homogeneous(0);
3737
self.terrain_generator.prepare_chunk(&at, &self.perlin);
3838
let noise_value = self.perlin.get([at.x as f64 / 16.0, at.z as f64 / 16.0]);
3939

@@ -64,7 +64,7 @@ impl<B: BiomeGenerator, T: PerlinTerrainGenerator> WorldGenerator for GenericGen
6464
self.terrain_generator.generate_block(
6565
coordinates,
6666
coordinates.with_chunk_coordinates(at),
67-
&mut subchunks,
67+
&mut blocks,
6868
chunk_height,
6969
biome,
7070
);
@@ -73,9 +73,11 @@ impl<B: BiomeGenerator, T: PerlinTerrainGenerator> WorldGenerator for GenericGen
7373
}
7474

7575
ChunkData {
76-
subchunks,
76+
blocks,
7777
heightmap: Default::default(),
7878
position: at,
79+
// This chunk was just created! We want to say its been changed
80+
dirty: true,
7981
}
8082
}
8183
}

pumpkin-world/src/generation/implementation/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod superflat;
33
use pumpkin_util::math::{vector2::Vector2, vector3::Vector3};
44

55
use crate::{
6-
chunk::{ChunkData, Subchunks},
6+
chunk::{ChunkBlocks, ChunkData},
77
coordinates::ChunkRelativeBlockCoordinates,
88
generation::{
99
GlobalRandomConfig, Seed, WorldGenerator, generator::GeneratorInit,
@@ -35,7 +35,7 @@ impl GeneratorInit for VanillaGenerator {
3535

3636
impl WorldGenerator for VanillaGenerator {
3737
fn generate_chunk(&self, at: Vector2<i32>) -> ChunkData {
38-
let mut subchunks = Subchunks::Single(0);
38+
let mut blocks = ChunkBlocks::Homogeneous(0);
3939
// TODO: This is bad, but it works
4040
let generation_settings = GENERATION_SETTINGS
4141
.get(&GeneratorSetting::Overworld)
@@ -67,15 +67,16 @@ impl WorldGenerator for VanillaGenerator {
6767
continue;
6868
}
6969

70-
subchunks.set_block(coordinates, block.state_id);
70+
blocks.set_block(coordinates, block.state_id);
7171
}
7272
}
7373
}
7474

7575
ChunkData {
76-
subchunks,
76+
blocks,
7777
heightmap: Default::default(),
7878
position: at,
79+
dirty: true,
7980
}
8081
}
8182
}

pumpkin-world/src/generation/proto_chunk.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use pumpkin_util::math::{vector2::Vector2, vector3::Vector3};
44
use crate::{
55
biome::{BiomeSupplier, MultiNoiseBiomeSupplier},
66
block::{ChunkBlockState, registry::get_state_by_state_id},
7-
chunk::{CHUNK_AREA, CHUNK_WIDTH},
7+
chunk::CHUNK_AREA,
88
generation::{biome, positions::chunk_pos},
99
};
1010

1111
use super::{
1212
GlobalRandomConfig,
1313
aquifer_sampler::{FluidLevel, FluidLevelSampler, FluidLevelSamplerImpl},
1414
biome_coords,
15-
chunk_noise::{ChunkNoiseGenerator, LAVA_BLOCK, WATER_BLOCK},
15+
chunk_noise::{CHUNK_DIM, ChunkNoiseGenerator, LAVA_BLOCK, WATER_BLOCK},
1616
height_limit::HeightLimitView,
1717
noise_router::{
1818
multi_noise_sampler::{MultiNoiseSampler, MultiNoiseSamplerBuilderOptions},
@@ -106,8 +106,7 @@ impl<'a> ProtoChunk<'a> {
106106
) -> Self {
107107
let generation_shape = &settings.noise;
108108

109-
let horizontal_cell_count =
110-
CHUNK_WIDTH / generation_shape.horizontal_cell_block_count() as usize;
109+
let horizontal_cell_count = CHUNK_DIM / generation_shape.horizontal_cell_block_count();
111110

112111
// TODO: Customize these
113112
let sampler = FluidLevelSampler::Chunk(StandardChunkFluidLevelSampler::new(
@@ -122,7 +121,7 @@ impl<'a> ProtoChunk<'a> {
122121
let sampler = ChunkNoiseGenerator::new(
123122
base_router,
124123
random_config,
125-
horizontal_cell_count,
124+
horizontal_cell_count as usize,
126125
start_x,
127126
start_z,
128127
generation_shape,
@@ -136,16 +135,19 @@ impl<'a> ProtoChunk<'a> {
136135
biome_coords::from_block(start_z),
137136
);
138137
let horizontal_biome_end = biome_coords::from_block(
139-
horizontal_cell_count * generation_shape.horizontal_cell_block_count() as usize,
138+
horizontal_cell_count * generation_shape.horizontal_cell_block_count(),
139+
);
140+
let multi_noise_config = MultiNoiseSamplerBuilderOptions::new(
141+
biome_pos.x,
142+
biome_pos.z,
143+
horizontal_biome_end as usize,
140144
);
141-
let multi_noise_config =
142-
MultiNoiseSamplerBuilderOptions::new(biome_pos.x, biome_pos.z, horizontal_biome_end);
143145
let multi_noise_sampler = MultiNoiseSampler::generate(base_router, &multi_noise_config);
144146

145147
let surface_config = SurfaceHeightSamplerBuilderOptions::new(
146148
biome_pos.x,
147149
biome_pos.z,
148-
horizontal_biome_end,
150+
horizontal_biome_end as usize,
149151
generation_shape.min_y as i32,
150152
generation_shape.max_y() as i32,
151153
generation_shape.vertical_cell_block_count() as usize,
@@ -166,8 +168,8 @@ impl<'a> ProtoChunk<'a> {
166168
.into_boxed_slice(),
167169
flat_biome_map: vec![
168170
Biome::Plains;
169-
biome_coords::from_block(CHUNK_WIDTH)
170-
* biome_coords::from_block(CHUNK_WIDTH)
171+
biome_coords::from_block(CHUNK_DIM as usize)
172+
* biome_coords::from_block(CHUNK_DIM as usize)
171173
* biome_coords::from_block(height as usize)
172174
]
173175
.into_boxed_slice(),
@@ -182,8 +184,8 @@ impl<'a> ProtoChunk<'a> {
182184
assert!(local_pos.y < self.noise_sampler.height() as i32 && local_pos.y >= 0);
183185
assert!(local_pos.z >= 0 && local_pos.z <= 15);
184186
}
185-
self.noise_sampler.height() as usize * CHUNK_WIDTH * local_pos.x as usize
186-
+ CHUNK_WIDTH * local_pos.y as usize
187+
self.noise_sampler.height() as usize * CHUNK_DIM as usize * local_pos.x as usize
188+
+ CHUNK_DIM as usize * local_pos.y as usize
187189
+ local_pos.z as usize
188190
}
189191

@@ -200,9 +202,9 @@ impl<'a> ProtoChunk<'a> {
200202
}
201203

202204
biome_coords::from_block(self.noise_sampler.height() as usize)
203-
* biome_coords::from_block(CHUNK_WIDTH)
205+
* biome_coords::from_block(CHUNK_DIM as usize)
204206
* local_biome_pos.x as usize
205-
+ biome_coords::from_block(CHUNK_WIDTH) * local_biome_pos.y as usize
207+
+ biome_coords::from_block(CHUNK_DIM as usize) * local_biome_pos.y as usize
206208
+ local_biome_pos.z as usize
207209
}
208210

@@ -266,7 +268,7 @@ impl<'a> ProtoChunk<'a> {
266268
let block_y = section_coords::section_to_block(i);
267269
let start_y = biome_coords::from_block(block_y);
268270

269-
let biomes_per_section = biome_coords::from_block(CHUNK_WIDTH) as i32;
271+
let biomes_per_section = biome_coords::from_block(CHUNK_DIM) as i32;
270272
for x in 0..biomes_per_section {
271273
for y in 0..biomes_per_section {
272274
for z in 0..biomes_per_section {
@@ -300,7 +302,7 @@ impl<'a> ProtoChunk<'a> {
300302
let horizontal_cell_block_count = self.noise_sampler.horizontal_cell_block_count();
301303
let vertical_cell_block_count = self.noise_sampler.vertical_cell_block_count();
302304

303-
let horizontal_cells = (CHUNK_WIDTH / horizontal_cell_block_count as usize) as u8;
305+
let horizontal_cells = (CHUNK_DIM / horizontal_cell_block_count) as u8;
304306

305307
let min_y = self.noise_sampler.min_y();
306308
let minimum_cell_y = min_y / vertical_cell_block_count as i8;

0 commit comments

Comments
 (0)