1234567891011121314151617181920212223242526272829303132333435363738 |
- #include "server/packets/WorldPackets.h"
- #include "common/network/Packets.h"
- void WorldPackets::sendChunk(ServerPlayer& p, World& w, int cx, int cz) {
- constexpr int size = BlockStorage::SEGMENT;
- cx *= size;
- cz *= size;
- OutPacket out = OutPacket::reliable(
- w.getHeight() * size * size * sizeof(BlockId) * 2 + 10);
- out.writeU16(Packets::S_WORLD_SEGMENT);
- out.writeS32(cx);
- out.writeS32(cz);
- int endX = cx + size;
- int endZ = cz + size;
- BlockId current = w.getBlock(cx, 0, cz).getId();
- uint16 counter = 0;
- for(int y = 0; y < w.getHeight(); y++) {
- for(int x = cx; x < endX; x++) {
- for(int z = cz; z < endZ; z++) {
- BlockId id = w.getBlock(x, y, z).getId();
- if(current == id && counter < 65535) {
- counter++;
- } else {
- out.writeU16(current);
- out.writeU16(counter);
- current = id;
- counter = 1;
- }
- }
- }
- }
- out.writeU16(current);
- out.writeU16(counter);
- p.send(out);
- }
|