123456789101112131415161718192021222324252627282930313233 |
- #include "client/packets/WorldPackets.h"
- #include "client/Game.h"
- #include "common/network/Packets.h"
- #include "utils/Logger.h"
- void WorldPackets::receiveChunk(World& w, InPacket& in) {
- LOG_DEBUG("received chunk from server");
- int32 ox;
- int32 oz;
- if(in.readS32(ox) || in.readS32(oz)) {
- LOG_WARNING("missing chunk offset in packet");
- return;
- }
- uint16 counter = 0;
- const Block* b = &Game::blockRegistry.getBlock("air");
- for(int y = 0; y < w.getHeight(); y++) {
- for(int x = 0; x < BlockStorage::SEGMENT; x++) {
- for(int z = 0; z < BlockStorage::SEGMENT; z++) {
- if(counter == 0) {
- BlockId id;
- if(in.readU16(id) || in.readU16(counter)) {
- LOG_WARNING("missing block data in packet");
- return;
- }
- b = &Game::blockRegistry.getBlock(id);
- }
- w.setBlock(ox + x, y, oz + z, *b);
- counter--;
- }
- }
- }
- w.dirty = true;
- }
|