diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/StandardClient.java b/src/main/java/ch/spacebase/mcprotocol/standard/StandardClient.java index dfd21e10..21df7fb1 100644 --- a/src/main/java/ch/spacebase/mcprotocol/standard/StandardClient.java +++ b/src/main/java/ch/spacebase/mcprotocol/standard/StandardClient.java @@ -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()); diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/io/StandardOutput.java b/src/main/java/ch/spacebase/mcprotocol/standard/io/StandardOutput.java index e21f4872..18464f7d 100644 --- a/src/main/java/ch/spacebase/mcprotocol/standard/io/StandardOutput.java +++ b/src/main/java/ch/spacebase/mcprotocol/standard/io/StandardOutput.java @@ -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); } } } diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketLogin.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketLogin.java index 19c88300..d347af50 100644 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketLogin.java +++ b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketLogin.java @@ -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(); - this.dimension = 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); - out.writeByte(this.dimension); + if(FORGE) { + out.writeInt(this.dimension); + } else { + out.writeByte(this.dimension); + } out.writeByte(this.difficulty); out.writeByte(this.unused); out.writeByte(this.maxPlayers); diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMapChunk.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMapChunk.java index ffeed74a..60376e86 100644 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMapChunk.java +++ b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketMapChunk.java @@ -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 diff --git a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerPositionLook.java b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerPositionLook.java index fe3a9661..5f850b82 100644 --- a/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerPositionLook.java +++ b/src/main/java/ch/spacebase/mcprotocol/standard/packet/PacketPlayerPositionLook.java @@ -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();