Как правильно упаковать данные в пакет minecraft? (netty)
Пытаюсь сделать пакет для отправки сообщения в чат. Уже есть CHandshakePacket и CLoginStartPacket. Они оба работают и передают нужные данные. А при отправке CChatMessagePacket на сервер, вылезает вот это:
lost connection: Internal Exception: io.netty.handler.codec.DecoderException: java.io.IOException: Bad packet id 14
CChatMessagePacket:
public class CChatMessagePacket extends Packet {
public String message;
public GameProfile gp;
public CChatMessagePacket(String message, GameProfile gp) {
this.message = message;
this.gp = gp;
}
@Override
public void write(ByteBuf buf) {
//
PacketUtils.writeString(this.message, buf);
buf.writeByte(0);
PacketUtils.writeUniqueId(GameProfile.getOfflineUUID(gp.getName()), buf);
}
@Override
public byte[] getWrappedPacket() {
ByteBuf allocated = Unpooled.buffer();
allocated.writeByte(0x0E);//айди пакета
this.write(allocated);//запись данных
ByteBuf wrapped = Unpooled.buffer();
PacketUtils.writeVarInt(allocated.readableBytes(), wrapped);
wrapped.writeBytes(allocated);
byte[] bytes = new byte[wrapped.readableBytes()];
wrapped.getBytes(0, bytes);
wrapped.release();
return bytes;
}
}
Вот еще CHandshakePacket для примера:
public class CHandshakePacket extends Packet {
public int protocolVersion;
public String host;
public int port;
public int requestedProtocol;
public CHandshakePacket(int protocolVersion, String host, int port, int requestedProtocol) {
this.protocolVersion = protocolVersion;
this.host = host;
this.port = port;
this.requestedProtocol = requestedProtocol;
}
@Override
public void write(final ByteBuf buf) {
PacketUtils.writeVarInt(this.protocolVersion, buf);
PacketUtils.writeString(this.host, buf);
buf.writeShort(this.port);
PacketUtils.writeVarInt(this.requestedProtocol, buf);
}
@Override
public byte[] getWrappedPacket() {
ByteBuf allocated = Unpooled.buffer();
allocated.writeByte(0x00);
this.write(allocated);
ByteBuf wrapped = Unpooled.buffer();
PacketUtils.writeVarInt(allocated.readableBytes(), wrapped);
wrapped.writeBytes(allocated);
byte[] bytes = new byte[wrapped.readableBytes()];
wrapped.getBytes(0, bytes);
wrapped.release();
return bytes;
}
}
Есть предположения, что я делаю не так и как это исправить?