Skip to content

Commit

Permalink
Improve FlatWorld generator (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
michidk authored May 3, 2021
1 parent 144cf14 commit b63fd95
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions feather/common/src/world_source/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,33 @@ impl Default for FlatWorldSource {

impl FlatWorldSource {
pub fn new() -> Self {
let archetype = Self::generate();

Self {
archetype,
loaded: Vec::new(),
}
}

fn generate() -> Chunk {
let mut archetype = Chunk::new(ChunkPosition::new(0, 0));
for y in 0..64 {
for z in 0..CHUNK_WIDTH {
for x in 0..CHUNK_WIDTH {
let block = if y == 63 {
BlockId::grass_block()
} else {
BlockId::stone()
};
archetype.set_block_at(x, y, z, block);
archetype.set_block_at(x, y, z, Self::select_block(y));
}
}
}
archetype
}

Self {
archetype,
loaded: Vec::new(),
fn select_block(height: usize) -> BlockId {
match height {
0 => BlockId::bedrock(),
1..=57 => BlockId::stone(),
58..=62 => BlockId::dirt(),
63 => BlockId::grass_block(),
_ => BlockId::air(),
}
}
}
Expand Down

0 comments on commit b63fd95

Please sign in to comment.