From 43c724dec77898210fcb8c506af1b9a8f44d6f75 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Wed, 28 Aug 2024 11:27:06 +0200 Subject: [PATCH] Added Superflat implementation. --- .../src/world_gen/implementations/mod.rs | 1 + .../world_gen/implementations/superflat.rs | 48 +++++++++++++++++++ pumpkin-world/src/world_gen/mod.rs | 9 +++- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 pumpkin-world/src/world_gen/implementations/mod.rs create mode 100644 pumpkin-world/src/world_gen/implementations/superflat.rs diff --git a/pumpkin-world/src/world_gen/implementations/mod.rs b/pumpkin-world/src/world_gen/implementations/mod.rs new file mode 100644 index 000000000..716121f9d --- /dev/null +++ b/pumpkin-world/src/world_gen/implementations/mod.rs @@ -0,0 +1 @@ +pub mod superflat; diff --git a/pumpkin-world/src/world_gen/implementations/superflat.rs b/pumpkin-world/src/world_gen/implementations/superflat.rs new file mode 100644 index 000000000..edbbcf4ba --- /dev/null +++ b/pumpkin-world/src/world_gen/implementations/superflat.rs @@ -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; + +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, + } + } +} diff --git a/pumpkin-world/src/world_gen/mod.rs b/pumpkin-world/src/world_gen/mod.rs index 43a5ca1a6..9ab676e24 100644 --- a/pumpkin-world/src/world_gen/mod.rs +++ b/pumpkin-world/src/world_gen/mod.rs @@ -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 { - todo!() +pub fn get_world_gen(seed: Seed) -> Box { + // TODO decide which WorldGenerator to pick based on config. + Box::new(SuperflatGenerator::new(seed)) }