Skip to content

Commit 2a86351

Browse files
committed
actually check if chunk is unloaded
1 parent eccd6ec commit 2a86351

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/java/gregtech/api/metatileentity/NeighborCacheTileEntityBase.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,20 @@ public void onChunkUnload() {
7575

7676
private boolean invalidRef(EnumFacing facing) {
7777
WeakReference<TileEntity> ref = getRef(facing);
78-
if (ref == INVALID || crossesChunk(facing)) return true;
78+
if (ref == INVALID || crossesUnloadedChunk(facing)) return true;
7979
TileEntity te = ref.get();
8080
return te != null && te.isInvalid();
8181
}
8282

83-
private boolean crossesChunk(EnumFacing facing) {
84-
BlockPos pos = getPos();
83+
private boolean crossesUnloadedChunk(EnumFacing facing) {
84+
int cx = getPos().getX() >> 4, cz = getPos().getZ() >> 4;
8585
BlockPos offset = getPos().offset(facing);
86-
return pos.getX() >> 4 != offset.getX() >> 4 ||
87-
pos.getZ() >> 4 != offset.getZ() >> 4;
86+
int ncx = offset.getX() >> 4, ncz = offset.getZ() >> 4;
87+
88+
if (cx != ncx || cz != ncz) {
89+
return getWorld().getChunkProvider().getLoadedChunk(ncx, ncz) == null;
90+
}
91+
return false;
8892
}
8993

9094
@NotNull

0 commit comments

Comments
 (0)