From c1ed040c6f442a49e04dda09cce1d5731c81e676 Mon Sep 17 00:00:00 2001 From: tom lee Date: Sat, 12 Feb 2022 22:50:08 +0800 Subject: [PATCH] Rollback some unneeded backport. And make it compile --- .../BatchGenerationEnvironment.java | 19 ++----- .../worldGeneration/GenerationEvent.java | 7 +-- .../step/StepStructureReference.java | 51 ++++++++++++++----- core | 2 +- 4 files changed, 44 insertions(+), 35 deletions(-) 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 b433668e8..af0855844 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(this); + public final StepStructureReference stepStructureReference = new StepStructureReference(); public final StepBiomes stepBiomes = new StepBiomes(this); public final StepNoise stepNoise = new StepNoise(this); public final StepSurface stepSurface = new StepSurface(this); @@ -212,13 +212,6 @@ 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); @@ -419,21 +412,17 @@ 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, wrappedChunk, + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), new LodBuilderConfig(DistanceGenerationMode.FULL), true, e.genAllDetails); } else if (target.getStatus() == ChunkStatus.EMPTY && generationMode == DistanceGenerationMode.NONE) { - params.lodBuilder.generateLodNodeFromChunk(params.lodDim, wrappedChunk, + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), LodBuilderConfig.getFillVoidConfig(), true, e.genAllDetails); } else { - params.lodBuilder.generateLodNodeFromChunk(params.lodDim, wrappedChunk, + params.lodBuilder.generateLodNodeFromChunk(params.lodDim, new ChunkWrapper(target, region), 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 ff93c3eae..e70fb1a3e 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,12 +42,7 @@ public final class GenerationEvent { this.genAllDetails = genAllDetails; future = generationGroup.executors.submit(() -> { - BatchGenerationEnvironment.isDistantGeneratorThread.set(true); - try { - generationGroup.generateLodFromList(this); - } finally { - BatchGenerationEnvironment.isDistantGeneratorThread.remove(); - } + generationGroup.generateLodFromList(this); }); } 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 321b42361..6c7696e3a 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,20 +20,45 @@ import net.minecraft.world.level.chunk.ProtoChunk; import net.minecraft.world.level.levelgen.structure.StructureStart; public final class StepStructureReference { - /** - * - */ - private final BatchGenerationEnvironment envionment; - - /** - * @param worldGenerationEnvironment - */ - public StepStructureReference(BatchGenerationEnvironment worldGenerationEnvironment) { - envionment = worldGenerationEnvironment; - } - public final ChunkStatus STATUS = ChunkStatus.STRUCTURE_REFERENCES; + 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); + } + } + } + } + } + public void generateGroup(ThreadedParameters tParams, WorldGenRegion worldGenRegion, List chunks) { ArrayList chunksToDo = new ArrayList(); @@ -47,7 +72,7 @@ public final class StepStructureReference { for (ChunkAccess chunk : chunksToDo) { // System.out.println("StepStructureReference: "+chunk.getPos()); - envionment.params.generator.createReferences(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk); + createReferences(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk); } } } \ No newline at end of file diff --git a/core b/core index fbbccf473..ae752c6f6 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit fbbccf473937a5f2344513012758b2239ce9a7e3 +Subproject commit ae752c6f630ba844736074e84e97722a450d29f8