Skip to content

Commit

Permalink
Properly read unused light data in 1.17->1.16
Browse files Browse the repository at this point in the history
Some servers for some reason do this
  • Loading branch information
kennytv committed Aug 18, 2024
1 parent ef2621c commit 0b3a792
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,27 +247,37 @@ public void register() {

private void writeLightArrays(PacketWrapper wrapper, BitSet bitMask, int cutBitMask,
int startFromSection, int sectionHeight) {
wrapper.read(Types.VAR_INT); // Length - throw it away

int packetContentsLength = wrapper.read(Types.VAR_INT);
int read = 0;
List<byte[]> light = new ArrayList<>();

// Remove lower bounds
for (int i = 0; i < startFromSection; i++) {
if (bitMask.get(i)) {
read++;
wrapper.read(Types.BYTE_ARRAY_PRIMITIVE);
}
}

// Add the important 18 sections
for (int i = 0; i < 18; i++) {
if (isSet(cutBitMask, i)) {
read++;
light.add(wrapper.read(Types.BYTE_ARRAY_PRIMITIVE));
}
}

// Remove upper bounds
for (int i = startFromSection + 18; i < sectionHeight + 2; i++) {
if (bitMask.get(i)) {
read++;
wrapper.read(Types.BYTE_ARRAY_PRIMITIVE);
}
}

if (read != packetContentsLength) {
// Read the rest if the server for some reason sends more than are actually consumed
for (int i = read; i < packetContentsLength; i++) {
wrapper.read(Types.BYTE_ARRAY_PRIMITIVE);
}
}
Expand Down

0 comments on commit 0b3a792

Please sign in to comment.