Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,27 @@ public void onChunkUnload() {

private boolean invalidRef(EnumFacing facing) {
WeakReference<TileEntity> ref = getRef(facing);
if (ref == INVALID) return true;
if (ref == INVALID || crossesUnloadedChunk(facing)) return true;
TileEntity te = ref.get();
return te != null && te.isInvalid();
}

private boolean crossesUnloadedChunk(EnumFacing facing) {
if (crossesChunk(facing)) {
int ncx = getPos().offset(facing).getX() >> 4;
int ncz = getPos().offset(facing).getZ() >> 4;
return getWorld().getChunkProvider().getLoadedChunk(ncx, ncz) == null;
}
return false;
}

private boolean crossesChunk(EnumFacing facing) {
int cx = getPos().getX() >> 4, cz = getPos().getZ() >> 4;
BlockPos offset = getPos().offset(facing);
int ncx = offset.getX() >> 4, ncz = offset.getZ() >> 4;
return cx != ncx || cz != ncz;
}

@NotNull
private WeakReference<TileEntity> computeNeighbor(EnumFacing facing) {
TileEntity te = super.getNeighbor(facing);
Expand Down
Loading