WIP generating chunks at player position

This commit is contained in:
Piotrek
2021-05-12 16:17:38 +02:00
parent 4acf8ea816
commit ab9f4c83d0
10 changed files with 186 additions and 147 deletions
+12 -1
View File
@@ -28,6 +28,7 @@ impl WorldChunk {
}
}
#[allow(unused)]
pub fn from_bytes(bytes: Vec<u8>) -> Self {
let mut instance = Self::new();
@@ -59,6 +60,7 @@ impl WorldChunk {
instance
}
#[allow(unused)]
pub fn to_bytes(&self) -> Vec<u8> {
// Header
@@ -82,6 +84,7 @@ impl WorldChunk {
bytes
}
#[allow(unused)]
pub fn all_blocks(&self) -> Vec<(Point3<u32>, &WorldBlock)> {
self.nodes.iter().enumerate()
.filter(|(_, n)| **n != 0)
@@ -101,7 +104,7 @@ impl WorldChunk {
.collect()
}
pub fn get_block(&mut self, block_pos: &Point3<u32>) -> &mut WorldBlock {
pub fn get_block_mut(&mut self, block_pos: &Point3<u32>) -> &mut WorldBlock {
// Get block index
let index = (block_pos.x + SIZE as u32 * (block_pos.y + SIZE as u32 * block_pos.z)) as usize;
let mut value = self.nodes[index];
@@ -114,4 +117,12 @@ impl WorldChunk {
// Return block reference
&mut self.blocks[(value-1) as usize]
}
pub fn get_block(&self, block_pos: &Point3<u32>) -> &WorldBlock {
// Get block index
let index = (block_pos.x + SIZE as u32 * (block_pos.y + SIZE as u32 * block_pos.z)) as usize;
let value = self.nodes[index];
// Return block reference
&self.blocks[(value-1) as usize]
}
}