From 3a3fe214c414d0942da11d33c19afb0d8008aa5a Mon Sep 17 00:00:00 2001 From: tom lee Date: Sun, 30 Jan 2022 15:31:59 +0800 Subject: [PATCH] Fix experGen loading existing chunks. (It now works.) --- .../wrappers/worldGeneration/ChunkLoader.java | 37 ++++++++++++------- .../worldGeneration/WorldGenerationStep.java | 20 +++++----- core | 2 +- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ChunkLoader.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ChunkLoader.java index 4809913d1..b19278c5e 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ChunkLoader.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ChunkLoader.java @@ -28,10 +28,11 @@ import net.minecraft.world.level.lighting.LevelLightEngine; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluids; + + import org.apache.logging.log4j.Logger; public class ChunkLoader { - private static final Logger LOGGER = ClientApi.LOGGER; private static LevelChunkSection[] readSections(WorldGenLevel level, LevelLightEngine lightEngine, @@ -85,18 +86,21 @@ public class ChunkLoader { } } - public static ChunkStatus.ChunkType readChunkType(CompoundTag compoundTag) { - return ChunkStatus.byName(compoundTag.getString("Status")).getChunkType(); + public static ChunkStatus.ChunkType readChunkType(CompoundTag tagLevel) { + ChunkStatus chunkStatus = ChunkStatus.byName(tagLevel.getString("Status")); + if (chunkStatus != null) { + return chunkStatus.getChunkType(); + } + return ChunkStatus.ChunkType.PROTOCHUNK; } public static LevelChunk read(WorldGenLevel level, LevelLightEngine lightEngine, ChunkPos chunkPos, CompoundTag chunkData) { - ChunkStatus.ChunkType chunkType = readChunkType(chunkData); - if (chunkType == ChunkStatus.ChunkType.PROTOCHUNK) - return null; - - ChunkGenerator chunkGenerator = level.getLevel().getChunkSource().getGenerator(); CompoundTag tagLevel = chunkData.getCompound("Level"); + + ChunkStatus.ChunkType chunkType = readChunkType(tagLevel); + if (chunkType != ChunkStatus.ChunkType.LEVELCHUNK) + return null; ChunkPos actualPos = new ChunkPos(tagLevel.getInt("xPos"), tagLevel.getInt("zPos")); if (!Objects.equals(chunkPos, actualPos)) { @@ -105,34 +109,41 @@ public class ChunkLoader { return null; } + + //====================== Read params for making the LevelChunk ============================ + ChunkBiomeContainer chunkBiomeContainer = new ChunkBiomeContainer( level.getLevel().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), chunkPos, - chunkGenerator.getBiomeSource(), + level.getLevel().getChunkSource().getGenerator().getBiomeSource(), tagLevel.contains("Biomes", 11) ? tagLevel.getIntArray("Biomes") : null); - - - // Read params for making the LevelChunk - + UpgradeData upgradeData = tagLevel.contains("UpgradeData", 10) ? new UpgradeData(tagLevel.getCompound("UpgradeData")) : UpgradeData.EMPTY; + TickList blockTicks = tagLevel.contains("TileTicks", 9) ? ChunkTickList.create(tagLevel.getList("TileTicks", 10), Registry.BLOCK::getKey, Registry.BLOCK::get) : new ProtoTickList(block -> (block == null || block.defaultBlockState().isAir()), chunkPos, tagLevel.getList("ToBeTicked", 9)); + TickList liquidTicks = tagLevel.contains("LiquidTicks", 9) ? ChunkTickList.create(tagLevel.getList("LiquidTicks", 10), Registry.FLUID::getKey, Registry.FLUID::get) : new ProtoTickList(fluid -> (fluid == null || fluid == Fluids.EMPTY), chunkPos, tagLevel.getList("LiquidsToBeTicked", 9)); + long inhabitedTime = tagLevel.getLong("InhabitedTime"); + LevelChunkSection[] levelChunkSections = readSections(level, lightEngine, chunkPos, tagLevel); + //======================== Make the chunk =========================================== LevelChunk chunk = new LevelChunk(level.getLevel(), chunkPos, chunkBiomeContainer, upgradeData, blockTicks, liquidTicks, inhabitedTime, levelChunkSections, null); + //========================== Post setup some chunk data ============================== chunk.setLightCorrect(tagLevel.getBoolean("isLightOn")); readHeightmaps(chunk, tagLevel); readPostPocessings(chunk, tagLevel); + //ClientApi.LOGGER.info("Loaded chunk @ "+chunk.getPos()); return chunk; } } diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java index aa5efc4bc..f28bd3a43 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/WorldGenerationStep.java @@ -68,6 +68,7 @@ import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.DataLayer; +import net.minecraft.world.level.chunk.ImposterProtoChunk; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunkSection; import net.minecraft.world.level.chunk.LightChunkGetter; @@ -452,12 +453,6 @@ public final class WorldGenerationStep { } } - - - - - - //=================Generation Step=================== private static T joinSync(CompletableFuture f) { @@ -557,8 +552,7 @@ public final class WorldGenerationStep { if (chunkData == null) { return new ProtoChunk(chunkPos, UpgradeData.EMPTY); } else { - return null; - //return ChunkLoader.read(level, lightEngine, chunkPos, chunkData); + return ChunkLoader.read(level, lightEngine, chunkPos, chunkData); } } @@ -1073,11 +1067,19 @@ public final class WorldGenerationStep { return l>=0 && l=0 && k