Search in sources :

Example 1 with SPacketCustomPayload

use of net.minecraft.network.play.server.SPacketCustomPayload in project MinecraftForge by MinecraftForge.

the class FMLProxyPacket method toS3FPackets.

public List<Packet<INetHandlerPlayClient>> toS3FPackets() throws IOException {
    List<Packet<INetHandlerPlayClient>> ret = Lists.newArrayList();
    byte[] data = payload.array();
    if (data.length < PART_SIZE) {
        ret.add(new SPacketCustomPayload(channel, new PacketBuffer(payload.duplicate())));
    } else {
        //We add a byte header so -1
        int parts = (int) Math.ceil(data.length / (double) (PART_SIZE - 1));
        if (parts > 255) {
            throw new IllegalArgumentException("Payload may not be larger than " + MAX_LENGTH + " bytes");
        }
        PacketBuffer preamble = new PacketBuffer(Unpooled.buffer());
        preamble.writeString(channel);
        preamble.writeByte(parts);
        preamble.writeInt(data.length);
        ret.add(new SPacketCustomPayload("FML|MP", preamble));
        int offset = 0;
        for (int x = 0; x < parts; x++) {
            int length = Math.min(PART_SIZE, data.length - offset + 1);
            byte[] tmp = new byte[length];
            tmp[0] = (byte) (x & 0xFF);
            System.arraycopy(data, offset, tmp, 1, tmp.length - 1);
            offset += tmp.length - 1;
            ret.add(new SPacketCustomPayload("FML|MP", new PacketBuffer(Unpooled.wrappedBuffer(tmp))));
        }
    }
    return ret;
}
Also used : Packet(net.minecraft.network.Packet) SPacketCustomPayload(net.minecraft.network.play.server.SPacketCustomPayload) PacketBuffer(net.minecraft.network.PacketBuffer)

Aggregations

Packet (net.minecraft.network.Packet)1 PacketBuffer (net.minecraft.network.PacketBuffer)1 SPacketCustomPayload (net.minecraft.network.play.server.SPacketCustomPayload)1