From f318b52280d8f90edd131888e0d0c0ac6ed852c6 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Thu, 27 Nov 2025 22:12:46 -0600 Subject: [PATCH] Fix compiling for older MC versions --- .../worldGeneration/GlobalWorldGenParams.java | 5 +++ .../worldGeneration/ThreadWorldGenParams.java | 2 +- .../ChunkCompoundTagParser.java | 33 ++++++++++++------- .../chunkFileHandling/ChunkFileReader.java | 23 +++++++++++-- .../InternalServerGenerator.java | 13 +++++--- .../worldGeneration/step/StepBiomes.java | 22 ++++++------- .../worldGeneration/step/StepFeatures.java | 2 +- .../worldGeneration/step/StepNoise.java | 16 ++++----- .../step/StepStructureStart.java | 18 +++++----- .../worldGeneration/step/StepSurface.java | 4 +-- .../server/MixinUtilBackgroundThread.java | 9 +++++ 11 files changed, 98 insertions(+), 49 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GlobalWorldGenParams.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GlobalWorldGenParams.java index c640685f6..e1b112ec2 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GlobalWorldGenParams.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/GlobalWorldGenParams.java @@ -33,9 +33,14 @@ import net.minecraft.world.level.chunk.ChunkGenerator; #if MC_VER >= MC_1_18_2 import net.minecraft.world.level.chunk.storage.ChunkScanAccess; #endif + #if MC_VER < MC_1_19_2 import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; +#elif MC_VER < MC_1_19_2 +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; #else +import net.minecraft.world.level.levelgen.RandomState; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager; #endif import net.minecraft.world.level.storage.WorldData; diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/ThreadWorldGenParams.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/ThreadWorldGenParams.java index 2ea22d04e..5c6b20a71 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/ThreadWorldGenParams.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/ThreadWorldGenParams.java @@ -73,7 +73,7 @@ public final class ThreadWorldGenParams this.level = param.level; #if MC_VER < MC_1_18_2 - this.structFeat = new WorldGenStructFeatManager(param.worldGenSettings, this.level); + this.structFeatManager = new WorldGenStructFeatManager(param.worldGenSettings, this.level); #elif MC_VER < MC_1_19_2 this.structCheck = this.createStructureCheck(param); #else diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/chunkFileHandling/ChunkCompoundTagParser.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/chunkFileHandling/ChunkCompoundTagParser.java index 652096195..826992cce 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/chunkFileHandling/ChunkCompoundTagParser.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/chunkFileHandling/ChunkCompoundTagParser.java @@ -20,6 +20,7 @@ package com.seibel.distanthorizons.common.wrappers.worldGeneration.chunkFileHandling; import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; import com.mojang.serialization.Dynamic; import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; @@ -56,6 +57,11 @@ import net.minecraft.world.level.chunk.storage.ChunkSerializer; #else #endif +#if MC_VER < MC_1_21_9 +import net.minecraft.world.level.block.Blocks; +#else +#endif + import net.minecraft.world.level.levelgen.Heightmap; #if MC_VER >= MC_1_18_2 import net.minecraft.world.level.levelgen.blending.BlendingData; @@ -168,7 +174,7 @@ public class ChunkCompoundTagParser { return null; } - #elif MC_VER < MC_1_19_2 + #elif MC_VER < MC_1_20_6 if (chunkType == ChunkStatus.ChunkType.PROTOCHUNK) { return null; @@ -376,7 +382,7 @@ public class ChunkCompoundTagParser Registry biomeRegistry = getBiomeRegistry(level); - #if MC_VER < MC_1_18_2 + #if MC_VER < MC_1_19_2 Codec> biomeCodec; #else Codec>> biomeCodec; @@ -401,12 +407,13 @@ public class ChunkCompoundTagParser biomeTag = CompoundTagUtil.getCompoundTag(tagSection, "biomes"); } - if (biomeTag != null) + if (biomeTag != null + && !biomeTag.isEmpty()) { - #if MC_VER < MC_1_20_6 - biomeContainer = biomeCodec.parse(NbtOps.INSTANCE, biomeTag) - .promotePartial(string -> logBiomeDeserializationWarning(chunkPos, sectionYIndex, (String) string)) - .getOrThrow(false, (message) -> logParsingWarningOnce(message)); + #if MC_VER < MC_1_20_6 + biomeContainer = new PalettedContainer>( + biomeRegistry.asHolderIdMap(), + biomeRegistry.getHolderOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES); #else biomeContainer = biomeCodec.parse(NbtOps.INSTANCE, biomeTag) .promotePartial(string -> logBiomeDeserializationWarning(chunkPos, sectionYIndex, (String) string)) @@ -448,9 +455,11 @@ public class ChunkCompoundTagParser private static Codec> getBlockStateCodec(LevelAccessor level) { - #if MC_VER <= MC_1_18_2 + #if MC_VER < MC_1_18_2 + return null; // unused for older MC versions + #elif MC_VER < MC_1_19_2 return PalettedContainer.codec(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState()); - #elif MC_VER <= MC_1_19_2 + #elif MC_VER <= MC_1_21_8 return PalettedContainer.codecRW(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState()); #else return PalettedContainerFactory.create(level.registryAccess()).blockStatesContainerCodec(); @@ -471,13 +480,15 @@ public class ChunkCompoundTagParser #endif } private static - #if MC_VER < MC_1_18_2 Codec> + #if MC_VER < MC_1_19_2 Codec> #else Codec>> #endif getBiomeCodec(LevelAccessor level, Registry biomeRegistry) { #if MC_VER < MC_1_18_2 - Codec> biomeCodec = PalettedContainer.codec( + return null; // unused for older MC versions + #elif MC_VER < MC_1_19_2 + return PalettedContainer.codec( biomeRegistry, biomeRegistry.byNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomeRegistry.getOrThrow(Biomes.PLAINS)); #elif MC_VER < MC_1_19_2 return PalettedContainer.codec( diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/chunkFileHandling/ChunkFileReader.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/chunkFileHandling/ChunkFileReader.java index e12f64042..c652c3401 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/chunkFileHandling/ChunkFileReader.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/chunkFileHandling/ChunkFileReader.java @@ -11,16 +11,16 @@ import com.seibel.distanthorizons.core.pos.DhChunkPos; import com.seibel.distanthorizons.core.util.ExceptionUtil; import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.ChunkLightStorage; import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModChecker; + import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.chunk.PalettedContainerFactory; import net.minecraft.world.level.chunk.ProtoChunk; import net.minecraft.world.level.chunk.UpgradeData; -import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.chunk.storage.IOWorker; import net.minecraft.world.level.chunk.storage.RegionFileStorage; + import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -31,6 +31,25 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.atomic.AtomicReference; +#if MC_VER <= MC_1_17_1 +import net.minecraft.world.level.chunk.ChunkStatus; +#elif MC_VER <= MC_1_19_2 +import net.minecraft.world.level.chunk.ChunkStatus; +import net.minecraft.core.Registry; +#elif MC_VER <= MC_1_19_4 +import net.minecraft.core.registries.Registries; +import net.minecraft.world.level.chunk.ChunkStatus; +#elif MC_VER <= MC_1_20_6 +import net.minecraft.core.registries.Registries; +import net.minecraft.world.level.chunk.ChunkStatus; +#elif MC_VER <= MC_1_21_10 +import net.minecraft.core.registries.Registries; +import net.minecraft.world.level.chunk.status.ChunkStatus; +#else +import net.minecraft.world.level.chunk.status.ChunkStatus; +import net.minecraft.world.level.chunk.PalettedContainerFactory; +#endif + public class ChunkFileReader implements AutoCloseable { diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/internalServer/InternalServerGenerator.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/internalServer/InternalServerGenerator.java index e8f2269dd..4eaf32f17 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/internalServer/InternalServerGenerator.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/worldGeneration/internalServer/InternalServerGenerator.java @@ -23,7 +23,12 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.TicketType; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.chunk.ChunkAccess; + +#if MC_VER <= MC_1_20_4 +import net.minecraft.world.level.chunk.ChunkStatus; +#else import net.minecraft.world.level.chunk.status.ChunkStatus; +#endif import java.util.*; import java.util.concurrent.CompletableFuture; @@ -220,7 +225,7 @@ public class InternalServerGenerator #if MC_VER < MC_1_21_5 int chunkLevel = 33; // 33 is equivalent to FULL Chunk - level.getChunkSource().distanceManager.addTicket(DH_SERVER_GEN_TICKET, pos, chunkLevel, pos); + level.getChunkSource().distanceManager.addTicket(DH_SERVER_GEN_TICKET, chunkPos, chunkLevel, chunkPos); #else level.getChunkSource().addTicketWithRadius(DH_SERVER_GEN_TICKET, chunkPos, 0); #endif @@ -235,13 +240,13 @@ public class InternalServerGenerator } #if MC_VER <= MC_1_20_4 - return chunkHolder.getOrScheduleFuture(ChunkStatus.FEATURES, level.getChunkSource().chunkMap) + return chunkHolder.getOrScheduleFuture(ChunkStatus.FULL, level.getChunkSource().chunkMap) .thenApply(result -> result.left().orElseThrow(() -> new RuntimeException(result.right().get().toString()))); // can throw if the server is shutting down #elif MC_VER <= MC_1_20_6 - return chunkHolder.getOrScheduleFuture(ChunkStatus.FEATURES, level.getChunkSource().chunkMap) + return chunkHolder.getOrScheduleFuture(ChunkStatus.FULL, level.getChunkSource().chunkMap) .thenApply(result -> result.orElseThrow(() -> new RuntimeException(result.toString()))); // can throw if the server is shutting down #else - return chunkHolder.scheduleChunkGenerationTask(ChunkStatus.FEATURES, level.getChunkSource().chunkMap) + return chunkHolder.scheduleChunkGenerationTask(ChunkStatus.FULL, level.getChunkSource().chunkMap) .thenApply(result -> result.orElseThrow(() -> new RuntimeException(result.getError()))); // can throw if the server is shutting down #endif 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 34cd8343d..5d04bc004 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 @@ -74,32 +74,32 @@ public final class StepBiomes extends AbstractWorldGenStep #if MC_VER < MC_1_18_2 - this.environment.params.generator.createBiomes(this.environment.params.biomes, chunk); + this.environment.globalParams.generator.createBiomes(this.environment.globalParams.biomes, chunk); #elif MC_VER < MC_1_19_2 chunk = this.environment.confirmFutureWasRunSynchronously( - this.environment.params.generator.createBiomes( - this.environment.params.biomes, + this.environment.globalParams.generator.createBiomes( + this.environment.globalParams.biomes, Runnable::run, Blender.of(worldGenRegion), - tParams.structFeat.forWorldGenRegion(worldGenRegion), + tParams.structFeatManager.forWorldGenRegion(worldGenRegion), chunk) ); #elif MC_VER < MC_1_19_4 chunk = this.environment.confirmFutureWasRunSynchronously( - this.environment.params.generator.createBiomes( - this.environment.params.biomes, + this.environment.globalParams.generator.createBiomes( + this.environment.globalParams.biomes, Runnable::run, - this.environment.params.randomState, Blender.of(worldGenRegion), - tParams.structFeat.forWorldGenRegion(worldGenRegion), + this.environment.globalParams.randomState, Blender.of(worldGenRegion), + tParams.structFeatManager.forWorldGenRegion(worldGenRegion), chunk) ); #elif MC_VER < MC_1_21_1 chunk = this.environment.confirmFutureWasRunSynchronously( - this.environment.params.generator.createBiomes( + this.environment.globalParams.generator.createBiomes( Runnable::run, - this.environment.params.randomState, + this.environment.globalParams.randomState, Blender.of(worldGenRegion), - tParams.structFeat.forWorldGenRegion(worldGenRegion), + tParams.structFeatManager.forWorldGenRegion(worldGenRegion), chunk) ); #else 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 fae6a935a..20407770e 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 @@ -80,7 +80,7 @@ public final class StepFeatures extends AbstractWorldGenStep { #if MC_VER < MC_1_18_2 worldGenRegion.setOverrideCenter(chunk.getPos()); - environment.params.generator.applyBiomeDecoration(worldGenRegion, tParams.structFeat); + environment.globalParams.generator.applyBiomeDecoration(worldGenRegion, tParams.structFeatManager); #else if (worldGenRegion.hasChunk(chunkWrapper.getChunkPos().getX(), chunkWrapper.getChunkPos().getZ())) { 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 036bdc7f6..04cd3d356 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 @@ -73,27 +73,27 @@ public final class StepNoise extends AbstractWorldGenStep ChunkAccess chunk = chunkWrapper.getChunk(); #if MC_VER < MC_1_17_1 - this.environment.params.generator.fillFromNoise(worldGenRegion, tParams.structFeat, chunk); + this.environment.globalParams.generator.fillFromNoise(worldGenRegion, tParams.structFeatManager, chunk); #elif MC_VER < MC_1_18_2 chunk = this.environment.confirmFutureWasRunSynchronously( - this.environment.params.generator.fillFromNoise( + this.environment.globalParams.generator.fillFromNoise( Runnable::run, - tParams.structFeat.forWorldGenRegion(worldGenRegion), + tParams.structFeatManager.forWorldGenRegion(worldGenRegion), chunk)); #elif MC_VER < MC_1_19_2 chunk = this.environment.confirmFutureWasRunSynchronously( - this.environment.params.generator.fillFromNoise( + this.environment.globalParams.generator.fillFromNoise( Runnable::run, Blender.of(worldGenRegion), - tParams.structFeat.forWorldGenRegion(worldGenRegion), + tParams.structFeatManager.forWorldGenRegion(worldGenRegion), chunk)); #elif MC_VER < MC_1_21_1 chunk = this.environment.confirmFutureWasRunSynchronously( - this.environment.params.generator.fillFromNoise( + this.environment.globalParams.generator.fillFromNoise( Runnable::run, Blender.of(worldGenRegion), - this.environment.params.randomState, - tParams.structFeat.forWorldGenRegion(worldGenRegion), + this.environment.globalParams.randomState, + tParams.structFeatManager.forWorldGenRegion(worldGenRegion), chunk)); #else chunk = this.environment.confirmFutureWasRunSynchronously( 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 9d1eb1c42..70c2d1431 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 @@ -74,9 +74,9 @@ public final class StepStructureStart extends AbstractWorldGenStep // TODO should be put in wrapped environment so we can skip some other world gen steps // SURFACE wouldn't need structure generation either #if MC_VER < MC_1_19_2 - if (!this.environment.params.worldGenSettings.generateFeatures()) + if (!this.environment.globalParams.worldGenSettings.generateFeatures()) #elif MC_VER < MC_1_19_4 - if (!this.environment.params.worldGenSettings.generateStructures()) + if (!this.environment.globalParams.worldGenSettings.generateStructures()) #else if (!this.environment.globalParams.worldOptions.generateStructures()) #endif @@ -95,15 +95,15 @@ public final class StepStructureStart extends AbstractWorldGenStep 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); + this.environment.globalParams.generator.createStructures(this.environment.globalParams.registry, tParams.structFeatManager, chunk, this.environment.globalParams.structures, + this.environment.globalParams.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); + this.environment.globalParams.generator.createStructures(this.environment.globalParams.registry, this.environment.globalParams.randomState, tParams.structFeatManager, chunk, this.environment.globalParams.structures, + this.environment.globalParams.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); + this.environment.globalParams.generator.createStructures(this.environment.globalParams.registry, + this.environment.globalParams.level.getChunkSource().getGeneratorState(), + tParams.structFeatManager, chunk, this.environment.globalParams.structures); #else this.environment.globalParams.generator.createStructures(this.environment.globalParams.registry, this.environment.globalParams.level.getChunkSource().getGeneratorState(), 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 b7f460c2b..6e9a2d606 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 @@ -70,9 +70,9 @@ public final class StepSurface extends AbstractWorldGenStep ChunkAccess chunk = chunkWrapper.getChunk(); #if MC_VER < MC_1_18_2 - this.environment.params.generator.buildSurfaceAndBedrock(worldGenRegion, chunk); + this.environment.globalParams.generator.buildSurfaceAndBedrock(worldGenRegion, chunk); #elif MC_VER < MC_1_19_2 - this.environment.params.generator.buildSurface(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk); + this.environment.globalParams.generator.buildSurface(worldGenRegion, tParams.structFeatManager.forWorldGenRegion(worldGenRegion), chunk); #else this.environment.globalParams.generator.buildSurface(worldGenRegion, tParams.structFeatManager.forWorldGenRegion(worldGenRegion), this.environment.globalParams.randomState, chunk); #endif diff --git a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinUtilBackgroundThread.java b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinUtilBackgroundThread.java index 33e38e235..0974498ee 100644 --- a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinUtilBackgroundThread.java +++ b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinUtilBackgroundThread.java @@ -25,6 +25,15 @@ import org.spongepowered.asm.mixin.Mixin; import net.minecraft.Util; +#if MC_VER < MC_1_21_3 +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.concurrent.ExecutorService; +import java.util.function.Supplier; +#endif + /** * This is needed for DH's world gen so we can run * world gen on our own threads instead of using MC thread pools.