package org.spacehq.mc.protocol.packet.ingame.server.world;

import org.spacehq.mc.protocol.data.game.chunk.Chunk;
import org.spacehq.mc.protocol.data.game.chunk.Column;
import org.spacehq.mc.protocol.util.NetUtil;
import org.spacehq.packetlib.io.NetInput;
import org.spacehq.packetlib.io.NetOutput;
import org.spacehq.packetlib.io.stream.StreamNetOutput;
import org.spacehq.packetlib.packet.Packet;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class ServerChunkDataPacket implements Packet {

    private Column column;

    @SuppressWarnings("unused")
    private ServerChunkDataPacket() {
    }

    /**
     * Convenience constructor for creating a packet to unload chunks.
     *
     * @param x X of the chunk column.
     * @param z Z of the chunk column.
     */
    public ServerChunkDataPacket(int x, int z) {
        this(new Column(x, z, new Chunk[16], new byte[256]));
    }

    /**
     * Constructs a ServerChunkDataPacket for updating chunks.
     *
     * @param column Column to send.
     */
    public ServerChunkDataPacket(Column column) {
        this.column = column;
    }

    public Column getColumn() {
        return this.column;
    }

    @Override
    public void read(NetInput in) throws IOException {
        int x = in.readInt();
        int z = in.readInt();
        boolean fullChunk = in.readBoolean();
        int chunkMask = in.readInt();
        byte data[] = in.readBytes(in.readVarInt());

        this.column = NetUtil.readColumn(data, x, z, fullChunk, false, chunkMask);
    }

    @Override
    public void write(NetOutput out) throws IOException {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        NetOutput netOut = new StreamNetOutput(byteOut);
        int mask = NetUtil.writeColumn(netOut, this.column, this.column.hasBiomeData(), this.column.hasSkylight());

        out.writeInt(this.column.getX());
        out.writeInt(this.column.getZ());
        out.writeBoolean(this.column.hasBiomeData());
        out.writeShort(mask);
        out.writeVarInt(byteOut.size());
        out.writeBytes(byteOut.toByteArray(), byteOut.size());
    }

    @Override
    public boolean isPriority() {
        return false;
    }
}

@@ -58,62 +58,8 @@
 d;%0A%0A
-import org.spacehq.mc.protocol.data.game.chunk.Chunk;%0A
 impo
@@ -109,16 +109,16 @@
 Column;%0A
+
 import o
@@ -462,17 +462,16 @@
 acket %7B%0A
-%0A
     priv
@@ -571,421 +571,8 @@
  %7D%0A%0A
-    /**%0A     * Convenience constructor for creating a packet to unload chunks.%0A     *%0A     * @param x X of the chunk column.%0A     * @param z Z of the chunk column.%0A     */%0A    public ServerChunkDataPacket(int x, int z) %7B%0A        this(new Column(x, z, new Chunk%5B16%5D, new byte%5B256%5D));%0A    %7D%0A%0A    /**%0A     * Constructs a ServerChunkDataPacket for updating chunks.%0A     *%0A     * @param column Column to send.%0A     */%0A
     

Remove old chunk data packet constructor for unloading chunks.