diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/AbstractWorldGenStep.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/AbstractWorldGenStep.java index 7915596ed..dad094c37 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/AbstractWorldGenStep.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/step/AbstractWorldGenStep.java @@ -27,26 +27,26 @@ public abstract class AbstractWorldGenStep /** @return the list of chunks that have an earlier status and can be generated */ - protected ArrayList getChunksToGenerate(List chunkWrappers) + protected ArrayList getChunkWrappersToGenerate(List chunkWrappers) { - ArrayList chunksToGenerate = new ArrayList<>(); + ArrayList chunkWrappersToGenerate = new ArrayList<>(chunkWrappers.size()); for (ChunkWrapper chunkWrapper : chunkWrappers) { ChunkAccess chunk = chunkWrapper.getChunk(); if (chunkWrapper.getStatus().isOrAfter(this.getChunkStatus())) { - // this chunk has already generated this step + // this chunk has already been generated up to this step continue; } else if (chunk instanceof ProtoChunk) { chunkWrapper.trySetStatus(this.getChunkStatus()); - chunksToGenerate.add(chunk); + chunkWrappersToGenerate.add(chunkWrapper); } } - return chunksToGenerate; + return chunkWrappersToGenerate; } 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 ed185b4a8..17d05ad84 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 @@ -67,9 +67,12 @@ public final class StepBiomes extends AbstractWorldGenStep ThreadWorldGenParams tParams, DhLitWorldGenRegion worldGenRegion, ArrayGridList chunkWrappers) { - ArrayList chunksToDo = this.getChunksToGenerate(chunkWrappers); - for (ChunkAccess chunk : chunksToDo) + ArrayList chunksToDo = this.getChunkWrappersToGenerate(chunkWrappers); + for (ChunkWrapper chunkWrapper : chunksToDo) { + ChunkAccess chunk = chunkWrapper.getChunk(); + + #if MC_VER < MC_1_18_2 this.environment.params.generator.createBiomes(this.environment.params.biomes, chunk); #elif MC_VER < MC_1_19_2 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 b9920546d..fecc60e9e 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 @@ -37,6 +37,7 @@ import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.status.ChunkStatus; #endif +import java.util.ArrayList; import java.util.ConcurrentModificationException; @@ -70,18 +71,10 @@ public final class StepFeatures extends AbstractWorldGenStep ThreadWorldGenParams tParams, DhLitWorldGenRegion worldGenRegion, ArrayGridList chunkWrappers) { - for (ChunkWrapper chunkWrapper : chunkWrappers) + ArrayList chunksToDo = this.getChunkWrappersToGenerate(chunkWrappers); + for (ChunkWrapper chunkWrapper : chunksToDo) { ChunkAccess chunk = chunkWrapper.getChunk(); - if (chunkWrapper.getStatus().isOrAfter(STATUS)) - { - // this chunk has already generated this step - continue; - } - else if (chunk instanceof ProtoChunk) - { - chunkWrapper.trySetStatus(STATUS); - } try 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 4994ea365..d421543a2 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 @@ -68,21 +68,11 @@ public final class StepNoise extends AbstractWorldGenStep ThreadWorldGenParams tParams, DhLitWorldGenRegion worldGenRegion, ArrayGridList chunkWrappers) { - ArrayList chunksToDo = new ArrayList<>(); - - for (ChunkWrapper chunkWrapper : chunkWrappers) + ArrayList chunksToDo = this.getChunkWrappersToGenerate(chunkWrappers); + for (ChunkWrapper chunkWrapper : chunksToDo) { ChunkAccess chunk = chunkWrapper.getChunk(); - if (chunkWrapper.getStatus().isOrAfter(STATUS)) - { - continue; - } - chunkWrapper.trySetStatus(STATUS); - chunksToDo.add(chunk); - } - - for (ChunkAccess chunk : chunksToDo) - { + #if MC_VER < MC_1_17_1 this.environment.params.generator.fillFromNoise(worldGenRegion, tParams.structFeat, chunk); #elif MC_VER < MC_1_18_2 @@ -114,7 +104,6 @@ public final class StepNoise extends AbstractWorldGenStep tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk)); #endif - UncheckedInterruptedException.throwIfInterrupted(); } } 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 e743027ac..a96965c48 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 @@ -65,26 +65,10 @@ public final class StepStructureReference extends AbstractWorldGenStep ThreadWorldGenParams tParams, DhLitWorldGenRegion worldGenRegion, ArrayGridList chunkWrappers) { - ArrayList chunksToDo = new ArrayList(); - - for (ChunkWrapper chunkWrapper : chunkWrappers) + ArrayList chunksToDo = this.getChunkWrappersToGenerate(chunkWrappers); + for (ChunkWrapper chunkWrapper : chunksToDo) { ChunkAccess chunk = chunkWrapper.getChunk(); - if (chunkWrapper.getStatus().isOrAfter(STATUS)) - { - // this chunk has already generated this step - continue; - } - else if (chunk instanceof ProtoChunk) - { - chunkWrapper.trySetStatus(STATUS); - chunksToDo.add(chunk); - } - } - - for (ChunkAccess chunk : chunksToDo) - { - // System.out.println("StepStructureReference: "+chunk.getPos()); this.environment.params.generator.createReferences(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk); } } 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 c9df513ad..d94318267 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 @@ -69,71 +69,75 @@ public final class StepStructureStart extends AbstractWorldGenStep ThreadWorldGenParams tParams, DhLitWorldGenRegion worldGenRegion, ArrayGridList chunkWrappers) { - ArrayList chunksToDo = this.getChunksToGenerate(chunkWrappers); + ArrayList chunksToDo = this.getChunkWrappersToGenerate(chunkWrappers); #if MC_VER < MC_1_19_2 - if (this.environment.params.worldGenSettings.generateFeatures()) - { + if (!this.environment.params.worldGenSettings.generateFeatures()) #elif MC_VER < MC_1_19_4 - if (this.environment.params.worldGenSettings.generateStructures()) - { + if (!this.environment.params.worldGenSettings.generateStructures()) #else - if (this.environment.params.worldOptions.generateStructures()) - { + if (!this.environment.params.worldOptions.generateStructures()) #endif - for (ChunkAccess chunk : chunksToDo) + { + return; + } + + + + for (ChunkWrapper chunkWrapper : chunksToDo) + { + ChunkAccess chunk = chunkWrapper.getChunk(); + + // hopefully this shouldn't cause any performance issues (this step is generally quite quick so hopefully it should be fine) + // and should prevent some concurrency issues + STRUCTURE_PLACEMENT_LOCK.lock(); + + #if MC_VER < MC_1_19_2 + this.environment.params.generator.createStructures(this.environment.params.registry, tParams.structFeat, chunk, this.environment.params.structures, + this.environment.params.worldSeed); + #elif MC_VER < MC_1_19_4 + this.environment.params.generator.createStructures(this.environment.params.registry, this.environment.params.randomState, tParams.structFeat, chunk, this.environment.params.structures, + this.environment.params.worldSeed); + #elif MC_VER <= MC_1_21_3 + this.environment.params.generator.createStructures(this.environment.params.registry, + this.environment.params.level.getChunkSource().getGeneratorState(), + tParams.structFeat, chunk, this.environment.params.structures); + #else + this.environment.params.generator.createStructures(this.environment.params.registry, + this.environment.params.level.getChunkSource().getGeneratorState(), + tParams.structFeat, chunk, this.environment.params.structures, + this.environment.params.level.dimension()); + #endif + + #if MC_VER >= MC_1_18_2 + try { - // hopefully this shouldn't cause any performance issues (this step is generally quite quick so hopefully it should be fine) - // and should prevent some concurrency issues - STRUCTURE_PLACEMENT_LOCK.lock(); + tParams.structCheck.onStructureLoad(chunk.getPos(), chunk.getAllStarts()); + } + catch (ArrayIndexOutOfBoundsException firstEx) + { + // There's a rare issue with StructStart where it throws ArrayIndexOutOfBounds + // This means the structFeat is corrupted (For some reason) and I need to reset it. + // TODO: Figure out in the future why this happens even though I am using new structFeat - OLD - #if MC_VER < MC_1_19_2 - this.environment.params.generator.createStructures(this.environment.params.registry, tParams.structFeat, chunk, this.environment.params.structures, - this.environment.params.worldSeed); - #elif MC_VER < MC_1_19_4 - this.environment.params.generator.createStructures(this.environment.params.registry, this.environment.params.randomState, tParams.structFeat, chunk, this.environment.params.structures, - this.environment.params.worldSeed); - #elif MC_VER <= MC_1_21_3 - this.environment.params.generator.createStructures(this.environment.params.registry, - this.environment.params.level.getChunkSource().getGeneratorState(), - tParams.structFeat, chunk, this.environment.params.structures); - #else - this.environment.params.generator.createStructures(this.environment.params.registry, - this.environment.params.level.getChunkSource().getGeneratorState(), - tParams.structFeat, chunk, this.environment.params.structures, - this.environment.params.level.dimension()); - #endif + // reset the structureStart + tParams.recreateStructureCheck(); - #if MC_VER >= MC_1_18_2 try { + // try running the structure logic again tParams.structCheck.onStructureLoad(chunk.getPos(), chunk.getAllStarts()); } - catch (ArrayIndexOutOfBoundsException firstEx) + catch (ArrayIndexOutOfBoundsException secondEx) { - // There's a rare issue with StructStart where it throws ArrayIndexOutOfBounds - // This means the structFeat is corrupted (For some reason) and I need to reset it. - // TODO: Figure out in the future why this happens even though I am using new structFeat - OLD - - // reset the structureStart - tParams.recreateStructureCheck(); - - try - { - // try running the structure logic again - tParams.structCheck.onStructureLoad(chunk.getPos(), chunk.getAllStarts()); - } - catch (ArrayIndexOutOfBoundsException secondEx) - { - // the structure logic failed again, log it and move on - LOGGER.error("Unable to create structure starts for " + chunk.getPos() + ". This is an error with MC's world generation. Ignoring and continuing generation. Error: " + secondEx.getMessage()); // don't log the full stack trace since it is long and will generally end up in MC's code - } + // the structure logic failed again, log it and move on + LOGGER.error("Unable to create structure starts for " + chunk.getPos() + ". This is an error with MC's world generation. Ignoring and continuing generation. Error: " + secondEx.getMessage()); // don't log the full stack trace since it is long and will generally end up in MC's code } - - #endif - - STRUCTURE_PLACEMENT_LOCK.unlock(); } + + #endif + + STRUCTURE_PLACEMENT_LOCK.unlock(); } } 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 8a2c0ab4e..f56521085 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,34 +65,21 @@ public final class StepSurface extends AbstractWorldGenStep ThreadWorldGenParams tParams, DhLitWorldGenRegion worldGenRegion, ArrayGridList chunkWrappers) { - ArrayList chunksToDo = new ArrayList<>(); - - for (ChunkWrapper chunkWrapper : chunkWrappers) + ArrayList chunksToDo = this.getChunkWrappersToGenerate(chunkWrappers); + for (ChunkWrapper chunkWrapper : chunksToDo) { ChunkAccess chunk = chunkWrapper.getChunk(); - if (chunkWrapper.getStatus().isOrAfter(STATUS)) - { - // this chunk has already generated this step - continue; - } - else if (chunk instanceof ProtoChunk) - { - chunkWrapper.trySetStatus(STATUS); - chunksToDo.add(chunk); - } - } - - for (ChunkAccess chunk : chunksToDo) - { - // System.out.println("StepSurface: "+chunk.getPos()); + #if MC_VER < MC_1_18_2 - environment.params.generator.buildSurfaceAndBedrock(worldGenRegion, chunk); + this.environment.params.generator.buildSurfaceAndBedrock(worldGenRegion, chunk); #elif MC_VER < MC_1_19_2 - environment.params.generator.buildSurface(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk); + this.environment.params.generator.buildSurface(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk); #else - environment.params.generator.buildSurface(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), environment.params.randomState, chunk); + this.environment.params.generator.buildSurface(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), this.environment.params.randomState, chunk); #endif } } + + } \ No newline at end of file