Обновляем пакеты
This commit is contained in:
@@ -10,6 +10,7 @@ import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_1_12_2.netty.wrappers.ByteArrayOutputNetStream;
|
||||
import mc.core.network.proto_1_12_2.State;
|
||||
import mc.core.network.proto_1_12_2.netty.wrappers.WrapperNetStream;
|
||||
|
||||
@@ -38,8 +39,10 @@ public class PacketEncoder extends MessageToByteEncoder<SCPacket> {
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] bytes = packet.toByteArray();
|
||||
NetStream netStream = new WrapperNetStream(out);
|
||||
NetStream netStream = new ByteArrayOutputNetStream();
|
||||
packet.writeSelf(netStream);
|
||||
byte[] bytes = ((ByteArrayOutputNetStream) netStream).toByteArray();
|
||||
netStream = new WrapperNetStream(out);
|
||||
|
||||
netStream.writeVarInt(bytes.length + sizeVarInt(id));
|
||||
netStream.writeVarInt(id);
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-06-10
|
||||
*/
|
||||
package mc.core.network.proto_1_12_2.netty.wrappers;
|
||||
|
||||
import mc.core.network.proto_1_12_2.NetStream_p340;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public class ByteArrayOutputNetStream extends NetStream_p340 {
|
||||
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
@Override
|
||||
public boolean readBoolean() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readByte() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readBytes(byte[] buffer) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readUnsignedByte() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readUnsignedShort() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float readFloat() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double readDouble() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBoolean(boolean value) {
|
||||
baos.write(value ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeByte(int value) {
|
||||
baos.write(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeUnsignedByte(int value) {
|
||||
baos.write((byte)(value & 0xFF));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBytes(byte[] buffer) {
|
||||
baos.write(buffer, 0, buffer.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeShort(int value) {
|
||||
baos.write((byte) value >>> 8);
|
||||
baos.write((byte) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeInt(int value) {
|
||||
baos.write((byte)((int)(value >>> 24)));
|
||||
baos.write((byte)((int)(value >>> 16)));
|
||||
baos.write((byte)((int)(value >>> 8)));
|
||||
baos.write((byte)((int)(value)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeLong(long value) {
|
||||
baos.write((byte)((int)(value >>> 56)));
|
||||
baos.write((byte)((int)(value >>> 48)));
|
||||
baos.write((byte)((int)(value >>> 40)));
|
||||
baos.write((byte)((int)(value >>> 32)));
|
||||
baos.write((byte)((int)(value >>> 24)));
|
||||
baos.write((byte)((int)(value >>> 16)));
|
||||
baos.write((byte)((int)(value >>> 8)));
|
||||
baos.write((byte)((int)(value)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeFloat(float value) {
|
||||
writeInt(Float.floatToIntBits(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDouble(double value) {
|
||||
writeLong(Double.doubleToLongBits(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skipBytes(int count) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public byte[] toByteArray() {
|
||||
return baos.toByteArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user