diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commonMixins/MixinChunkMapCommon.java b/common/src/main/java/com/seibel/distanthorizons/common/commonMixins/MixinChunkMapCommon.java new file mode 100644 index 000000000..a9dce2530 --- /dev/null +++ b/common/src/main/java/com/seibel/distanthorizons/common/commonMixins/MixinChunkMapCommon.java @@ -0,0 +1,85 @@ +package com.seibel.distanthorizons.common.commonMixins; + +import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; +import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper; +import com.seibel.distanthorizons.core.api.internal.ServerApi; +import com.seibel.distanthorizons.core.api.internal.SharedApi; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.chunk.ChunkAccess; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +public class MixinChunkMapCommon +{ + + public static void onChunkSave(ServerLevel level, ChunkAccess chunk, CallbackInfoReturnable ci) + { + // is this position already being updated? + if (SharedApi.isChunkAtChunkPosAlreadyUpdating(chunk.getPos().x, chunk.getPos().z)) + { + return; + } + + + + // is this chunk being saved to disk? + boolean savingChunkToDisk = ci.getReturnValue(); + // true means a chunk was saved to disk + if (!savingChunkToDisk) + { + return; + } + + // TODO are the following validations necessary since we are checking above if + // the callback return value should state if the chunk was actually saved or not? + // Do we trust it to always be correct? + + + + // corrupt/incomplete chunk validation // + + // MC has a tendency to try saving incomplete or corrupted chunks (which show up as empty or black chunks) + // this logic should prevent that from happening + #if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1 + if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect()) + { + return; + } + #else + if (chunk.isUnsaved() || chunk.isUpgrading() || !chunk.isLightCorrect()) + { + return; + } + #endif + + + + // biome validation // + + // some chunks may be missing their biomes, which cause issues when attempting to save them + #if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1 + if (chunk.getBiomes() == null) + { + return; + } + #else + try + { + // this will throw an exception if the biomes aren't set up + chunk.getNoiseBiome(0,0,0); + } + catch (Exception e) + { + return; + } + #endif + + + + // submit the update event + ServerApi.INSTANCE.serverChunkSaveEvent( + new ChunkWrapper(chunk, level, ServerLevelWrapper.getWrapper(level)), + ServerLevelWrapper.getWrapper(level) + ); + } + +} diff --git a/coreSubProjects b/coreSubProjects index 301cce3d1..1b162f10e 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 301cce3d119e39c3902faf367cb55c71b7180dc0 +Subproject commit 1b162f10e6a092f8915c26a19ba6e5233b0c52fa 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 add9abccc..19ee18ee5 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 @@ -1,9 +1,6 @@ package com.seibel.distanthorizons.fabric.mixins.server; -import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; -import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper; -import com.seibel.distanthorizons.core.api.internal.ServerApi; -import com.seibel.distanthorizons.core.api.internal.SharedApi; +import com.seibel.distanthorizons.common.commonMixins.MixinChunkMapCommon; import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.chunk.ChunkAccess; @@ -33,65 +30,6 @@ public class MixinChunkMap // don't need the chunk(s) before MC has finished saving them @Inject(method = "save", at = @At(value = "RETURN", target = CHUNK_SERIALIZER_WRITE)) private void onChunkSave(ChunkAccess chunk, CallbackInfoReturnable ci) - { - // true means a chunk was saved to disk - if (ci.getReturnValue()) - { - // TODO is this validation necessary since we are checking above if - // the callback return value should state if the chunk was actually saved or not? - // Do we trust it to always be correct? - - //=====================================// - // corrupt/incomplete chunk validation // - //=====================================// - - // MC has a tendency to try saving incomplete or corrupted chunks (which show up as empty or black chunks) - // this logic should prevent that from happening - #if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1 - if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect()) - { - return; - } - #else - if (chunk.isUnsaved() || chunk.isUpgrading() || !chunk.isLightCorrect()) - { - return; - } - #endif - - - //==================// - // biome validation // - //==================// - - // some chunks may be missing their biomes, which cause issues when attempting to save them - #if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1 - if (chunk.getBiomes() == null) - { - return; - } - #else - try - { - // this will throw an exception if the biomes aren't set up - chunk.getNoiseBiome(0,0,0); - } - catch (Exception e) - { - return; - } - #endif - - - - if (!SharedApi.isChunkAtBlockPosAlreadyUpdating(chunk.getPos().getWorldPosition().getX(), chunk.getPos().getWorldPosition().getZ()) ) - { - ServerApi.INSTANCE.serverChunkSaveEvent( - new ChunkWrapper(chunk, this.level, ServerLevelWrapper.getWrapper(this.level)), - ServerLevelWrapper.getWrapper(this.level) - ); - } - } - } + { MixinChunkMapCommon.onChunkSave(this.level, chunk, ci); } } diff --git a/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/server/MixinChunkMap.java b/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/server/MixinChunkMap.java index 92e0a4a0c..4109ac6bd 100644 --- a/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/server/MixinChunkMap.java +++ b/forge/src/main/java/com/seibel/distanthorizons/forge/mixins/server/MixinChunkMap.java @@ -1,8 +1,6 @@ package com.seibel.distanthorizons.forge.mixins.server; -import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; -import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper; -import com.seibel.distanthorizons.core.api.internal.ServerApi; +import com.seibel.distanthorizons.common.commonMixins.MixinChunkMapCommon; import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.chunk.ChunkAccess; @@ -32,65 +30,6 @@ public class MixinChunkMap // don't need the chunk(s) before MC has finished saving them @Inject(method = "save", at = @At(value = "RETURN", target = CHUNK_SERIALIZER_WRITE)) private void onChunkSave(ChunkAccess chunk, CallbackInfoReturnable ci) - { - // true means a chunk was saved to disk - if (ci.getReturnValue()) - { - // TODO is this validation necessary since we are checking above if - // the callback return value should state if the chunk was actually saved or not? - // Do we trust it to always be correct? - - //=====================================// - // corrupt/incomplete chunk validation // - //=====================================// - - // MC has a tendency to try saving incomplete or corrupted chunks (which show up as empty or black chunks) - // this logic should prevent that from happening - #if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1 - if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect()) - { - return; - } - #else - if (chunk.isUnsaved() || chunk.isUpgrading() || !chunk.isLightCorrect()) - { - return; - } - #endif - - - //==================// - // biome validation // - //==================// - - // some chunks may be missing their biomes, which cause issues when attempting to save them - #if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1 - if (chunk.getBiomes() == null) - { - return; - } - #else - try - { - // this will throw an exception if the biomes aren't set up - chunk.getNoiseBiome(0,0,0); - } - catch (Exception e) - { - return; - } - #endif - - - - if (!SharedApi.isChunkAtBlockPosAlreadyUpdating(chunk.getPos().getWorldPosition().getX(), chunk.getPos().getWorldPosition().getZ()) ) - { - ServerApi.INSTANCE.serverChunkSaveEvent( - new ChunkWrapper(chunk, this.level, ServerLevelWrapper.getWrapper(this.level)), - ServerLevelWrapper.getWrapper(this.level) - ); - } - } - } + { MixinChunkMapCommon.onChunkSave(this.level, chunk, ci); } } \ No newline at end of file diff --git a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinChunkMap.java b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinChunkMap.java index c3d22e4b9..9ecfce79d 100644 --- a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinChunkMap.java +++ b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/server/MixinChunkMap.java @@ -1,9 +1,6 @@ package com.seibel.distanthorizons.neoforge.mixins.server; -import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; -import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper; -import com.seibel.distanthorizons.core.api.internal.ServerApi; -import com.seibel.distanthorizons.core.api.internal.SharedApi; +import com.seibel.distanthorizons.common.commonMixins.MixinChunkMapCommon; import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.chunk.ChunkAccess; @@ -33,65 +30,6 @@ public class MixinChunkMap // don't need the chunk(s) before MC has finished saving them @Inject(method = "save", at = @At(value = "RETURN", target = CHUNK_SERIALIZER_WRITE)) private void onChunkSave(ChunkAccess chunk, CallbackInfoReturnable ci) - { - // true means a chunk was saved to disk - if (ci.getReturnValue()) - { - // TODO is this validation necessary since we are checking above if - // the callback return value should state if the chunk was actually saved or not? - // Do we trust it to always be correct? - - //=====================================// - // corrupt/incomplete chunk validation // - //=====================================// - - // MC has a tendency to try saving incomplete or corrupted chunks (which show up as empty or black chunks) - // this logic should prevent that from happening - #if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1 - if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect()) - { - return; - } - #else - if (chunk.isUnsaved() || chunk.isUpgrading() || !chunk.isLightCorrect()) - { - return; - } - #endif - - - //==================// - // biome validation // - //==================// - - // some chunks may be missing their biomes, which cause issues when attempting to save them - #if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1 - if (chunk.getBiomes() == null) - { - return; - } - #else - try - { - // this will throw an exception if the biomes aren't set up - chunk.getNoiseBiome(0,0,0); - } - catch (Exception e) - { - return; - } - #endif - - - - if (!SharedApi.isChunkAtBlockPosAlreadyUpdating(chunk.getPos().getWorldPosition().getX(), chunk.getPos().getWorldPosition().getZ()) ) - { - ServerApi.INSTANCE.serverChunkSaveEvent( - new ChunkWrapper(chunk, this.level, ServerLevelWrapper.getWrapper(this.level)), - ServerLevelWrapper.getWrapper(this.level) - ); - } - } - } + { MixinChunkMapCommon.onChunkSave(this.level, chunk, ci); } } \ No newline at end of file