From f9f74a0da877e94b2da5d542475ea0e6f557b170 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 25 Jun 2021 13:51:52 -0400 Subject: [PATCH] Determine chunk Y offset on Java packet processing thread Should stop NullPointerExceptions if the session closes before chunks are processed --- .../translators/java/world/JavaChunkDataTranslator.java | 5 ++++- .../main/java/org/geysermc/connector/utils/ChunkUtils.java | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java index 198a7e3fb..81f5c4db3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java @@ -55,9 +55,12 @@ public class JavaChunkDataTranslator extends PacketTranslator { try { - ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, column); + ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, column, yOffset); ChunkSection[] sections = chunkData.getSections(); // Find highest section diff --git a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java index 9723cd53c..85b7f8600 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java @@ -81,10 +81,8 @@ public class ChunkUtils { return (yzx >> 8) | (yzx & 0x0F0) | ((yzx & 0x00F) << 8); } - public static ChunkData translateToBedrock(GeyserSession session, Column column) { + public static ChunkData translateToBedrock(GeyserSession session, Column column, int yOffset) { Chunk[] javaSections = column.getChunks(); - // Ensure that, if the player is using lower world heights, the position is not offset - int yOffset = session.getChunkCache().getChunkMinY(); ChunkSection[] sections = new ChunkSection[javaSections.length - yOffset]; // Temporarily stores compound tags of Bedrock-only block entities