WorldPackets.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #include "client/packets/WorldPackets.h"
  2. #include "client/Game.h"
  3. #include "common/network/Packets.h"
  4. #include "utils/Logger.h"
  5. void WorldPackets::receiveChunk(World& w, InPacket& in) {
  6. LOG_DEBUG("received chunk from server");
  7. int32 ox;
  8. int32 oz;
  9. if(in.readS32(ox) || in.readS32(oz)) {
  10. LOG_WARNING("missing chunk offset in packet");
  11. return;
  12. }
  13. uint16 counter = 0;
  14. const Block* b = &Game::blockRegistry.getBlock("air");
  15. for(int y = 0; y < w.getHeight(); y++) {
  16. for(int x = 0; x < BlockStorage::SEGMENT; x++) {
  17. for(int z = 0; z < BlockStorage::SEGMENT; z++) {
  18. if(counter == 0) {
  19. BlockId id;
  20. if(in.readU16(id) || in.readU16(counter)) {
  21. LOG_WARNING("missing block data in packet");
  22. return;
  23. }
  24. b = &Game::blockRegistry.getBlock(id);
  25. }
  26. w.setBlock(ox + x, y, oz + z, *b);
  27. counter--;
  28. }
  29. }
  30. }
  31. w.dirty = true;
  32. }