Skip to content

Commit

Permalink
Determine chunk Y offset on Java packet processing thread
Browse files Browse the repository at this point in the history
Should stop NullPointerExceptions if the session closes before chunks are processed
  • Loading branch information
Camotoy committed Jun 25, 2021
1 parent 975da57 commit f9f74a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ public void translate(ServerChunkDataPacket packet, GeyserSession session) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ private static int indexYZXtoXZY(int yzx) {
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
Expand Down

0 comments on commit f9f74a0

Please sign in to comment.