]> git.localhorst.tv Git - blank.git/blob - src/world/BlockLookup.hpp
some code reorganization
[blank.git] / src / world / BlockLookup.hpp
1 #ifndef BLANK_WORLD_BLOCKLOOKUP_HPP_
2 #define BLANK_WORLD_BLOCKLOOKUP_HPP_
3
4 #include "Block.hpp"
5 #include "Chunk.hpp"
6
7
8 namespace blank {
9
10 class BlockLookup {
11
12 public:
13         // resolve chunk/position from oob coordinates
14         BlockLookup(Chunk *c, const Chunk::Pos &p) noexcept;
15
16         // resolve chunk/position from ib coordinates and direction
17         BlockLookup(Chunk *c, const Chunk::Pos &p, Block::Face dir) noexcept;
18
19         // check if lookup was successful
20         operator bool() const { return chunk; }
21
22         // only valid if lookup was successful
23         Chunk &GetChunk() const noexcept { return *chunk; }
24         const Chunk::Pos &GetBlockPos() const noexcept { return pos; }
25         const Block &GetBlock() const noexcept { return GetChunk().BlockAt(GetBlockPos()); }
26         const BlockType &GetType() const noexcept { return GetChunk().Type(GetBlock()); }
27         int GetLight() const noexcept { return GetChunk().GetLight(GetBlockPos()); }
28
29         // traverse in given direction
30         BlockLookup Next(Block::Face f) const { return BlockLookup(chunk, pos, f); }
31
32 private:
33         Chunk *chunk;
34         Chunk::Pos pos;
35
36 };
37
38 }
39
40 #endif