diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java index 03d976036..8a80b547b 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java @@ -22,7 +22,6 @@ package com.seibel.distanthorizons.common.wrappers.chunk; import com.seibel.distanthorizons.common.wrappers.block.BiomeWrapper; import com.seibel.distanthorizons.common.wrappers.block.BlockStateWrapper; import com.seibel.distanthorizons.common.wrappers.misc.MutableBlockPosWrapper; -import com.seibel.distanthorizons.common.wrappers.worldGeneration.mimicObject.DhLitWorldGenRegion; import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos; @@ -36,8 +35,8 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.ProtoChunk; import net.minecraft.world.level.levelgen.Heightmap; import org.apache.logging.log4j.Logger; @@ -122,7 +121,7 @@ public class ChunkWrapper implements IChunkWrapper this.solidHeightMap = new int[LodUtil.CHUNK_WIDTH][LodUtil.CHUNK_WIDTH]; this.lightBlockingHeightMap = new int[LodUtil.CHUNK_WIDTH][LodUtil.CHUNK_WIDTH]; - this.recalculateDhHeightMaps(); + this.recalculateDhHeightMapsIfNeeded(); } else { @@ -250,8 +249,8 @@ public class ChunkWrapper implements IChunkWrapper } private int getChunkSectionMinHeight(int index) { return (index * 16) + this.getInclusiveMinBuildHeight(); } - - public void recalculateDhHeightMaps() + /** Will only run if the config says the MC heightmaps shouldn't be trusted. */ + public void recalculateDhHeightMapsIfNeeded() { // re-calculate the min/max heights for consistency (during world gen these may be wrong) this.minNonEmptyHeight = Integer.MIN_VALUE; @@ -394,6 +393,20 @@ public class ChunkWrapper implements IChunkWrapper public ChunkAccess getChunk() { return this.chunk; } + public void trySetStatus(ChunkStatus status) { trySetStatus(this.getChunk(), status); } + /** does nothing if the chunk object doesn't support setting it's status */ + public static void trySetStatus(ChunkAccess chunk, ChunkStatus status) + { + if (chunk instanceof ProtoChunk) + { + #if MC_VER < MC_1_21_1 + ((ProtoChunk) chunk).setStatus(STATUS); + #else + ((ProtoChunk) chunk).setPersistedStatus(status); + #endif + } + } + public ChunkStatus getStatus() { return getStatus(this.getChunk()); } public static ChunkStatus getStatus(ChunkAccess chunk) { diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java index 318aabffc..67e44e041 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/BatchGenerationEnvironment.java @@ -378,7 +378,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv // We handle this later, although that handling would need to change if the gen size ever changes. LodUtil.assertTrue(genEvent.size % 2 == 0, "Generation events are expected to be an evan number of chunks wide."); - if (genEvent.targetGenerationStep == EDhApiWorldGenerationStep.LIGHT) // TODO using something other than LIGHT would be good for clarity + if (genEvent.generatorMode == EDhApiDistantGeneratorMode.INTERNAL_SERVER) { return this.generateChunksViaInternalServerAsync(genEvent); } @@ -515,7 +515,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv try { - this.generateDirect(genEvent, chunkWrapperList, borderSize, genEvent.targetGenerationStep, region); + this.generateDirect(genEvent, chunkWrapperList, region); } catch (InterruptedException e) { @@ -669,7 +669,17 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv @Nullable ChunkAccess chunk = ChunkLoader.read(level, chunkPos, chunkData); - if (chunk == null) + if (chunk != null) + { + if (Config.Common.LodBuilding.assumePreExistingChunksAreFinished.get()) + { + // Sometimes the chunk status is wrong + // (this might be an issue with some versions of chunky) + // which can cause issues with some world gen steps re-running and locking up + ChunkWrapper.trySetStatus(chunk, ChunkStatus.FULL); + } + } + else { chunk = CreateEmptyChunk(level, chunkPos); } @@ -761,7 +771,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv ArrayList chunksToLight = new ArrayList<>(chunkWrappersByDhPos.values()); for (IChunkWrapper iChunkWrapper : chunksToLight) { - ((ChunkWrapper) iChunkWrapper).recalculateDhHeightMaps(); + ((ChunkWrapper) iChunkWrapper).recalculateDhHeightMapsIfNeeded(); // pre-generated chunks should have lighting but new ones won't if (!iChunkWrapper.isDhBlockLightingCorrect()) @@ -898,8 +908,8 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv } public void generateDirect( - GenerationEvent genEvent, ArrayGridList chunkWrappersToGenerate, int border, - EDhApiWorldGenerationStep step, DhLitWorldGenRegion region) throws InterruptedException + GenerationEvent genEvent, ArrayGridList chunkWrappersToGenerate, + DhLitWorldGenRegion region) throws InterruptedException { if (Thread.interrupted()) { @@ -919,8 +929,10 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv } }); + EDhApiWorldGenerationStep step = genEvent.targetGenerationStep; if (step == EDhApiWorldGenerationStep.EMPTY) { + // shouldn't normally happen but is here for consistency with the other world gen steps return; } @@ -1016,7 +1028,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv // make sure the height maps are all properly generated // if this isn't done everything else afterward may fail Heightmap.primeHeightmaps(centerChunk.getChunk(), ChunkStatus.FEATURES.heightmapsAfter()); - centerChunk.recalculateDhHeightMaps(); + centerChunk.recalculateDhHeightMapsIfNeeded(); // pre-generated chunks should have lighting but new ones won't if (!centerChunk.isDhBlockLightingCorrect()) @@ -1069,13 +1081,14 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv @Override public CompletableFuture generateChunks( - int minX, int minZ, int genSize, EDhApiWorldGenerationStep targetStep, + int minX, int minZ, int genSize, + EDhApiDistantGeneratorMode generatorMode, EDhApiWorldGenerationStep targetStep, ExecutorService worldGeneratorThreadPool, Consumer resultConsumer) { //System.out.println("GenerationEvent: "+genSize+"@"+minX+","+minZ+" "+targetStep); // TODO: Check event overlap via e.tooClose() - GenerationEvent genEvent = GenerationEvent.startEvent(new DhChunkPos(minX, minZ), genSize, this, targetStep, resultConsumer, worldGeneratorThreadPool); + GenerationEvent genEvent = GenerationEvent.startEvent(new DhChunkPos(minX, minZ), genSize, this, generatorMode, targetStep, resultConsumer, worldGeneratorThreadPool); this.generationEventList.add(genEvent); return genEvent.future; } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GenerationEvent.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GenerationEvent.java index 33900530c..2ad7fb499 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GenerationEvent.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GenerationEvent.java @@ -23,6 +23,7 @@ import java.lang.invoke.MethodHandles; import java.util.concurrent.*; import java.util.function.Consumer; +import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode; import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep; import com.seibel.distanthorizons.core.util.objects.UncheckedInterruptedException; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; @@ -44,6 +45,7 @@ public final class GenerationEvent /** the number of chunks wide this event is */ public final int size; public final EDhApiWorldGenerationStep targetGenerationStep; + public final EDhApiDistantGeneratorMode generatorMode; public EventTimer timer = null; public long inQueueTime; public long timeoutTime = -1; @@ -54,12 +56,13 @@ public final class GenerationEvent public GenerationEvent( DhChunkPos minPos, int size, BatchGenerationEnvironment generationGroup, - EDhApiWorldGenerationStep targetGenerationStep, Consumer resultConsumer) + EDhApiDistantGeneratorMode generatorMode, EDhApiWorldGenerationStep targetGenerationStep, Consumer resultConsumer) { this.inQueueTime = System.nanoTime(); this.id = generationFutureDebugIDs++; this.minPos = minPos; this.size = size; + this.generatorMode = generatorMode; this.targetGenerationStep = targetGenerationStep; this.threadedParam = ThreadedParameters.getOrMake(generationGroup.params); this.resultConsumer = resultConsumer; @@ -69,10 +72,10 @@ public final class GenerationEvent public static GenerationEvent startEvent( DhChunkPos minPos, int size, BatchGenerationEnvironment genEnvironment, - EDhApiWorldGenerationStep target, Consumer resultConsumer, + EDhApiDistantGeneratorMode generatorMode, EDhApiWorldGenerationStep target, Consumer resultConsumer, ExecutorService worldGeneratorThreadPool) { - GenerationEvent generationEvent = new GenerationEvent(minPos, size, genEnvironment, target, resultConsumer); + GenerationEvent generationEvent = new GenerationEvent(minPos, size, genEnvironment, generatorMode, target, resultConsumer); generationEvent.future = CompletableFuture.supplyAsync(() -> { long runStartTime = System.nanoTime(); diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepBiomes.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepBiomes.java index a901a8386..5f0eaa408 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepBiomes.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepBiomes.java @@ -68,12 +68,7 @@ public final class StepBiomes } else if (chunk instanceof ProtoChunk) { - #if MC_VER < MC_1_21_1 - ((ProtoChunk) chunk).setStatus(STATUS); - #else - ((ProtoChunk) chunk).setPersistedStatus(STATUS); - #endif - + chunkWrapper.trySetStatus(STATUS); chunksToDo.add(chunk); } } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepFeatures.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepFeatures.java index 8e5378d27..2b662a0af 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepFeatures.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepFeatures.java @@ -66,11 +66,7 @@ public final class StepFeatures } else if (chunk instanceof ProtoChunk) { - #if MC_VER < MC_1_21_1 - ((ProtoChunk) chunk).setStatus(STATUS); - #else - ((ProtoChunk) chunk).setPersistedStatus(STATUS); - #endif + chunkWrapper.trySetStatus(STATUS); } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepNoise.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepNoise.java index ce6e31c2d..49d8e1350 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepNoise.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepNoise.java @@ -67,12 +67,7 @@ public final class StepNoise { continue; } - - #if MC_VER < MC_1_21_1 - ((ProtoChunk) chunk).setStatus(STATUS); - #else - ((ProtoChunk) chunk).setPersistedStatus(STATUS); - #endif + chunkWrapper.trySetStatus(STATUS); chunksToDo.add(chunk); } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepStructureReference.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepStructureReference.java index f0479e3b3..83c48b7e7 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepStructureReference.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepStructureReference.java @@ -66,12 +66,7 @@ public final class StepStructureReference } else if (chunk instanceof ProtoChunk) { - #if MC_VER < MC_1_21_1 - ((ProtoChunk) chunk).setStatus(STATUS); - #else - ((ProtoChunk) chunk).setPersistedStatus(STATUS); - #endif - chunksToDo.add(chunk); + chunkWrapper.trySetStatus(STATUS); } } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepStructureStart.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepStructureStart.java index d991fefa6..64d4ae4d7 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepStructureStart.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepStructureStart.java @@ -85,12 +85,7 @@ public final class StepStructureStart } else if (chunk instanceof ProtoChunk) { - #if MC_VER < MC_1_21_1 - ((ProtoChunk) chunk).setStatus(STATUS); - #else - ((ProtoChunk) chunk).setPersistedStatus(STATUS); - #endif - chunksToDo.add(chunk); + chunkWrapper.trySetStatus(STATUS); } } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepSurface.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepSurface.java index f557fe124..9cc4f0253 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepSurface.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/StepSurface.java @@ -65,12 +65,7 @@ public final class StepSurface } else if (chunk instanceof ProtoChunk) { - #if MC_VER < MC_1_21_1 - ((ProtoChunk) chunk).setStatus(STATUS); - #else - ((ProtoChunk) chunk).setPersistedStatus(STATUS); - #endif - + chunkWrapper.trySetStatus(STATUS); chunksToDo.add(chunk); } } diff --git a/coreSubProjects b/coreSubProjects index e6ceba63f..3d866c480 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit e6ceba63f71b745d674d8b8d1d25ac2f7fb5bd45 +Subproject commit 3d866c480ff9bfe88b1d712384a5cde62c18fd80