2023-01-26 18:04:01 -06:00
|
|
|
use glam::{IVec3, ivec3};
|
|
|
|
use bracket_noise::prelude::*;
|
2023-01-22 17:16:58 -06:00
|
|
|
use super::{
|
|
|
|
chunk::{BlockData, CHUNK_SIZE},
|
|
|
|
block::Block
|
|
|
|
};
|
|
|
|
|
2023-01-26 18:04:01 -06:00
|
|
|
pub fn generate_world(chunk_position: IVec3, seed: u64) -> BlockData {
|
|
|
|
let offset = chunk_position * CHUNK_SIZE as i32;
|
|
|
|
let mut noise = FastNoise::seeded(seed);
|
|
|
|
noise.set_fractal_type(FractalType::FBM);
|
|
|
|
noise.set_frequency(0.1);
|
|
|
|
|
2023-01-22 17:16:58 -06:00
|
|
|
let mut blocks = Box::new([[[Block::Air; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]);
|
2023-01-26 18:04:01 -06:00
|
|
|
|
|
|
|
for x in 0..CHUNK_SIZE {
|
|
|
|
for y in 0..CHUNK_SIZE {
|
2023-01-25 20:39:39 -06:00
|
|
|
for z in 0..CHUNK_SIZE {
|
2023-01-26 18:04:01 -06:00
|
|
|
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);
|
2023-01-26 19:14:10 -06:00
|
|
|
if (0.7..0.8).contains(&noise) {
|
2023-01-26 18:04:01 -06:00
|
|
|
blocks[x][y][z] = Block::Stone;
|
2023-01-25 20:58:05 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-25 20:39:39 -06:00
|
|
|
}
|
2023-01-26 18:04:01 -06:00
|
|
|
|
2023-01-22 17:16:58 -06:00
|
|
|
blocks
|
|
|
|
}
|