summary refs log tree commit diff
path: root/src/World/Chunk.cpp
blob: 94e757e3c619dcfc55598b2c1e56e1e705058469 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "Chunk.hpp"
#include "BlockSide.hpp"

namespace MC::World {

void Chunk::set(U32 x, U32 y, U32 z, BlockData data) {
    m_blocks.at(pos(x, y, z)) = data;
}

Chunk::BlockData Chunk::get(U32 x, U32 y, U32 z) const {
    return m_blocks.at(pos(x, y, z));
}

Bool Chunk::is_empty(U32 x, U32 y, U32 z) const {
    return get(x, y, z).empty();
}

Vector<3> Chunk::position() const {
    return m_position;
}

Bool Chunk::is_valid_position(U32 x, U32 y, U32 z) {
    return x < Width && y < Height && z < Width;
}

U64 Chunk::pos(U32 x, U32 y, U32 z) {
    return x + Width * y + Width * Height * z;
}

}