mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 21:01:02 -05:00
Fixed some packets, added forge dimension field compatibility to PacketLogin (set PacketLogin.FORGE = true)
This commit is contained in:
parent
3f0ad4b462
commit
f65f0f59e5
5 changed files with 44 additions and 26 deletions
|
@ -126,9 +126,7 @@ public class StandardClient extends StandardConnection implements Client {
|
||||||
Util.logger().info("Finished logging in to minecraft.net");
|
Util.logger().info("Finished logging in to minecraft.net");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if(result.trim().equals("Bad login")) {
|
if(result.trim().equals("Old version")) {
|
||||||
return false;
|
|
||||||
} else if(result.trim().equals("Old version")) {
|
|
||||||
throw new OutdatedLibraryException();
|
throw new OutdatedLibraryException();
|
||||||
} else {
|
} else {
|
||||||
throw new LoginException(result.trim());
|
throw new LoginException(result.trim());
|
||||||
|
|
|
@ -84,6 +84,10 @@ public class StandardOutput implements NetOutput {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeString(String s) throws IOException {
|
public void writeString(String s) throws IOException {
|
||||||
|
if(s == null) {
|
||||||
|
throw new IllegalArgumentException("String cannot be null!");
|
||||||
|
}
|
||||||
|
|
||||||
int len = s.length();
|
int len = s.length();
|
||||||
if(len >= 65536) {
|
if(len >= 65536) {
|
||||||
throw new IllegalArgumentException("String too long.");
|
throw new IllegalArgumentException("String too long.");
|
||||||
|
@ -150,6 +154,8 @@ public class StandardOutput implements NetOutput {
|
||||||
if(item.getNBT() != null) {
|
if(item.getNBT() != null) {
|
||||||
this.writeShort(item.getNBT().length);
|
this.writeShort(item.getNBT().length);
|
||||||
this.writeBytes(item.getNBT());
|
this.writeBytes(item.getNBT());
|
||||||
|
} else {
|
||||||
|
this.writeShort(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,12 @@ import ch.spacebase.mcprotocol.packet.Packet;
|
||||||
|
|
||||||
public class PacketLogin extends Packet {
|
public class PacketLogin extends Packet {
|
||||||
|
|
||||||
|
public static boolean FORGE = false;
|
||||||
|
|
||||||
public int entityId;
|
public int entityId;
|
||||||
public String levelType;
|
public String levelType;
|
||||||
public byte gameMode;
|
public byte gameMode;
|
||||||
public byte dimension;
|
public int dimension;
|
||||||
public byte difficulty;
|
public byte difficulty;
|
||||||
public byte unused;
|
public byte unused;
|
||||||
public byte maxPlayers;
|
public byte maxPlayers;
|
||||||
|
@ -21,7 +23,7 @@ public class PacketLogin extends Packet {
|
||||||
public PacketLogin() {
|
public PacketLogin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketLogin(int entityId, String levelType, byte gameMode, byte dimension, byte difficulty, byte unused, byte maxPlayers) {
|
public PacketLogin(int entityId, String levelType, byte gameMode, int dimension, byte difficulty, byte unused, byte maxPlayers) {
|
||||||
this.entityId = entityId;
|
this.entityId = entityId;
|
||||||
this.levelType = levelType;
|
this.levelType = levelType;
|
||||||
this.gameMode = gameMode;
|
this.gameMode = gameMode;
|
||||||
|
@ -36,7 +38,12 @@ public class PacketLogin extends Packet {
|
||||||
this.entityId = in.readInt();
|
this.entityId = in.readInt();
|
||||||
this.levelType = in.readString();
|
this.levelType = in.readString();
|
||||||
this.gameMode = in.readByte();
|
this.gameMode = in.readByte();
|
||||||
|
if(FORGE) {
|
||||||
|
this.dimension = in.readInt();
|
||||||
|
} else {
|
||||||
this.dimension = in.readByte();
|
this.dimension = in.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
this.difficulty = in.readByte();
|
this.difficulty = in.readByte();
|
||||||
this.unused = in.readByte();
|
this.unused = in.readByte();
|
||||||
this.maxPlayers = in.readByte();
|
this.maxPlayers = in.readByte();
|
||||||
|
@ -47,7 +54,11 @@ public class PacketLogin extends Packet {
|
||||||
out.writeInt(this.entityId);
|
out.writeInt(this.entityId);
|
||||||
out.writeString(this.levelType);
|
out.writeString(this.levelType);
|
||||||
out.writeByte(this.gameMode);
|
out.writeByte(this.gameMode);
|
||||||
|
if(FORGE) {
|
||||||
|
out.writeInt(this.dimension);
|
||||||
|
} else {
|
||||||
out.writeByte(this.dimension);
|
out.writeByte(this.dimension);
|
||||||
|
}
|
||||||
out.writeByte(this.difficulty);
|
out.writeByte(this.difficulty);
|
||||||
out.writeByte(this.unused);
|
out.writeByte(this.unused);
|
||||||
out.writeByte(this.maxPlayers);
|
out.writeByte(this.maxPlayers);
|
||||||
|
|
|
@ -19,7 +19,6 @@ public class PacketMapChunk extends Packet {
|
||||||
public int startY;
|
public int startY;
|
||||||
public int endY;
|
public int endY;
|
||||||
public byte data[];
|
public byte data[];
|
||||||
public int length;
|
|
||||||
|
|
||||||
public PacketMapChunk() {
|
public PacketMapChunk() {
|
||||||
}
|
}
|
||||||
|
@ -30,17 +29,7 @@ public class PacketMapChunk extends Packet {
|
||||||
this.groundUp = groundUp;
|
this.groundUp = groundUp;
|
||||||
this.startY = startY;
|
this.startY = startY;
|
||||||
this.endY = endY;
|
this.endY = endY;
|
||||||
|
this.data = data;
|
||||||
Deflater deflater = new Deflater(-1);
|
|
||||||
|
|
||||||
try {
|
|
||||||
deflater.setInput(data, 0, data.length);
|
|
||||||
deflater.finish();
|
|
||||||
this.data = new byte[data.length];
|
|
||||||
this.length = deflater.deflate(this.data);
|
|
||||||
} finally {
|
|
||||||
deflater.end();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,23 +39,25 @@ public class PacketMapChunk extends Packet {
|
||||||
this.groundUp = in.readBoolean();
|
this.groundUp = in.readBoolean();
|
||||||
this.startY = in.readShort();
|
this.startY = in.readShort();
|
||||||
this.endY = in.readShort();
|
this.endY = in.readShort();
|
||||||
this.length = in.readInt();
|
int length = in.readInt();
|
||||||
|
|
||||||
byte[] compressed = in.readBytes(this.length);
|
byte[] compressed = in.readBytes(length);
|
||||||
|
|
||||||
int off = 0;
|
int off = 0;
|
||||||
|
int msb = 0;
|
||||||
for(int count = 0; count < 16; count++) {
|
for(int count = 0; count < 16; count++) {
|
||||||
off += this.startY >> count & 1;
|
off += this.startY >> count & 1;
|
||||||
|
msb += this.endY >> count & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = 12288 * off;
|
int size = (12288 * off) + (2048 * msb);
|
||||||
if(this.groundUp) {
|
if(this.groundUp) {
|
||||||
size += 256;
|
size += 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.data = new byte[size];
|
this.data = new byte[size];
|
||||||
Inflater inflater = new Inflater();
|
Inflater inflater = new Inflater();
|
||||||
inflater.setInput(compressed, 0, this.length);
|
inflater.setInput(compressed, 0, length);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
inflater.inflate(this.data);
|
inflater.inflate(this.data);
|
||||||
|
@ -79,13 +70,25 @@ public class PacketMapChunk extends Packet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void write(NetOutput out) throws IOException {
|
||||||
|
Deflater deflater = new Deflater(-1);
|
||||||
|
byte data[] = new byte[0];
|
||||||
|
int length = 0;
|
||||||
|
try {
|
||||||
|
deflater.setInput(this.data, 0, this.data.length);
|
||||||
|
deflater.finish();
|
||||||
|
data = new byte[this.data.length];
|
||||||
|
length = deflater.deflate(this.data);
|
||||||
|
} finally {
|
||||||
|
deflater.end();
|
||||||
|
}
|
||||||
|
|
||||||
out.writeInt(this.x);
|
out.writeInt(this.x);
|
||||||
out.writeInt(this.z);
|
out.writeInt(this.z);
|
||||||
out.writeBoolean(this.groundUp);
|
out.writeBoolean(this.groundUp);
|
||||||
out.writeShort((short) (this.startY & 0xffff));
|
out.writeShort((short) (this.startY & 0xffff));
|
||||||
out.writeShort((short) (this.endY & 0xffff));
|
out.writeShort((short) (this.endY & 0xffff));
|
||||||
out.writeInt(this.length);
|
out.writeInt(length);
|
||||||
out.writeBytes(this.data, this.length);
|
out.writeBytes(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,8 +34,8 @@ public class PacketPlayerPositionLook extends Packet {
|
||||||
@Override
|
@Override
|
||||||
public void read(NetInput in) throws IOException {
|
public void read(NetInput in) throws IOException {
|
||||||
this.x = in.readDouble();
|
this.x = in.readDouble();
|
||||||
this.stance = in.readDouble();
|
|
||||||
this.y = in.readDouble();
|
this.y = in.readDouble();
|
||||||
|
this.stance = in.readDouble();
|
||||||
this.z = in.readDouble();
|
this.z = in.readDouble();
|
||||||
this.yaw = in.readFloat();
|
this.yaw = in.readFloat();
|
||||||
this.pitch = in.readFloat();
|
this.pitch = in.readFloat();
|
||||||
|
|
Loading…
Reference in a new issue