mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-11 10:58:46 +01:00
Invalidate ChunkCache on unload
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
384126e3b4
commit
59d5bfe6d1
@ -32,7 +32,8 @@ public final class ChunkCache implements Block.Getter {
|
||||
Chunk chunk = this.chunk;
|
||||
final int chunkX = getChunkCoordinate(x);
|
||||
final int chunkZ = getChunkCoordinate(z);
|
||||
if (chunk == null || chunk.getChunkX() != chunkX || chunk.getChunkZ() != chunkZ) {
|
||||
if (chunk == null || !chunk.isLoaded() ||
|
||||
chunk.getChunkX() != chunkX || chunk.getChunkZ() != chunkZ) {
|
||||
this.chunk = chunk = this.instance.getChunk(chunkX, chunkZ);
|
||||
}
|
||||
if (chunk != null) {
|
||||
|
@ -31,4 +31,20 @@ public class InstanceBlockIntegrationTest {
|
||||
instance.loadChunk(1, 0).join();
|
||||
assertEquals(Block.AIR, instance.getBlock(16, 50, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unloadCache(Env env) {
|
||||
var instance = env.createFlatInstance();
|
||||
instance.loadChunk(0, 0).join();
|
||||
|
||||
instance.setBlock(0, 50, 0, Block.GRASS);
|
||||
assertEquals(Block.GRASS, instance.getBlock(0, 50, 0));
|
||||
|
||||
instance.unloadChunk(0, 0);
|
||||
assertThrows(NullPointerException.class, () -> instance.getBlock(0, 0, 0),
|
||||
"No exception throw when getting a block in an unloaded chunk");
|
||||
|
||||
instance.loadChunk(0, 0).join();
|
||||
assertEquals(Block.AIR, instance.getBlock(0, 50, 0));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user