Skip to content

Commit 26c7553

Browse files
committed
Clear chunk on dimension switch
This should resolve chunks being leftover in instances such as server switches in proxies.
1 parent b954150 commit 26c7553

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void addToCache(Column chunk) {
6767
chunks.put(chunkPosition, geyserColumn);
6868
}
6969

70-
public GeyserColumn getChunk(int chunkX, int chunkZ) {
70+
public GeyserColumn getChunk(int chunkX, int chunkZ) {
7171
long chunkPosition = MathUtils.chunkPositionToLong(chunkX, chunkZ);
7272
return chunks.getOrDefault(chunkPosition, null);
7373
}
@@ -136,6 +136,19 @@ public void removeChunk(int chunkX, int chunkZ) {
136136
chunks.remove(chunkPosition);
137137
}
138138

139+
/**
140+
* Manually clears all entries in the chunk cache.
141+
* The server is responsible for clearing chunk entries if out of render distance (for example) or switching dimensions,
142+
* but it is the client that must clear chunks in the event of proxy switches.
143+
*/
144+
public void clear() {
145+
if (!cache) {
146+
return;
147+
}
148+
149+
chunks.clear();
150+
}
151+
139152
public int getChunkMinY() {
140153
return minY >> 4;
141154
}

connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public static void switchDimension(GeyserSession session, String javaDimension)
6060
int bedrockDimension = javaToBedrock(javaDimension);
6161
Entity player = session.getPlayerEntity();
6262

63+
session.getChunkCache().clear();
6364
session.getEntityCache().removeAllEntities();
6465
session.getItemFrameCache().clear();
6566
session.getLecternCache().clear();

0 commit comments

Comments
 (0)