diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetup.java b/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetup.java index 0570ff653..8d7916aef 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetup.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetup.java @@ -33,5 +33,6 @@ public class DependencySetup { SingletonHandler.bind(IVersionConstants.class, VersionConstants.INSTANCE); } SingletonHandler.bind(IWrapperFactory.class, WrapperFactory.INSTANCE); + DependencySetupDoneCheck.isDone = true; } } diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetupDoneCheck.java b/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetupDoneCheck.java new file mode 100644 index 000000000..97b640568 --- /dev/null +++ b/common/src/main/java/com/seibel/lod/common/wrappers/DependencySetupDoneCheck.java @@ -0,0 +1,7 @@ +package com.seibel.lod.common.wrappers; + +public class DependencySetupDoneCheck +{ + public static boolean isDone = false; + +} diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java index af0855844..b433668e8 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java @@ -197,7 +197,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv public final LinkedList events = new LinkedList(); public final GlobalParameters params; public final StepStructureStart stepStructureStart = new StepStructureStart(this); - public final StepStructureReference stepStructureReference = new StepStructureReference(); + public final StepStructureReference stepStructureReference = new StepStructureReference(this); public final StepBiomes stepBiomes = new StepBiomes(this); public final StepNoise stepNoise = new StepNoise(this); public final StepSurface stepSurface = new StepSurface(this); @@ -212,6 +212,13 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv public long lastExceptionTriggerTime = 0; public static final LodThreadFactory threadFactory = new LodThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY); + + public static ThreadLocal isDistantGeneratorThread = new ThreadLocal(); + + public static boolean isCurrentThreadDistantGeneratorThread() { + return (isDistantGeneratorThread.get() != null); + } + public ExecutorService executors = Executors.newFixedThreadPool( CONFIG.client().advanced().threading().getNumberOfWorldGenerationThreads(), threadFactory); @@ -412,17 +419,21 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv int targetIndex = referencedChunks.offsetOf(centreIndex, ox, oy); ChunkAccess target = referencedChunks.get(targetIndex); target.setLightCorrect(true); + ChunkWrapper wrappedChunk = new ChunkWrapper(target, region); + if (!wrappedChunk.isLightCorrect()) { + throw new RuntimeException("The generated chunk somehow has isLightCorrect() returning false"); + } boolean isFull = target.getStatus() == ChunkStatus.FULL || target instanceof LevelChunk; if (isFull) { if (ENABLE_LOAD_EVENT_LOGGING) ClientApi.LOGGER.info("Detected full existing chunk at {}", target.getPos()); - params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, wrappedChunk, new LodBuilderConfig(DistanceGenerationMode.FULL), true, e.genAllDetails); } else if (target.getStatus() == ChunkStatus.EMPTY && generationMode == DistanceGenerationMode.NONE) { - params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, wrappedChunk, LodBuilderConfig.getFillVoidConfig(), true, e.genAllDetails); } else { - params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, wrappedChunk, new LodBuilderConfig(generationMode), true, e.genAllDetails); } lightEngine.retainData(target.getPos(), false); diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java index e70fb1a3e..ff93c3eae 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java @@ -42,7 +42,12 @@ public final class GenerationEvent { this.genAllDetails = genAllDetails; future = generationGroup.executors.submit(() -> { - generationGroup.generateLodFromList(this); + BatchGenerationEnvironment.isDistantGeneratorThread.set(true); + try { + generationGroup.generateLodFromList(this); + } finally { + BatchGenerationEnvironment.isDistantGeneratorThread.remove(); + } }); } diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepStructureReference.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepStructureReference.java index 6c7696e3a..321b42361 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepStructureReference.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepStructureReference.java @@ -20,44 +20,19 @@ import net.minecraft.world.level.chunk.ProtoChunk; import net.minecraft.world.level.levelgen.structure.StructureStart; public final class StepStructureReference { - public final ChunkStatus STATUS = ChunkStatus.STRUCTURE_REFERENCES; + /** + * + */ + private final BatchGenerationEnvironment envionment; - private void createReferences(WorldGenRegion worldGenLevel, StructureFeatureManager structureFeatureManager, - ChunkAccess chunkAccess) { - ChunkPos chunkPos = chunkAccess.getPos(); - int j = chunkPos.x; - int k = chunkPos.z; - int l = chunkPos.getMinBlockX(); - int m = chunkPos.getMinBlockZ(); - - SectionPos sectionPos = SectionPos.of(chunkAccess.getPos(), 0); - - for (int n = j - 8; n <= j + 8; n++) { - for (int o = k - 8; o <= k + 8; o++) { - if (!worldGenLevel.hasChunk(n, o)) - continue; - long p = ChunkPos.asLong(n, o); - for (StructureStart structureStart : worldGenLevel.getChunk(n, o).getAllStarts().values()) { - try { - if (structureStart.isValid() - && structureStart.getBoundingBox().intersects(l, m, l + 15, m + 15)) { - structureFeatureManager.addReferenceForFeature(sectionPos, structureStart.getFeature(), p, - chunkAccess); - } - } catch (Exception exception) { - CrashReport crashReport = CrashReport.forThrowable(exception, "Generating structure reference"); - CrashReportCategory crashReportCategory = crashReport.addCategory("Structure"); - crashReportCategory.setDetail("Id", - () -> Registry.STRUCTURE_FEATURE.getKey(structureStart.getFeature()).toString()); - crashReportCategory.setDetail("Name", () -> structureStart.getFeature().getFeatureName()); - crashReportCategory.setDetail("Class", - () -> structureStart.getFeature().getClass().getCanonicalName()); - throw new ReportedException(crashReport); - } - } - } - } + /** + * @param worldGenerationEnvironment + */ + public StepStructureReference(BatchGenerationEnvironment worldGenerationEnvironment) { + envionment = worldGenerationEnvironment; } + + public final ChunkStatus STATUS = ChunkStatus.STRUCTURE_REFERENCES; public void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, List chunks) { @@ -72,7 +47,7 @@ public final class StepStructureReference { for (ChunkAccess chunk : chunksToDo) { // System.out.println("StepStructureReference: "+chunk.getPos()); - createReferences(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk); + envionment.params.generator.createReferences(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk); } } } \ No newline at end of file diff --git a/core b/core index 50819c30d..fbbccf473 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 50819c30da8e6e706f1d057dda4a81bba4d4e6d1 +Subproject commit fbbccf473937a5f2344513012758b2239ce9a7e3