From 33c2ca839e2b9f043eb1be0cb43153d739a091e1 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Tue, 31 Oct 2023 20:21:22 -0500 Subject: [PATCH] Fix incorrect chunk saving for MC 1.16/1.17 --- .../common/wrappers/chunk/ChunkWrapper.java | 6 ++-- .../fabric/mixins/server/MixinChunkMap.java | 29 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java index 6da633095..bef8b46b7 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java @@ -263,10 +263,8 @@ public class ChunkWrapper implements IChunkWrapper } - #if PRE_MC_1_17_1 - return true; - #elif MC_1_17_1 - return false; // MC's lighting engine never works for 1.17 + #if MC_1_16_5 || MC_1_17_1 + return false; // MC's lighting engine doesn't work consistently enough to trust for 1.16 or 1.17 #else if (this.chunk instanceof LevelChunk) { diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinChunkMap.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinChunkMap.java index 9384dec06..90033b89a 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinChunkMap.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/server/MixinChunkMap.java @@ -31,12 +31,18 @@ public class MixinChunkMap @Inject(method = "save", at = @At(value = "INVOKE", target = CHUNK_SERIALIZER_WRITE)) private void onChunkSave(ChunkAccess chunk, CallbackInfoReturnable ci) { - // corrupt/incomplete chunk validation - #if MC_1_16_5 || MC_1_17_1 - // no validation necessary - #else + //=====================================// + // corrupt/incomplete chunk validation // + //=====================================// + // MC has a tendency to try saving incomplete or corrupted chunks (which show up as empty or black chunks) - // this should prevent that from happening + // this logic should prevent that from happening + #if MC_1_16_5 || MC_1_17_1 + if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect()) + { + return; + } + #else if (chunk.isUnsaved() || chunk.isUpgrading() || !chunk.isLightCorrect()) { return; @@ -44,11 +50,14 @@ public class MixinChunkMap #endif - // biome validation + //==================// + // biome validation // + //==================// + + // some chunks may be missing their biomes, which cause issues when attempting to save them #if MC_1_16_5 || MC_1_17_1 if (chunk.getBiomes() == null) { - // in 1.16.5 some chunks may be missing their biomes, which cause issues when attempting to save them return; } #else @@ -59,15 +68,15 @@ public class MixinChunkMap } catch (Exception e) { - // some chunks may be missing their biomes, which cause issues when attempting to save them return; } #endif + ServerApi.INSTANCE.serverChunkSaveEvent( - new ChunkWrapper(chunk, level, ServerLevelWrapper.getWrapper(level)), - ServerLevelWrapper.getWrapper(level) + new ChunkWrapper(chunk, this.level, ServerLevelWrapper.getWrapper(this.level)), + ServerLevelWrapper.getWrapper(this.level) ); }