diff --git a/src/main/java/com/seibel/lod/api/lod/ClientApi.java b/src/main/java/com/seibel/lod/api/lod/ClientApi.java index 8a554893b..cd170ef75 100644 --- a/src/main/java/com/seibel/lod/api/lod/ClientApi.java +++ b/src/main/java/com/seibel/lod/api/lod/ClientApi.java @@ -144,6 +144,7 @@ public class ClientApi configOverrideReminderPrinted = true; } +// CONFIG.client().worldGenerator().setDistanceGenerationMode(DistanceGenerationMode.SURFACE); CONFIG.client().advanced().debugging().setDebugKeybindingsEnabled(true); diff --git a/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodGenWorker.java b/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodGenWorker.java index 7c5aa90e6..934777747 100644 --- a/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodGenWorker.java +++ b/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodGenWorker.java @@ -35,22 +35,19 @@ import com.seibel.lod.core.wrapperAdapters.config.ILodConfigWrapperSingleton; import com.seibel.lod.core.wrapperAdapters.world.IWorldWrapper; import com.seibel.lod.core.wrapperAdapters.worldGeneration.AbstractWorldGeneratorWrapper; -import net.minecraftforge.common.WorldWorkerManager.IWorker; - /** * This is used to generate a LodChunk at a given ChunkPos. * * @author James Seibel - * @version 11-13-2021 + * @version 11-20-2021 */ -public class LodGenWorker implements IWorker // TODO is there a way to have this fabric/forge independent? +public class LodGenWorker { private static final ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class); private static final IWrapperFactory FACTORY = SingletonHandler.get(IWrapperFactory.class); public static ExecutorService genThreads = Executors.newFixedThreadPool(CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads(), new ThreadFactoryBuilder().setNameFormat("Gen-Worker-Thread-%d").build()); - private boolean threadStarted = false; private final LodChunkGenThread thread; @@ -79,41 +76,28 @@ public class LodGenWorker implements IWorker // TODO is there a way to have this newLodDimension, serverWorld); } - @Override - public boolean doWork() + public void queueWork() { - if (!threadStarted) + if (CONFIG.client().worldGenerator().getDistanceGenerationMode() == DistanceGenerationMode.FULL) { - if (CONFIG.client().worldGenerator().getDistanceGenerationMode() == DistanceGenerationMode.FULL) - { - // if we are using SERVER generation that has to be done - // synchronously to prevent crashing and harmful - // interactions with the normal world generator - thread.run(); - } - else - { - // Every other method can - // be done asynchronously - Thread newThread = new Thread(thread); - newThread.setPriority(5); - genThreads.execute(newThread); - } - - threadStarted = true; - - // useful for debugging -// ClientProxy.LOGGER.info(thread.lodDim.getNumberOfLods()); -// ClientProxy.LOGGER.info(genThreads.toString()); + // if we are using FULL generation there is no reason + // to queue up a bunch of generation requests, + // because MC's internal server (as of 1.16.5) only + // responds with a single thread. And we don't + // want to cause more lag then necessary or queue up + // requests that may end up being unneeded. + thread.run(); + } + else + { + // Every other method can + // be done asynchronously + genThreads.execute(thread); } - return false; - } - - @Override - public boolean hasWork() - { - return !threadStarted; + // useful for debugging +// ClientProxy.LOGGER.info(thread.lodDim.getNumberOfLods()); +// ClientProxy.LOGGER.info(genThreads.toString()); } diff --git a/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java b/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java index 369b1dc78..a6ff68876 100644 --- a/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java +++ b/src/main/java/com/seibel/lod/core/builders/worldGeneration/LodWorldGenerator.java @@ -41,8 +41,6 @@ import com.seibel.lod.core.wrapperAdapters.config.ILodConfigWrapperSingleton; import com.seibel.lod.core.wrapperAdapters.minecraft.IMinecraftWrapper; import com.seibel.lod.core.wrapperAdapters.world.IWorldWrapper; -import net.minecraftforge.common.WorldWorkerManager; - /** * A singleton that handles all long distance LOD world generation. * @author Leonardo Amato @@ -56,7 +54,7 @@ public class LodWorldGenerator private static final IWrapperFactory WRAPPER_FACTORY = SingletonHandler.get(IWrapperFactory.class); - /** This holds the thread used to generate new LODs off the main thread. */ + /** This holds the thread used to create LOD generation requests off the main thread. */ private final ExecutorService mainGenThread = Executors.newSingleThreadExecutor(new LodThreadFactory(this.getClass().getSimpleName() + " world generator")); /** we only want to queue up one generator thread at a time */ @@ -162,7 +160,7 @@ public class LodWorldGenerator positionsWaitingToBeGenerated.add(chunkPos); numberOfChunksWaitingToGenerate.addAndGet(1); LodGenWorker genWorker = new LodGenWorker(chunkPos, DetailDistanceUtil.getDistanceGenerationMode(detailLevel), lodBuilder, lodDim, serverWorld); - WorldWorkerManager.addWorker(genWorker); + genWorker.queueWork(); } @@ -188,7 +186,7 @@ public class LodWorldGenerator positionsWaitingToBeGenerated.add(chunkPos); numberOfChunksWaitingToGenerate.addAndGet(1); LodGenWorker genWorker = new LodGenWorker(chunkPos, DetailDistanceUtil.getDistanceGenerationMode(detailLevel), lodBuilder, lodDim, serverWorld); - WorldWorkerManager.addWorker(genWorker); + genWorker.queueWork(); } }