From f01e31f475e46e39bd646ac671864f99ac11cf52 Mon Sep 17 00:00:00 2001 From: TomTheFurry Date: Wed, 6 Apr 2022 00:10:01 +0800 Subject: [PATCH] Actually finish porting the world gen for 1.16 + add missing mixin for 1.16 & 1.17 + Solved the deadlock in world gen if moving too fast --- .../mimicObject/LightedWorldGenRegion.java | 12 ++++++- .../worldGeneration/step/StepBiomes.java | 2 +- .../worldGeneration/step/StepFeatures.java | 4 ++- .../worldGeneration/step/StepSurface.java | 2 +- .../fabric/mixins/MixinChunkGenerator.java | 36 +++++++++++++++++++ .../src/main/resources/fabric.lod.mixins.json | 1 + 6 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinChunkGenerator.java diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/mimicObject/LightedWorldGenRegion.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/mimicObject/LightedWorldGenRegion.java index 8575d3c19..536715691 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/mimicObject/LightedWorldGenRegion.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/mimicObject/LightedWorldGenRegion.java @@ -52,12 +52,22 @@ public class LightedWorldGenRegion extends WorldGenRegion { Long2ObjectOpenHashMap chunkMap = new Long2ObjectOpenHashMap(); #if MC_VERSION_1_17_1 private ChunkPos overrideCenterPos = null; - public void setOverrideCenter(ChunkPos pos) {overrideCenterPos = pos;} @Override public ChunkPos getCenter() { return overrideCenterPos==null ? super.getCenter() : overrideCenterPos; } + #elif MC_VERSION_1_16_5 + private ChunkPos overrideCenterPos = null; + public void setOverrideCenter(ChunkPos pos) {overrideCenterPos = pos;} + @Override + public int getCenterX() { + return overrideCenterPos==null ? super.getCenterX() : overrideCenterPos.x; + } + @Override + public int getCenterZ() { + return overrideCenterPos==null ? super.getCenterX() : overrideCenterPos.z; + } #endif public LightedWorldGenRegion(ServerLevel serverLevel, WorldGenLevelLightEngine lightEngine, diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepBiomes.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepBiomes.java index 279cc12de..9e0e856b1 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepBiomes.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepBiomes.java @@ -53,7 +53,7 @@ public final class StepBiomes { #if MC_VERSION_1_18_2 || MC_VERSION_1_18_1 chunk = environment.joinSync(environment.params.generator.createBiomes(environment.params.biomes, Runnable::run, Blender.of(worldGenRegion), tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk)); - #elif MC_VERSION_1_17_1 + #elif MC_VERSION_1_17_1 || MC_VERSION_1_16_5 environment.params.generator.createBiomes(environment.params.biomes, chunk); #endif } diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepFeatures.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepFeatures.java index 2936af1bc..0d6ccdfed 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepFeatures.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepFeatures.java @@ -12,6 +12,7 @@ import net.minecraft.server.level.WorldGenRegion; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.ProtoChunk; +import net.minecraft.world.level.levelgen.Heightmap; #if MC_VERSION_1_18_2 || MC_VERSION_1_18_1 import net.minecraft.world.level.levelgen.blending.Blender; #endif @@ -48,8 +49,9 @@ public final class StepFeatures { environment.params.generator.applyBiomeDecoration(worldGenRegion, chunk, tParams.structFeat.forWorldGenRegion(worldGenRegion)); Blender.generateBorderTicks(worldGenRegion, chunk); - #elif MC_VERSION_1_17_1 + #elif MC_VERSION_1_17_1 || MC_VERSION_1_16_5 worldGenRegion.setOverrideCenter(chunk.getPos()); + Heightmap.primeHeightmaps(chunk, STATUS.heightmapsAfter()); environment.params.generator.applyBiomeDecoration(worldGenRegion, tParams.structFeat); #endif } catch (ReportedException e) { diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepSurface.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepSurface.java index 8c01f2953..5908fe5e6 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepSurface.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/step/StepSurface.java @@ -39,7 +39,7 @@ public final class StepSurface { for (ChunkAccess chunk : chunksToDo) { // System.out.println("StepSurface: "+chunk.getPos()); - #if MC_VERSION_1_17_1 + #if MC_VERSION_1_17_1 || MC_VERSION_1_16_5 environment.params.generator.buildSurfaceAndBedrock(worldGenRegion, chunk); #elif MC_VERSION_1_18_1 || MC_VERSION_1_18_2 environment.params.generator.buildSurface(worldGenRegion, tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk); diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinChunkGenerator.java b/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinChunkGenerator.java new file mode 100644 index 000000000..50c396f1a --- /dev/null +++ b/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinChunkGenerator.java @@ -0,0 +1,36 @@ +package com.seibel.lod.fabric.mixins; + +import org.spongepowered.asm.mixin.Mixin; +import net.minecraft.world.level.chunk.ChunkGenerator; + +#if MC_VERSION_1_16_5 || MC_VERSION_1_17_1 +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.WorldGenRegion; +import net.minecraft.world.level.StructureFeatureManager; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.WorldgenRandom; + +@Mixin(ChunkGenerator.class) +public class MixinChunkGenerator { + @Redirect(method = "applyBiomeDecoration", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/biome/Biome;generate(Lnet/minecraft/world/level/StructureFeatureManager;" + + "Lnet/minecraft/world/level/chunk/ChunkGenerator;Lnet/minecraft/server/level/WorldGenRegion;J" + + "Lnet/minecraft/world/level/levelgen/WorldgenRandom;Lnet/minecraft/core/BlockPos;)V" + + )) + private void wrapBiomeGenerateCall(Biome biome, StructureFeatureManager structFeatManager, ChunkGenerator generator, + WorldGenRegion genRegion, long l, WorldgenRandom random, BlockPos pos) { + synchronized(ChunkGenerator.class) { + biome.generate(structFeatManager, (ChunkGenerator)(Object)this, genRegion, l, random, pos); + } + } +} + +#else +@Mixin(ChunkGenerator.class) +public class MixinChunkGenerator {} +#endif \ No newline at end of file diff --git a/fabric/src/main/resources/fabric.lod.mixins.json b/fabric/src/main/resources/fabric.lod.mixins.json index d30b710a4..5bf5759db 100644 --- a/fabric/src/main/resources/fabric.lod.mixins.json +++ b/fabric/src/main/resources/fabric.lod.mixins.json @@ -13,6 +13,7 @@ "MixinOptionsScreen", "MixinWorldRenderer", "MixinFogRenderer", + "MixinChunkGenerator", "events.MixinClientLevel", "events.MixinMinecraft", "events.MixinBlockUpdate"