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

This commit is contained in:
TomTheFurry
2022-04-06 00:10:01 +08:00
parent 4285f32b94
commit f01e31f475
6 changed files with 53 additions and 4 deletions
@@ -52,12 +52,22 @@ public class LightedWorldGenRegion extends WorldGenRegion {
Long2ObjectOpenHashMap<ChunkAccess> chunkMap = new Long2ObjectOpenHashMap<ChunkAccess>();
#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,
@@ -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
}
@@ -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) {
@@ -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);
@@ -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
@@ -13,6 +13,7 @@
"MixinOptionsScreen",
"MixinWorldRenderer",
"MixinFogRenderer",
"MixinChunkGenerator",
"events.MixinClientLevel",
"events.MixinMinecraft",
"events.MixinBlockUpdate"