fix chunk reading for some servers (1.9)

This commit is contained in:
Bixilon 2020-07-03 23:37:09 +02:00
parent 9dcbcfcf29
commit 9872606d40
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 17 additions and 9 deletions

View File

@ -189,6 +189,7 @@ public class Connection {
handleThread.start();
}
public PluginChannelHandler getPluginChannelHandler() {
return pluginChannelHandler;
}

View File

@ -53,6 +53,8 @@ public class PacketChunkData implements ClientboundPacket {
boolean groundUpContinuous = buffer.readBoolean();
short sectionBitMask = buffer.readShort();
int size = buffer.readVarInt();
int lastPos = buffer.getPosition();
buffer.setPosition(size + lastPos);
chunk = ChunkUtil.readChunkPacket(buffer, sectionBitMask, (short) 0, groundUpContinuous, true);
return true;
@ -62,13 +64,19 @@ public class PacketChunkData implements ClientboundPacket {
boolean groundUpContinuous = buffer.readBoolean();
short sectionBitMask = (short) buffer.readVarInt();
int size = buffer.readVarInt();
int lastPos = buffer.getPosition();
chunk = ChunkUtil.readChunkPacket(buffer, sectionBitMask, (short) 0, groundUpContinuous, true);
// set position of the byte buffer, because of some reasons HyPixel makes some weired stuff and sends way to much 0 bytes. (~ 190k)
buffer.setPosition(size + lastPos);
int blockEntitiesCount = buffer.readVarInt();
for (int i = 0; i < blockEntitiesCount; i++) {
CompoundTag tag = buffer.readNBT();
blockEntities.put(new BlockPosition(tag.getIntTag("x").getValue(), (short) tag.getIntTag("y").getValue(), tag.getIntTag("z").getValue()), tag);
}
if (buffer.getBytesLeft() > 0) {
Log.debug("ERROR");
}
return true;
}
}

View File

@ -37,7 +37,7 @@ public class PacketPlayerAbilitiesSending implements ServerboundPacket {
case VERSION_1_7_10:
case VERSION_1_8:
case VERSION_1_9_4:
// only fly matches, everything else ignored
// only fly matters, everything else ignored
byte flags = 0;
if (flying) {
flags |= 0b10;

View File

@ -73,7 +73,7 @@ public class PacketPlayerDigging implements ServerboundPacket {
@Override
public void log() {
Log.protocol(String.format("Send player digging packet (status=%s, position=%s, face=%d)", status.name(), position.toString(), face));
Log.protocol(String.format("Send player digging packet (status=%s, position=%s, face=%s)", status.name(), position.toString(), face.name()));
}
public enum DiggingStatus {

View File

@ -378,4 +378,8 @@ public class InByteBuffer {
public String toString() {
return "dataLen: " + bytes.length + "; pos: " + pos;
}
public byte[] getBytes() {
return bytes;
}
}

View File

@ -55,15 +55,10 @@ public class Util {
while (!inflater.finished()) {
stream.write(buffer, 0, inflater.inflate(buffer));
}
} catch (DataFormatException e) {
e.printStackTrace();
} finally {
try {
stream.close();
} catch (IOException e) {
} catch (IOException | DataFormatException e) {
e.printStackTrace();
}
}
return new InByteBuffer(stream.toByteArray(), version);
}