Browse Source

World loading should no longer "lock" up

Gregorius Techneticies 3 months ago
parent
commit
ab8561136b
Signed by: Gregorius Techneticies <gregoriustech@gmail.com> GPG Key ID: 1B693EA14F2FD70F

+ 4
- 2
src/main/java/gregapi/GT_API_Proxy.java View File

@@ -28,6 +28,7 @@ import java.util.Iterator;
28 28
 import java.util.List;
29 29
 import java.util.Map;
30 30
 import java.util.Random;
31
+import java.util.concurrent.TimeUnit;
31 32
 
32 33
 import cpw.mods.fml.common.FMLCommonHandler;
33 34
 import cpw.mods.fml.common.FMLLog;
@@ -239,7 +240,8 @@ public abstract class GT_API_Proxy extends Abstract_Proxy implements IGuiHandler
239 240
 	@SuppressWarnings("unchecked")
240 241
 	public void onServerTick(ServerTickEvent aEvent) {
241 242
 		if (aEvent.side.isServer()) {
242
-			//TICK_LOCK.lock();
243
+			// Try acquiring the Lock within 10 Milliseconds. Otherwise fuck anyone who locks it up for too long, or any other faulty reason MC doesn't work.
244
+			try {TICK_LOCK.tryLock(10, TimeUnit.MILLISECONDS);} catch (Throwable e) {e.printStackTrace(ERR);} finally {if (TICK_LOCK.isHeldByCurrentThread()) TICK_LOCK.unlock();}
243 245
 			
244 246
 			// Making sure it is being free'd up in order to prevent exploits or Garbage Collection mishaps.
245 247
 			LAST_BROKEN_TILEENTITY.set(null);
@@ -438,7 +440,7 @@ public abstract class GT_API_Proxy extends Abstract_Proxy implements IGuiHandler
438 440
 					}
439 441
 				}
440 442
 				EntityFoodTracker.tick();
441
-				//TICK_LOCK.unlock();
443
+				if (TICK_LOCK.isHeldByCurrentThread()) TICK_LOCK.unlock();
442 444
 			}
443 445
 		}
444 446
 	}

+ 1
- 1
src/main/java/gregapi/tileentity/ITileEntityMachineBlockUpdateable.java View File

@@ -120,7 +120,7 @@ public interface ITileEntityMachineBlockUpdateable {
120 120
 			
121 121
 			@Override
122 122
 			public void run() {
123
-				try {stepToUpdateMachine(mWorld, mCoords, new HashSetNoNulls<>(F, mCoords));} catch(Throwable e) {/**/}
123
+				try {stepToUpdateMachine(mWorld, mCoords, new HashSetNoNulls<>(F, mCoords));} catch(Throwable e) {/**/} finally {if (TICK_LOCK.isHeldByCurrentThread()) TICK_LOCK.unlock();}
124 124
 			}
125 125
 			
126 126
 			private void stepToUpdateMachine(World aWorld, ChunkCoordinates aCoords, HashSetNoNulls<ChunkCoordinates> aSet) {

Loading…
Cancel
Save