1 #ifndef BLANK_WORLD_BLOCKLOOKUP_HPP_
2 #define BLANK_WORLD_BLOCKLOOKUP_HPP_
5 #include "BlockType.hpp"
14 /// resolve chunk/position from oob coordinates
15 BlockLookup(Chunk *c, const RoughLocation::Fine &p) noexcept;
17 /// resolve chunk/position from ib coordinates and direction
18 BlockLookup(Chunk *c, const RoughLocation::Fine &p, Block::Face dir) noexcept;
20 /// check if lookup was successful
21 operator bool() const { return chunk; }
23 // only valid if lookup was successful
24 Chunk &GetChunk() const noexcept { return *chunk; }
25 const RoughLocation::Fine &GetBlockPos() const noexcept { return pos; }
26 int GetBlockIndex() const noexcept { return Chunk::ToIndex(pos); }
27 ExactLocation::Fine GetBlockCoords() const noexcept { return Chunk::ToCoords(pos); }
28 const Block &GetBlock() const noexcept { return GetChunk().BlockAt(GetBlockPos()); }
29 const BlockType &GetType() const noexcept { return GetChunk().Type(GetBlock()); }
30 int GetLight() const noexcept { return GetChunk().GetLight(GetBlockPos()); }
32 bool FaceFilled(Block::Face f) const noexcept { return GetType().FaceFilled(GetBlock(), f); }
34 void SetBlock(const Block &b) noexcept { GetChunk().SetBlock(GetBlockPos(), b); }
36 // traverse in given direction
37 BlockLookup Next(Block::Face f) const { return BlockLookup(chunk, pos, f); }
41 RoughLocation::Fine pos;