diff options
| author | Mel <einebeere@gmail.com> | 2023-07-21 02:17:03 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2023-07-21 02:17:03 +0200 |
| commit | 23d88e5f1c8f0c8652a07050fcfa8ff126e85d4a (patch) | |
| tree | d2979c12a9675885b7ed969d5f51dbd69d969286 /src/World/Generation/ChunkNeighbors.cpp | |
| parent | c0556f76fc5c8271c2eaa7ca91ad1c92c691d8bc (diff) | |
| download | meowcraft-23d88e5f1c8f0c8652a07050fcfa8ff126e85d4a.tar.zst meowcraft-23d88e5f1c8f0c8652a07050fcfa8ff126e85d4a.zip | |
Extremely simple chunk-limited lighting
Diffstat (limited to 'src/World/Generation/ChunkNeighbors.cpp')
| -rw-r--r-- | src/World/Generation/ChunkNeighbors.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/World/Generation/ChunkNeighbors.cpp b/src/World/Generation/ChunkNeighbors.cpp new file mode 100644 index 0000000..f34466e --- /dev/null +++ b/src/World/Generation/ChunkNeighbors.cpp @@ -0,0 +1,34 @@ +#include "ChunkNeighbors.hpp" + +namespace MC::World::Generation { + +Chunk::BlockData get_block_wrapping(const Chunk& chunk, const ChunkNeighbors& neighbors, Vector<3, I32> pos) { + const Chunk* chunk_to_ask; + + auto overflow = [](I32& c, I32 max) -> I8 { + if (c < 0) { c += max; return -1; } + if (c >= max) { c -= max; return 1; } + return 0; + }; + + auto xo = overflow(pos.x(), Chunk::Width); + auto yo = overflow(pos.y(), Chunk::Height); + auto zo = overflow(pos.z(), Chunk::Width); + + // Blocks above and below a chunk are always Air. + if (yo != 0) return {}; + + if (xo == 1 && zo == 1) { chunk_to_ask = neighbors.south_east; } + else if (xo == 1 && zo == -1) { chunk_to_ask = neighbors.north_east; } + else if (xo == -1 && zo == 1) { chunk_to_ask = neighbors.south_west; } + else if (xo == -1 && zo == -1) { chunk_to_ask = neighbors.north_west; } + else if (xo == 1) { chunk_to_ask = neighbors.east; } + else if (xo == -1) { chunk_to_ask = neighbors.west; } + else if (zo == 1) { chunk_to_ask = neighbors.south; } + else if (zo == -1) { chunk_to_ask = neighbors.north; } + else { chunk_to_ask = &chunk; } + + return chunk_to_ask->at(pos.x(), pos.y(), pos.z()); +} + +} \ No newline at end of file |
