Added Superflat implementation.

This commit is contained in:
DaniD3v 2024-08-28 11:27:06 +02:00
parent 9149e82508
commit 43c724dec7
3 changed files with 56 additions and 2 deletions

View File

@ -0,0 +1 @@
pub mod superflat;

View File

@ -0,0 +1,48 @@
use crate::{
biome::Biome,
block::BlockId,
coordinates::{BlockCoordinates, XZBlockCoordinates},
world_gen::{
generator::{BiomeGenerator, GeneratorInit, TerrainGenerator},
generic_generator::GenericGenerator,
Seed,
},
};
#[allow(dead_code)]
pub type SuperflatGenerator = GenericGenerator<SuperflatBiomeGenerator, SuperflatTerrainGenerator>;
pub(crate) struct SuperflatBiomeGenerator {}
impl GeneratorInit for SuperflatBiomeGenerator {
fn new(_: Seed) -> Self {
Self {}
}
}
impl BiomeGenerator for SuperflatBiomeGenerator {
// TODO make generic over Biome and allow changing the Biome in the config.
fn generate_biome(&self, _: XZBlockCoordinates) -> Biome {
Biome::Plains
}
}
pub(crate) struct SuperflatTerrainGenerator {}
impl GeneratorInit for SuperflatTerrainGenerator {
fn new(_: Seed) -> Self {
Self {}
}
}
impl TerrainGenerator for SuperflatTerrainGenerator {
// TODO allow specifying which blocks should be at which height in the config.
fn generate_block(&self, at: BlockCoordinates, _: Biome) -> BlockId {
match *at.y {
-64 => BlockId::from_id(79), // Bedrock
-63..=-62 => BlockId::from_id(10), // Dirt
-61 => BlockId::from_id(9), // Grass
_ => BlockId::AIR,
}
}
}

View File

@ -1,11 +1,16 @@
mod generator;
mod generic_generator;
mod implementations;
mod seed;
pub use generator::WorldGenerator;
pub use seed::Seed;
use generator::GeneratorInit;
use implementations::superflat::SuperflatGenerator;
#[allow(dead_code)]
pub fn get_world_gen(_: Seed) -> Box<dyn WorldGenerator> {
todo!()
pub fn get_world_gen(seed: Seed) -> Box<dyn WorldGenerator> {
// TODO decide which WorldGenerator to pick based on config.
Box::new(SuperflatGenerator::new(seed))
}