-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also add Perlin noise
- Loading branch information
Showing
11 changed files
with
169 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...orld/src/world_gen/implementations/mod.rs → ...world/src/world_gen/implementation/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod overworld; | ||
pub mod superflat; |
1 change: 1 addition & 0 deletions
1
pumpkin-world/src/world_gen/implementation/overworld/biome/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod plains; |
60 changes: 60 additions & 0 deletions
60
pumpkin-world/src/world_gen/implementation/overworld/biome/plains.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use noise::Perlin; | ||
use pumpkin_core::math::vector2::Vector2; | ||
|
||
use crate::{ | ||
biome::Biome, | ||
block::BlockId, | ||
coordinates::{BlockCoordinates, XZBlockCoordinates}, | ||
world_gen::{ | ||
generator::{BiomeGenerator, GeneratorInit, PerlinTerrainGenerator}, | ||
generic_generator::GenericGenerator, | ||
Seed, | ||
}, | ||
}; | ||
|
||
pub type PlainsGenerator = GenericGenerator<PlainsBiomeGenerator, PlainsTerrainGenerator>; | ||
|
||
pub(crate) struct PlainsBiomeGenerator {} | ||
|
||
impl GeneratorInit for PlainsBiomeGenerator { | ||
fn new(_: Seed) -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl BiomeGenerator for PlainsBiomeGenerator { | ||
// TODO make generic over Biome and allow changing the Biome in the config. | ||
fn generate_biome(&self, _: XZBlockCoordinates) -> Biome { | ||
Biome::Plains | ||
} | ||
} | ||
|
||
pub(crate) struct PlainsTerrainGenerator {} | ||
|
||
impl GeneratorInit for PlainsTerrainGenerator { | ||
fn new(_: Seed) -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl PerlinTerrainGenerator for PlainsTerrainGenerator { | ||
fn prepare_chunk(&self, _at: &Vector2<i32>, _perlin: &Perlin) {} | ||
// TODO allow specifying which blocks should be at which height in the config. | ||
fn generate_block(&self, at: BlockCoordinates, chunk_height: i16, _: Biome) -> BlockId { | ||
let begin_stone_height = chunk_height - 5; | ||
let begin_dirt_height = chunk_height - 1; | ||
|
||
let y = *at.y; | ||
if y == -64 { | ||
BlockId::from_id(79) // BEDROCK | ||
} else if y >= -63 && y <= begin_stone_height { | ||
return BlockId::from_id(1); // STONE | ||
} else if y >= begin_stone_height && y < begin_dirt_height { | ||
return BlockId::from_id(10); // DIRT; | ||
} else if y == chunk_height - 1 { | ||
return BlockId::from_id(9); // GRASS BLOCK | ||
} else { | ||
BlockId::AIR | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod biome; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
mod generator; | ||
mod generic_generator; | ||
mod implementations; | ||
mod implementation; | ||
mod seed; | ||
|
||
pub use generator::WorldGenerator; | ||
use implementation::overworld::biome::plains::PlainsGenerator; | ||
pub use seed::Seed; | ||
|
||
use generator::GeneratorInit; | ||
use implementations::superflat::SuperflatGenerator; | ||
|
||
pub fn get_world_gen(seed: Seed) -> Box<dyn WorldGenerator> { | ||
// TODO decide which WorldGenerator to pick based on config. | ||
Box::new(SuperflatGenerator::new(seed)) | ||
Box::new(PlainsGenerator::new(seed)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters