Skip to content

Commit 193387c

Browse files
committed
superbasic generation
1 parent 275d63d commit 193387c

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

src/net/packet.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
include!(concat!(env!("OUT_DIR"), "/packets.rs"));
1+
pub use packets::*;
2+
3+
#[allow(unused)]
4+
mod packets {
5+
include!(concat!(env!("OUT_DIR"), "/packets.rs"));
6+
}
27

38
use tokio::io::AsyncReadExt;
49
use std::collections::HashMap;

src/types/blocks.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
include!(concat!(env!("OUT_DIR"), "/blocks.rs"));
1+
pub use blocks::*;
2+
3+
#[allow(unused)]
4+
mod blocks {
5+
include!(concat!(env!("OUT_DIR"), "/blocks.rs"));
6+
}

src/world/chunks.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ pub struct Chunk {
7979
}
8080

8181
impl Chunk {
82-
pub fn set_block(&mut self, x: u8, y: u8, z: u8, block_id: u16) {
83-
let section_idx = (y as i32) / 16;
82+
pub fn set_block(&mut self, x: u8, y: i32, z: u8, block_id: u16) {
83+
let section_idx = y.div_euclid(16) + 4;
8484

8585
if let Some(section) = self.sections.get_mut(section_idx as usize) {
86-
section.set_block(x, y % 16, z, block_id);
86+
section.set_block(x, (y & 15) as u8, z, block_id);
8787
}
8888
}
8989
}

src/world/worldgen/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,23 @@ pub fn generate(x: i32, z: i32) -> Chunk {
4949
}
5050

5151
fn place_column(chunk: &mut Chunk, x: u8, z: u8, height: i32) {
52-
chunk.set_block(x, 0, z, crate::types::blocks::BEDROCK);
52+
chunk.set_block(x, -64, z, crate::types::blocks::BEDROCK);
53+
54+
for y in -63..height {
55+
let block_id = match y {
56+
y if y >= SEA_LEVEL && y == height => crate::types::blocks::GRASS_BLOCK,
57+
y if y < SEA_LEVEL && y == height => crate::types::blocks::SAND,
58+
y if y < SEA_LEVEL && y > height - 4 => crate::types::blocks::SAND,
59+
y if y > height - 4 => crate::types::blocks::DIRT,
60+
_ => crate::types::blocks::STONE,
61+
};
62+
63+
chunk.set_block(x, y, z, block_id);
64+
}
65+
66+
if height < SEA_LEVEL {
67+
for y in height..SEA_LEVEL {
68+
chunk.set_block(x, y, z, crate::types::blocks::WATER);
69+
}
70+
}
5371
}

0 commit comments

Comments
 (0)