diff options
author | Jakub <53441451+kuba6000@users.noreply.github.com> | 2022-08-29 16:04:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-29 16:04:28 +0200 |
commit | 7d1f51a8937e0a86486267437d444696e81e8aa0 (patch) | |
tree | a5b145e7271998f7b4b968a2212ed487e54a92b5 /src/main/java/gtPlusPlus/api/objects/minecraft/ThreadPooCollector.java | |
parent | 5267969156d30b4bb5f4cb2279ebb49db6bd40e2 (diff) | |
download | GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.gz GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.tar.bz2 GT5-Unofficial-7d1f51a8937e0a86486267437d444696e81e8aa0.zip |
Buildscript + Spotless (#318)
* Convert AES.java to readable class
* Buildscript
* Spotless
Diffstat (limited to 'src/main/java/gtPlusPlus/api/objects/minecraft/ThreadPooCollector.java')
-rw-r--r-- | src/main/java/gtPlusPlus/api/objects/minecraft/ThreadPooCollector.java | 174 |
1 files changed, 85 insertions, 89 deletions
diff --git a/src/main/java/gtPlusPlus/api/objects/minecraft/ThreadPooCollector.java b/src/main/java/gtPlusPlus/api/objects/minecraft/ThreadPooCollector.java index 0ff6e112ac..b40696747b 100644 --- a/src/main/java/gtPlusPlus/api/objects/minecraft/ThreadPooCollector.java +++ b/src/main/java/gtPlusPlus/api/objects/minecraft/ThreadPooCollector.java @@ -1,14 +1,13 @@ package gtPlusPlus.api.objects.minecraft; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; - import gtPlusPlus.GTplusplus; import gtPlusPlus.GTplusplus.INIT_PHASE; import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.tileentities.machines.TileEntityPooCollector; import gtPlusPlus.core.util.Utils; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; @@ -16,96 +15,93 @@ import net.minecraft.world.chunk.Chunk; public class ThreadPooCollector extends Thread { - public boolean canRun = true; + public boolean canRun = true; public boolean isRunning = false; - + private static final long INIT_TIME; private static long internalTickCounter = 0; - private static final ThreadPooCollector mThread; - private static final HashMap<String, Pair<BlockPos, TileEntityPooCollector>> mPooCollectors = new LinkedHashMap<String, Pair<BlockPos, TileEntityPooCollector>>(); - - - static { - mThread = new ThreadPooCollector(); - INIT_TIME = (System.currentTimeMillis()); - } - - public ThreadPooCollector() { + private static final ThreadPooCollector mThread; + private static final HashMap<String, Pair<BlockPos, TileEntityPooCollector>> mPooCollectors = + new LinkedHashMap<String, Pair<BlockPos, TileEntityPooCollector>>(); + + static { + mThread = new ThreadPooCollector(); + INIT_TIME = (System.currentTimeMillis()); + } + + public ThreadPooCollector() { setName("gtpp.handler.poop"); start(); - } - - public static ThreadPooCollector getInstance() { - return mThread; - } - - public static void addTask(TileEntityPooCollector aTile) { - BlockPos aTempPos = new BlockPos(aTile); - mPooCollectors.put(aTempPos.getUniqueIdentifier(), new Pair<BlockPos, TileEntityPooCollector>(aTempPos, aTile)); - } - - public static void stopThread() { - mThread.canRun = false; - } - - - @Override - public void run() { - - if (!isRunning) { - isRunning = true; - } - else { - return; - } + } + + public static ThreadPooCollector getInstance() { + return mThread; + } + + public static void addTask(TileEntityPooCollector aTile) { + BlockPos aTempPos = new BlockPos(aTile); + mPooCollectors.put(aTempPos.getUniqueIdentifier(), new Pair<BlockPos, TileEntityPooCollector>(aTempPos, aTile)); + } + + public static void stopThread() { + mThread.canRun = false; + } + + @Override + public void run() { + + if (!isRunning) { + isRunning = true; + } else { + return; + } - while (canRun) { - if (mPooCollectors.isEmpty() || GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED) { - continue; - } else { - internalTickCounter = Utils.getTicksFromSeconds( - Utils.getSecondsFromMillis(Utils.getMillisSince(INIT_TIME, System.currentTimeMillis()))); - if (internalTickCounter % 100 == 0) { - for (Pair<BlockPos, TileEntityPooCollector> pair : mPooCollectors.values()) { - if (pair != null) { - BlockPos p = pair.getKey(); - if (p != null) { - if (p.world != null) { - World w = p.world; - if (w == null) { - continue; - } - Chunk c = w.getChunkFromBlockCoords(p.xPos, p.zPos); - if (c != null) { - if (c.isChunkLoaded) { - int startX = p.xPos - 2; - int startY = p.yPos; - int startZ = p.zPos - 2; - int endX = p.xPos + 3; - int endY = p.yPos + 5; - int endZ = p.zPos + 3; - AxisAlignedBB box = AxisAlignedBB.getBoundingBox(startX, startY, startZ, - endX, endY, endZ); - if (box != null) { - @SuppressWarnings("unchecked") - List<EntityAnimal> animals = w.getEntitiesWithinAABB(EntityAnimal.class, box); - if (animals != null && !animals.isEmpty()) { - pair.getValue().onPostTick(animals); - } - } else { - continue; - } - } - } - } - } - } - } - } - } - } - } - - + while (canRun) { + if (mPooCollectors.isEmpty() || GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED) { + continue; + } else { + internalTickCounter = Utils.getTicksFromSeconds( + Utils.getSecondsFromMillis(Utils.getMillisSince(INIT_TIME, System.currentTimeMillis()))); + if (internalTickCounter % 100 == 0) { + for (Pair<BlockPos, TileEntityPooCollector> pair : mPooCollectors.values()) { + if (pair != null) { + BlockPos p = pair.getKey(); + if (p != null) { + if (p.world != null) { + World w = p.world; + if (w == null) { + continue; + } + Chunk c = w.getChunkFromBlockCoords(p.xPos, p.zPos); + if (c != null) { + if (c.isChunkLoaded) { + int startX = p.xPos - 2; + int startY = p.yPos; + int startZ = p.zPos - 2; + int endX = p.xPos + 3; + int endY = p.yPos + 5; + int endZ = p.zPos + 3; + AxisAlignedBB box = AxisAlignedBB.getBoundingBox( + startX, startY, startZ, endX, endY, endZ); + if (box != null) { + @SuppressWarnings("unchecked") + List<EntityAnimal> animals = + w.getEntitiesWithinAABB(EntityAnimal.class, box); + if (animals != null && !animals.isEmpty()) { + pair.getValue().onPostTick(animals); + } + } else { + continue; + } + } + } + } + } + } + } + } + } + } + } } |