WorldPackets.cpp 943 B

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