This commit is contained in:
griffi-gh 2023-01-28 23:41:34 +01:00
parent 5a0e73e2b5
commit 427feecb55

View file

@ -7,32 +7,43 @@ use super::{
pub fn generate_world(chunk_position: IVec3, seed: u64) -> BlockData { pub fn generate_world(chunk_position: IVec3, seed: u64) -> BlockData {
let offset = chunk_position * CHUNK_SIZE as i32; let offset = chunk_position * CHUNK_SIZE as i32;
let mut noise = FastNoise::seeded(seed);
noise.set_fractal_type(FractalType::FBM); let mut cave_noise = FastNoise::seeded(seed);
noise.set_frequency(0.1); cave_noise.set_fractal_type(FractalType::FBM);
cave_noise.set_frequency(0.1);
let mut dirt_noise = FastNoise::seeded(seed.rotate_left(1));
dirt_noise.set_fractal_type(FractalType::FBM);
dirt_noise.set_frequency(0.1);
let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]); let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]);
// blocks[0][0][0] = Block::Stone; if chunk_position.y > 0 {
// blocks[0][CHUNK_SIZE - 1][0] = Block::Stone; if chunk_position.y == 1 {
// blocks[CHUNK_SIZE - 1][0][0] = Block::Stone; for x in 0..CHUNK_SIZE {
// blocks[CHUNK_SIZE - 1][CHUNK_SIZE - 1][0] = Block::Stone; for z in 0..CHUNK_SIZE {
// blocks[0][0][CHUNK_SIZE - 1] = Block::Stone; blocks[x][0][z] = Block::Dirt;
// blocks[0][CHUNK_SIZE - 1][CHUNK_SIZE - 1] = Block::Stone; blocks[x][1][z] = Block::Grass;
// blocks[CHUNK_SIZE - 1][0][CHUNK_SIZE - 1] = Block::Stone; }
// blocks[CHUNK_SIZE - 1][CHUNK_SIZE - 1][CHUNK_SIZE - 1] = Block::Stone; }
}
} else {
for x in 0..CHUNK_SIZE { for x in 0..CHUNK_SIZE {
for y in 0..CHUNK_SIZE { for y in 0..CHUNK_SIZE {
for z in 0..CHUNK_SIZE { for z in 0..CHUNK_SIZE {
let position = ivec3(x as i32, y as i32, z as i32) + offset; let position = ivec3(x as i32, y as i32, z as i32) + offset;
let noise = noise.get_noise3d(position.x as f32, position.y as f32, position.z as f32); let v_cave_noise = cave_noise.get_noise3d(position.x as f32, position.y as f32, position.z as f32) * (-position.y as f32 - 10.0).clamp(0., 1.);
if (0.7..0.8).contains(&noise) { let v_dirt_noise = dirt_noise.get_noise3d(position.x as f32, position.y as f32, position.z as f32) * (-position.y as f32).clamp(0., 1.);
if v_cave_noise > 0.5 {
blocks[x][y][z] = Block::Stone; blocks[x][y][z] = Block::Stone;
} else if v_dirt_noise > 0.5 {
blocks[x][y][z] = Block::Dirt;
}
} }
} }
} }
} }
blocks blocks
} }