aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java22
-rw-r--r--src/main/java/gregtech/common/GT_Proxy.java13
2 files changed, 16 insertions, 19 deletions
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 6564cf316a..3ce1daf9b2 100644
--- a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
+++ b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
@@ -1,11 +1,9 @@
package gregtech.api.threads;
-
-import cpw.mods.fml.common.eventhandler.SubscribeEvent;
-import cpw.mods.fml.common.gameevent.TickEvent;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable;
+import gregtech.common.GT_Proxy;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
@@ -18,7 +16,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.ReentrantLock;
public class GT_Runnable_MachineBlockUpdate implements Runnable {
// used by runner thread
@@ -27,9 +24,6 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
private final Set<ChunkCoordinates> visited = new HashSet<>(80);
private final Queue<ChunkCoordinates> tQueue = new LinkedList<>();
- // Locking
- private static ReentrantLock lock = new ReentrantLock();
-
// Threading
private static final ThreadFactory THREAD_FACTORY = r -> {
Thread thread = new Thread(r);
@@ -47,16 +41,6 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
}
- @SubscribeEvent
- public void onServerTick(TickEvent.ServerTickEvent aEvent) {
- // Using onServerTick because there's race conditions in updateTrackedEntities() which is called AFTER the END phase of onWorldTick
- if (aEvent.phase == TickEvent.Phase.START) {
- lock.lock();
- } else {
- lock.unlock();
- }
- }
-
public static boolean isEnabled() {
return isEnabled;
}
@@ -123,12 +107,12 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
// 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();
+ GT_Proxy.TICK_LOCK.lock();
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();
+ GT_Proxy.TICK_LOCK.unlock();
}
// See if the block itself needs an update
diff --git a/src/main/java/gregtech/common/GT_Proxy.java b/src/main/java/gregtech/common/GT_Proxy.java
index c94ad9a33d..181dc9fe2b 100644
--- a/src/main/java/gregtech/common/GT_Proxy.java
+++ b/src/main/java/gregtech/common/GT_Proxy.java
@@ -116,6 +116,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
+import java.util.concurrent.locks.ReentrantLock;
import static gregtech.api.enums.GT_Values.debugEntityCramming;
@@ -256,6 +257,10 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
public static Map<String, Integer> oreDictBurnTimes = new HashMap<>();
+ // Locking
+ public static ReentrantLock TICK_LOCK = new ReentrantLock();
+
+
static {
oreDictBurnTimes.put("dustTinyWood", 11);
oreDictBurnTimes.put("dustTinySodium", 44);
@@ -1324,6 +1329,14 @@ public abstract class GT_Proxy implements IGT_Mod, IGuiHandler, IFuelHandler {
@SubscribeEvent
public void onServerTickEvent(TickEvent.ServerTickEvent aEvent) {
+ if (aEvent.side.isServer()) {
+ if (aEvent.phase == TickEvent.Phase.START) {
+ TICK_LOCK.lock();
+ } else {
+ TICK_LOCK.unlock();
+ }
+ }
+
}
@SubscribeEvent