WIP generating chunks at player position
This commit is contained in:
+12
-1
@@ -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]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user