From 6d58f65939261a915761c11ecf01848c2cef451c Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Mon, 18 Jan 2021 18:19:29 -0800 Subject: try/finally --- .../gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java index 09b2801c79..e46d63cdff 100644 --- a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java +++ b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java @@ -117,13 +117,18 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable { try { while (!tQueue.isEmpty()) { final ChunkCoordinates aCoords = tQueue.poll(); + final TileEntity tTileEntity; + final boolean isMachineBlock; // This might load a chunk... which might load a TileEntity... which might get added to `loadedTileEntityList`... which might be in the process // of being iterated over during `UpdateEntities()`... which might cause a ConcurrentModificationException. So, lock that shit. lock.lock(); - final TileEntity tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ); - final boolean isMachineBlock = GregTech_API.isMachineBlock(world.getBlock(aCoords.posX, aCoords.posY, aCoords.posZ), world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ)); - lock.unlock(); + try { + tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ); + isMachineBlock = GregTech_API.isMachineBlock(world.getBlock(aCoords.posX, aCoords.posY, aCoords.posZ), world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ)); + } finally { + lock.unlock(); + } // See if the block itself needs an update if (tTileEntity instanceof IMachineBlockUpdateable) -- cgit