From 4d16dbf76fd611132d5bef2b9ea2c6d089fd0089 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Wed, 8 May 2019 20:38:36 -0300 Subject: [PATCH 1/2] Not tested workaround for #1312 --- .../types/Chunk1_13Type.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java index 804d69531..7c972abeb 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.List; +import java.util.logging.Level; public class Chunk1_13Type extends PartialType { public Chunk1_13Type(ClientWorld param) { @@ -30,7 +31,7 @@ public class Chunk1_13Type extends PartialType { boolean groundUp = input.readBoolean(); int primaryBitmask = Type.VAR_INT.read(input); - Type.VAR_INT.read(input); + ByteBuf data = input.readSlice(Type.VAR_INT.read(input)); BitSet usedSections = new BitSet(16); ChunkSection[] sections = new ChunkSection[16]; @@ -44,18 +45,23 @@ public class Chunk1_13Type extends PartialType { // Read sections for (int i = 0; i < 16; i++) { if (!usedSections.get(i)) continue; // Section not set - ChunkSection section = Types1_13.CHUNK_SECTION.read(input); + ChunkSection section = Types1_13.CHUNK_SECTION.read(data); sections[i] = section; - section.readBlockLight(input); + section.readBlockLight(data); if (world.getEnvironment() == Environment.NORMAL) { - section.readSkyLight(input); + section.readSkyLight(data); } } int[] biomeData = groundUp ? new int[256] : null; if (groundUp) { - for (int i = 0; i < 256; i++) { - biomeData[i] = input.readInt(); + try { + for (int i = 0; i < 256; i++) { + biomeData[i] = data.readInt(); + } + } catch (IndexOutOfBoundsException e) { + // Some plugin isn't sending biome data while groundUp is true, see #1312 + Via.getPlatform().getLogger().log(Level.WARNING, "IndexOutOfBoundsException while trying to read biome data", e); } } From a51f3473715af0588566e7a91f46de5fc74f01e5 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Fri, 10 May 2019 16:02:17 -0300 Subject: [PATCH 2/2] Use readableBytes --- .../protocol1_13to1_12_2/types/Chunk1_13Type.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java index 7c972abeb..672fd1a34 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java @@ -55,13 +55,12 @@ public class Chunk1_13Type extends PartialType { int[] biomeData = groundUp ? new int[256] : null; if (groundUp) { - try { + if (data.readableBytes() >= 256 * 4) { for (int i = 0; i < 256; i++) { biomeData[i] = data.readInt(); } - } catch (IndexOutOfBoundsException e) { - // Some plugin isn't sending biome data while groundUp is true, see #1312 - Via.getPlatform().getLogger().log(Level.WARNING, "IndexOutOfBoundsException while trying to read biome data", e); + } else { + Via.getPlatform().getLogger().log(Level.WARNING, "Chunk x="+ chunkX + " z=" + chunkZ + " doesn't have biome data!"); } }