Determine chunk Y offset on Java packet processing thread

Should stop NullPointerExceptions if the session closes before chunks are processed
This commit is contained in:
Camotoy 2021-06-25 13:51:52 -04:00
parent 975da57617
commit f9f74a0da8
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 5 additions and 4 deletions

View file

@ -55,9 +55,12 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
session.getChunkCache().addToCache(packet.getColumn());
Column column = packet.getColumn();
// Ensure that, if the player is using lower world heights, the position is not offset
int yOffset = session.getChunkCache().getChunkMinY();
GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> {
try {
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, column);
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, column, yOffset);
ChunkSection[] sections = chunkData.getSections();
// Find highest section

View file

@ -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