summary refs log tree commit diff
path: root/src/World/Chunk.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/World/Chunk.cpp')
-rw-r--r--src/World/Chunk.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp
index 08f08bc..1874950 100644
--- a/src/World/Chunk.cpp
+++ b/src/World/Chunk.cpp
@@ -3,8 +3,12 @@
 
 namespace MC::World {
 
-void Chunk::set(uint32_t x, uint32_t y, uint32_t z, BlockType type) {
-    m_blocks[x][y][z].type = type;
+void Chunk::set(uint32_t x, uint32_t y, uint32_t z, BlockData data) {
+    m_blocks[pos(x, y, z)] = data;
+}
+
+Chunk::BlockData Chunk::get(uint32_t x, uint32_t y, uint32_t z) {
+    return m_blocks[pos(x, y, z)];
 }
 
 GFX::Mesh Chunk::mesh() {
@@ -16,7 +20,7 @@ GFX::Mesh Chunk::mesh() {
     for (int x = 0; x < Chunk::Width; x++) {
         for (int y = 0; y < Chunk::Height; y++) {
             for (int z = 0; z < Chunk::Width; z++) {
-                auto type = m_blocks[x][y][z].type;
+                auto type = get(x, y, z).type;
                 if (type == BlockType::Air) {
                     continue;
                 }
@@ -90,7 +94,7 @@ bool Chunk::is_face_visible(uint32_t x, uint32_t y, uint32_t z, BlockSide side)
         return true;
     }
 
-    auto neighbor = m_blocks[neighbor_pos.x()][neighbor_pos.y()][neighbor_pos.z()];
+    auto neighbor = get(neighbor_pos.x(), neighbor_pos.y(), neighbor_pos.z());
     if (neighbor.type == BlockType::Air) {
         return true;
     }
@@ -154,4 +158,8 @@ std::array<Vector<3>, 4> Chunk::face_normals(BlockSide side) {
     return {normal, normal, normal, normal};
 }
 
+uint64_t Chunk::pos(uint32_t x, uint32_t y, uint32_t z) {
+    return x + Chunk::Width * y + Chunk::Width * Chunk::Height * z;
+}
+
 }