]> git.localhorst.tv Git - blank.git/blob - src/world/BlockLookup.hpp
special treatment for players
[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         void SetBlock(const Block &b) noexcept { GetChunk().SetBlock(GetBlockPos(), b); }
30
31         // traverse in given direction
32         BlockLookup Next(Block::Face f) const { return BlockLookup(chunk, pos, f); }
33
34 private:
35         Chunk *chunk;
36         Chunk::Pos pos;
37
38 };
39
40 }
41
42 #endif