aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/threads
diff options
context:
space:
mode:
authorRaven Szewczyk <git@eigenraven.me>2022-08-27 10:19:57 +0100
committerGitHub <noreply@github.com>2022-08-27 11:19:57 +0200
commit6f31720697bcc351421a4d86ba3bf749375dd12c (patch)
tree3adf8f318f22c892d74cd7c9d30b6dd3f11f11bd /src/main/java/gregtech/api/threads
parentc3eac50decd33ee2be8703dfb2ecf9cdc31c2b67 (diff)
downloadGT5-Unofficial-6f31720697bcc351421a4d86ba3bf749375dd12c.tar.gz
GT5-Unofficial-6f31720697bcc351421a4d86ba3bf749375dd12c.tar.bz2
GT5-Unofficial-6f31720697bcc351421a4d86ba3bf749375dd12c.zip
Update buildscript & apply spotless (#1306)
* Update dependencies * Update buildscript, apply spotless
Diffstat (limited to 'src/main/java/gregtech/api/threads')
-rw-r--r--src/main/java/gregtech/api/threads/GT_Runnable_Cable_Update.java26
-rw-r--r--src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java66
-rw-r--r--src/main/java/gregtech/api/threads/GT_Runnable_Sound.java34
3 files changed, 84 insertions, 42 deletions
diff --git a/src/main/java/gregtech/api/threads/GT_Runnable_Cable_Update.java b/src/main/java/gregtech/api/threads/GT_Runnable_Cable_Update.java
index 7093184533..9ae94d1c80 100644
--- a/src/main/java/gregtech/api/threads/GT_Runnable_Cable_Update.java
+++ b/src/main/java/gregtech/api/threads/GT_Runnable_Cable_Update.java
@@ -30,8 +30,8 @@ public class GT_Runnable_Cable_Update extends GT_Runnable_MachineBlockUpdate {
GT_Proxy.TICK_LOCK.lock();
try {
- //we dont want to go over cables that are in unloaded chunks
- //keeping the lock just to make sure no CME happens
+ // we dont want to go over cables that are in unloaded chunks
+ // keeping the lock just to make sure no CME happens
if (world.blockExists(aCoords.posX, aCoords.posY, aCoords.posZ)) {
tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ);
} else {
@@ -47,23 +47,27 @@ public class GT_Runnable_Cable_Update extends GT_Runnable_MachineBlockUpdate {
// Now see if we should add the nearby blocks to the queue:
// only add blocks the cable is connected to
- if (tTileEntity instanceof BaseMetaPipeEntity &&
- ((BaseMetaPipeEntity) tTileEntity).getMetaTileEntity() instanceof GT_MetaPipeEntity_Cable)
- {
+ if (tTileEntity instanceof BaseMetaPipeEntity
+ && ((BaseMetaPipeEntity) tTileEntity).getMetaTileEntity() instanceof GT_MetaPipeEntity_Cable) {
ChunkCoordinates tCoords;
- for (byte i = 0;i<6;i++) {
- if (((GT_MetaPipeEntity_Cable) ((BaseMetaPipeEntity) tTileEntity).getMetaTileEntity()).isConnectedAtSide(i)) {
+ for (byte i = 0; i < 6; i++) {
+ if (((GT_MetaPipeEntity_Cable) ((BaseMetaPipeEntity) tTileEntity).getMetaTileEntity())
+ .isConnectedAtSide(i)) {
ForgeDirection offset = ForgeDirection.getOrientation(i);
- if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX + offset.offsetX,
- aCoords.posY + offset.offsetY, aCoords.posZ + offset.offsetZ)))
- tQueue.add(tCoords);
+ if (visited.add(
+ tCoords = new ChunkCoordinates(
+ aCoords.posX + offset.offsetX,
+ aCoords.posY + offset.offsetY,
+ aCoords.posZ + offset.offsetZ))) tQueue.add(tCoords);
}
}
}
}
} catch (Exception e) {
GT_Mod.GT_FML_LOGGER.error(
- "Well this update was broken... " + mCoords + ", mWorld={" + world.getProviderName() + " @dimId " + world.provider.dimensionId + "}", e);
+ "Well this update was broken... " + mCoords + ", mWorld={" + world.getProviderName() + " @dimId "
+ + world.provider.dimensionId + "}",
+ e);
}
}
}
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 4b4c01345a..371c3316f3 100644
--- a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
+++ b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java
@@ -4,10 +4,6 @@ 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;
-
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
@@ -16,6 +12,9 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.ChunkCoordinates;
+import net.minecraft.world.World;
public class GT_Runnable_MachineBlockUpdate implements Runnable {
// used by runner thread
@@ -23,7 +22,7 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
protected final World world;
protected final Set<ChunkCoordinates> visited = new HashSet<>(80);
protected final Queue<ChunkCoordinates> tQueue = new LinkedList<>();
-
+
// Threading
private static final ThreadFactory THREAD_FACTORY = r -> {
Thread thread = new Thread(r);
@@ -65,7 +64,8 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
}
public static void initExecutorService() {
- EXECUTOR_SERVICE = Executors.newFixedThreadPool(Math.max(1, (Runtime.getRuntime().availableProcessors() * 2 / 3)), THREAD_FACTORY);
+ EXECUTOR_SERVICE = Executors.newFixedThreadPool(
+ Math.max(1, (Runtime.getRuntime().availableProcessors() * 2 / 3)), THREAD_FACTORY);
}
public static void shutdownExecutorService() {
@@ -77,7 +77,8 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
EXECUTOR_SERVICE.shutdownNow(); // Cancel currently executing tasks
// Wait a while for tasks to respond to being cancelled
if (!EXECUTOR_SERVICE.awaitTermination(60, TimeUnit.SECONDS)) {
- GT_Mod.GT_FML_LOGGER.error("Well this didn't terminated well... GT_Runnable_MachineBlockUpdate.shutdownExecutorService");
+ GT_Mod.GT_FML_LOGGER.error(
+ "Well this didn't terminated well... GT_Runnable_MachineBlockUpdate.shutdownExecutorService");
}
}
} catch (InterruptedException ie) {
@@ -86,11 +87,11 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
EXECUTOR_SERVICE.shutdownNow();
// Preserve interrupt status
Thread.currentThread().interrupt();
- }catch (Exception e){
+ } catch (Exception e) {
GT_Mod.GT_FML_LOGGER.error("Well this didn't terminated well...", e);
// (Re-)Cancel in case
EXECUTOR_SERVICE.shutdownNow();
- }finally {
+ } finally {
GT_Mod.GT_FML_LOGGER.info("Leaving... GT_Runnable_MachineBlockUpdate.shutdownExecutorService");
}
}
@@ -102,17 +103,21 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
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.
+
+ // 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.
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));
+ isMachineBlock = GregTech_API.isMachineBlock(
+ world.getBlock(aCoords.posX, aCoords.posY, aCoords.posZ),
+ world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ));
} finally {
GT_Proxy.TICK_LOCK.unlock();
}
-
+
// See if the block itself needs an update
if (tTileEntity instanceof IMachineBlockUpdateable)
((IMachineBlockUpdateable) tTileEntity).onMachineBlockUpdate();
@@ -121,24 +126,31 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable {
// 1) If we've visited less than 5 blocks, then yes
// 2) If the tile says we should recursively updated (pipes don't, machine blocks do)
// 3) If the block at the coordinates is marked as a machine block
- if (visited.size() < 5
- || (tTileEntity instanceof IMachineBlockUpdateable && ((IMachineBlockUpdateable) tTileEntity).isMachineBlockUpdateRecursive())
- || isMachineBlock)
- {
+ if (visited.size() < 5
+ || (tTileEntity instanceof IMachineBlockUpdateable
+ && ((IMachineBlockUpdateable) tTileEntity).isMachineBlockUpdateRecursive())
+ || isMachineBlock) {
ChunkCoordinates tCoords;
-
- if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX + 1, aCoords.posY, aCoords.posZ))) tQueue.add(tCoords);
- if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX - 1, aCoords.posY, aCoords.posZ))) tQueue.add(tCoords);
- if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY + 1, aCoords.posZ))) tQueue.add(tCoords);
- if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY - 1, aCoords.posZ))) tQueue.add(tCoords);
- if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ + 1))) tQueue.add(tCoords);
- if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ - 1))) tQueue.add(tCoords);
+
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX + 1, aCoords.posY, aCoords.posZ)))
+ tQueue.add(tCoords);
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX - 1, aCoords.posY, aCoords.posZ)))
+ tQueue.add(tCoords);
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY + 1, aCoords.posZ)))
+ tQueue.add(tCoords);
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY - 1, aCoords.posZ)))
+ tQueue.add(tCoords);
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ + 1)))
+ tQueue.add(tCoords);
+ if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ - 1)))
+ tQueue.add(tCoords);
}
}
} catch (Exception e) {
GT_Mod.GT_FML_LOGGER.error(
- "Well this update was broken... " + mCoords + ", mWorld={" + world.getProviderName() + " @dimId " + world.provider.dimensionId + "}", e);
+ "Well this update was broken... " + mCoords + ", mWorld={" + world.getProviderName() + " @dimId "
+ + world.provider.dimensionId + "}",
+ e);
}
}
-
}
diff --git a/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java b/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java
index 441d46ad58..99aa638f87 100644
--- a/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java
+++ b/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java
@@ -11,7 +11,15 @@ public class GT_Runnable_Sound implements Runnable {
private final ResourceLocation mSoundResourceLocation;
private final float mSoundStrength, mSoundModulation;
- public GT_Runnable_Sound(World aWorld, int aX, int aY, int aZ, int aTimeUntilNextSound, ResourceLocation aSoundResourceLocation, float aSoundStrength, float aSoundModulation) {
+ public GT_Runnable_Sound(
+ World aWorld,
+ int aX,
+ int aY,
+ int aZ,
+ int aTimeUntilNextSound,
+ ResourceLocation aSoundResourceLocation,
+ float aSoundStrength,
+ float aSoundModulation) {
mWorld = aWorld;
mX = aX;
mY = aY;
@@ -26,8 +34,24 @@ public class GT_Runnable_Sound implements Runnable {
* @deprecated Use {@link #GT_Runnable_Sound(World, int, int, int, int, ResourceLocation, float, float)}
*/
@Deprecated
- public GT_Runnable_Sound(World aWorld, int aX, int aY, int aZ, int aTimeUntilNextSound, String aSoundName, float aSoundStrength, float aSoundModulation) {
- this(aWorld, aX, aY, aZ, aTimeUntilNextSound, new ResourceLocation(aSoundName), aSoundStrength, aSoundModulation);
+ public GT_Runnable_Sound(
+ World aWorld,
+ int aX,
+ int aY,
+ int aZ,
+ int aTimeUntilNextSound,
+ String aSoundName,
+ float aSoundStrength,
+ float aSoundModulation) {
+ this(
+ aWorld,
+ aX,
+ aY,
+ aZ,
+ aTimeUntilNextSound,
+ new ResourceLocation(aSoundName),
+ aSoundStrength,
+ aSoundModulation);
}
@Override
@@ -38,6 +62,8 @@ public class GT_Runnable_Sound implements Runnable {
return;
mWorld.playSound(mX, mY, mZ, mSoundResourceLocation.toString(), mSoundStrength, mSoundModulation, false);
GT_Utility.sPlayedSoundMap.put(tSound, mTimeUntilNextSound);
- } catch (Throwable e) {/**/}
+ } catch (Throwable e) {
+ /**/
+ }
}
}