Fixed some packets, added forge dimension field compatibility to PacketLogin (set PacketLogin.FORGE = true)

This commit is contained in:
Steveice10 2013-08-18 10:14:14 -07:00
parent 3f0ad4b462
commit f65f0f59e5
5 changed files with 44 additions and 26 deletions

View file

@ -126,9 +126,7 @@ public class StandardClient extends StandardConnection implements Client {
Util.logger().info("Finished logging in to minecraft.net");
return true;
} else {
if(result.trim().equals("Bad login")) {
return false;
} else if(result.trim().equals("Old version")) {
if(result.trim().equals("Old version")) {
throw new OutdatedLibraryException();
} else {
throw new LoginException(result.trim());

View file

@ -84,6 +84,10 @@ public class StandardOutput implements NetOutput {
@Override
public void writeString(String s) throws IOException {
if(s == null) {
throw new IllegalArgumentException("String cannot be null!");
}
int len = s.length();
if(len >= 65536) {
throw new IllegalArgumentException("String too long.");
@ -150,6 +154,8 @@ public class StandardOutput implements NetOutput {
if(item.getNBT() != null) {
this.writeShort(item.getNBT().length);
this.writeBytes(item.getNBT());
} else {
this.writeShort(-1);
}
}
}

View file

@ -10,10 +10,12 @@ import ch.spacebase.mcprotocol.packet.Packet;
public class PacketLogin extends Packet {
public static boolean FORGE = false;
public int entityId;
public String levelType;
public byte gameMode;
public byte dimension;
public int dimension;
public byte difficulty;
public byte unused;
public byte maxPlayers;
@ -21,7 +23,7 @@ public class PacketLogin extends Packet {
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.levelType = levelType;
this.gameMode = gameMode;
@ -36,7 +38,12 @@ public class PacketLogin extends Packet {
this.entityId = in.readInt();
this.levelType = in.readString();
this.gameMode = in.readByte();
if(FORGE) {
this.dimension = in.readInt();
} else {
this.dimension = in.readByte();
}
this.difficulty = in.readByte();
this.unused = in.readByte();
this.maxPlayers = in.readByte();
@ -47,7 +54,11 @@ public class PacketLogin extends Packet {
out.writeInt(this.entityId);
out.writeString(this.levelType);
out.writeByte(this.gameMode);
if(FORGE) {
out.writeInt(this.dimension);
} else {
out.writeByte(this.dimension);
}
out.writeByte(this.difficulty);
out.writeByte(this.unused);
out.writeByte(this.maxPlayers);

View file

@ -19,7 +19,6 @@ public class PacketMapChunk extends Packet {
public int startY;
public int endY;
public byte data[];
public int length;
public PacketMapChunk() {
}
@ -30,17 +29,7 @@ public class PacketMapChunk extends Packet {
this.groundUp = groundUp;
this.startY = startY;
this.endY = endY;
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();
}
this.data = data;
}
@Override
@ -50,23 +39,25 @@ public class PacketMapChunk extends Packet {
this.groundUp = in.readBoolean();
this.startY = 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 msb = 0;
for(int count = 0; count < 16; count++) {
off += this.startY >> count & 1;
msb += this.endY >> count & 1;
}
int size = 12288 * off;
int size = (12288 * off) + (2048 * msb);
if(this.groundUp) {
size += 256;
}
this.data = new byte[size];
Inflater inflater = new Inflater();
inflater.setInput(compressed, 0, this.length);
inflater.setInput(compressed, 0, length);
try {
inflater.inflate(this.data);
@ -79,13 +70,25 @@ public class PacketMapChunk extends Packet {
@Override
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.z);
out.writeBoolean(this.groundUp);
out.writeShort((short) (this.startY & 0xffff));
out.writeShort((short) (this.endY & 0xffff));
out.writeInt(this.length);
out.writeBytes(this.data, this.length);
out.writeInt(length);
out.writeBytes(data, length);
}
@Override

View file

@ -34,8 +34,8 @@ public class PacketPlayerPositionLook extends Packet {
@Override
public void read(NetInput in) throws IOException {
this.x = in.readDouble();
this.stance = in.readDouble();
this.y = in.readDouble();
this.stance = in.readDouble();
this.z = in.readDouble();
this.yaw = in.readFloat();
this.pitch = in.readFloat();