+class BlockLookup {
+
+public:
+ // resolve chunk/position from oob coordinates
+ BlockLookup(Chunk *c, const Chunk::Pos &p) noexcept;
+
+ // resolve chunk/position from ib coordinates and direction
+ BlockLookup(Chunk *c, const Chunk::Pos &p, Block::Face dir) noexcept;
+
+ // check if lookup was successful
+ operator bool() const { return chunk; }
+
+ // only valid if lookup was successful
+ Chunk &GetChunk() const noexcept { return *chunk; }
+ const Chunk::Pos &GetBlockPos() const noexcept { return pos; }
+ const Block &GetBlock() const noexcept { return GetChunk().BlockAt(GetBlockPos()); }
+ const BlockType &GetType() const noexcept { return GetChunk().Type(GetBlock()); }
+ int GetLight() const noexcept { return GetChunk().GetLight(GetBlockPos()); }
+
+ // traverse in given direction
+ BlockLookup Next(Block::Face f) const { return BlockLookup(chunk, pos, f); }
+
+private:
+ Chunk *chunk;
+ Chunk::Pos pos;
+
+};
+
+