aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech
diff options
context:
space:
mode:
authorbartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>2020-04-14 02:48:53 +0200
committerbartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>2020-04-14 02:48:53 +0200
commit72f84737e2ffee28590d35b1b3be2b656afd4fc7 (patch)
treeaece23041754ad33abdc7cf51d4236baec71596c /src/main/java/gregtech
parent3178edd36a563bffaaa0fab2c48640464c063475 (diff)
downloadGT5-Unofficial-72f84737e2ffee28590d35b1b3be2b656afd4fc7.tar.gz
GT5-Unofficial-72f84737e2ffee28590d35b1b3be2b656afd4fc7.tar.bz2
GT5-Unofficial-72f84737e2ffee28590d35b1b3be2b656afd4fc7.zip
Made use of Thread.wait()
+ shortened "causeMachineUpdate" method Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>
Diffstat (limited to 'src/main/java/gregtech')
-rw-r--r--src/main/java/gregtech/api/GregTech_API.java9
-rw-r--r--src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java15
2 files changed, 18 insertions, 6 deletions
diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java
index c7d02c7bed..68d8d6aaa8 100644
--- a/src/main/java/gregtech/api/GregTech_API.java
+++ b/src/main/java/gregtech/api/GregTech_API.java
@@ -389,12 +389,11 @@ public class GregTech_API {
* @param aZ is the Z-Coord of the update causing Block
*/
public static boolean causeMachineUpdate(World aWorld, int aX, int aY, int aZ) {
- if (!aWorld.isRemote && !GT_Runnable_MachineBlockUpdate.getINSTANCETHREAD().isAlive()) {
- GT_Runnable_MachineBlockUpdate.setMachineUpdateValues(aWorld, aX, aY, aZ);
- GT_Runnable_MachineBlockUpdate.getINSTANCETHREAD().start();
- return true;
- } else if (!aWorld.isRemote && !GT_Runnable_MachineBlockUpdate.isAllowedToRun()){
+ Thread updateThread = GT_Runnable_MachineBlockUpdate.getINSTANCETHREAD();
+ if (!aWorld.isRemote) {
GT_Runnable_MachineBlockUpdate.setMachineUpdateValues(aWorld, aX, aY, aZ);
+ if (!updateThread.isAlive())
+ updateThread.start();
return true;
}
return false;
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 3bac8866c3..cefbb0bc8d 100644
--- a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
+++ b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
@@ -68,6 +68,10 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
GT_Runnable_MachineBlockUpdate.setmWorld(aWorld);
GT_Runnable_MachineBlockUpdate.resetVisited();
GT_Runnable_MachineBlockUpdate.setAllowedToRun(true);
+ synchronized (GT_Runnable_MachineBlockUpdate.INSTANCETHREAD) {
+ if (GT_Runnable_MachineBlockUpdate.INSTANCETHREAD.getState() == Thread.State.WAITING)
+ GT_Runnable_MachineBlockUpdate.INSTANCETHREAD.notify();
+ }
}
/**
@@ -161,8 +165,17 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
//DO NOT USE OPTIONALS HERE!
synchronized (toUpdate) {
Coordinates coordinates = toUpdate.poll();
- if (coordinates != null)
+ if (coordinates != null) {
coordinates.update();
+ } else {
+ synchronized(INSTANCETHREAD) {
+ try {
+ INSTANCETHREAD.wait();
+ } catch (InterruptedException ignored) {
+ return;
+ }
+ }
+ }
}
}
}