Chunk.cpp 644 B

1234567891011121314151617181920
  1. #include "common/world/Chunk.h"
  2. #include "common/block/BlockRegistry.h"
  3. Chunk::Chunk() {
  4. for(u32 y = 0; y < HEIGHT; y++) {
  5. for(u32 x = 0; x < CHUNK_PARTION_SIZE; x++) {
  6. for(u32 z = 0; z < CHUNK_PARTION_SIZE; z++) {
  7. blocks[y][x][z] = 0;
  8. }
  9. }
  10. }
  11. }
  12. const Block& Chunk::getBlock(u32 x, u32 y, u32 z) const {
  13. return BlockRegistry::getBlock(blocks[y & BITMASK_HEIGHT][x & CHUNK_PARTION_SIZE][z & CHUNK_PARTION_SIZE]);
  14. }
  15. void Chunk::setBlock(u32 x, u32 y, u32 z, const Block& block) {
  16. blocks[y & BITMASK_HEIGHT][x & CHUNK_PARTION_SIZE][z & CHUNK_PARTION_SIZE] = block.getId();
  17. }