diff --git a/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/MixinPlugin.java b/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/MixinPlugin.java index 3411ce5d6..4371b9904 100644 --- a/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/MixinPlugin.java +++ b/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/MixinPlugin.java @@ -1,6 +1,7 @@ package com.ishland.c2me.rewrites.chunksystem; import com.ishland.c2me.base.common.ModuleMixinPlugin; +import com.ishland.c2me.rewrites.chunksystem.common.Config; import java.lang.reflect.Field; @@ -16,7 +17,8 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { if (mixinClassName.startsWith("com.ishland.c2me.rewrites.chunksystem.mixin.serialization_sync.")) return !gcFreeChunkSerializerDetected; - + if (mixinClassName.startsWith("com.ishland.c2me.rewrites.chunksystem.mixin.fluid_postprocessing")) + return Config.fluidPostProcessingToScheduledTick; return true; } diff --git a/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/common/Config.java b/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/common/Config.java index 3c314cf8c..e9069529b 100644 --- a/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/common/Config.java +++ b/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/common/Config.java @@ -58,6 +58,17 @@ Whether to allow POIs (Point of Interest) to be unloaded """) .getBoolean(true, false); + public static final boolean fluidPostProcessingToScheduledTick = new ConfigSystem.ConfigAccessor() + .key("chunkSystem.fluidPostProcessingToScheduledTick") + .comment(""" + Whether to turn fluid postprocessing into scheduled tick + + Fluid post-processing is very expensive when loading in new chunks, and this can affect + MSPT significantly. This option delays fluid post-processing to scheduled tick to hopefully + mitigate this issue. + """) + .getBoolean(true, false); + public static void init() { // intentionally empty } diff --git a/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/mixin/fluid_postprocessing/MixinWorldChunk.java b/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/mixin/fluid_postprocessing/MixinWorldChunk.java new file mode 100644 index 000000000..d48b7c79b --- /dev/null +++ b/c2me-rewrites-chunk-system/src/main/java/com/ishland/c2me/rewrites/chunksystem/mixin/fluid_postprocessing/MixinWorldChunk.java @@ -0,0 +1,20 @@ +package com.ishland.c2me.rewrites.chunksystem.mixin.fluid_postprocessing; + +import net.minecraft.block.BlockState; +import net.minecraft.fluid.FluidState; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.chunk.WorldChunk; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(WorldChunk.class) +public class MixinWorldChunk { + + @Redirect(method = "runPostProcessing", at = @At(value = "INVOKE", target = "Lnet/minecraft/fluid/FluidState;onScheduledTick(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V")) + private void redirectFluidScheduledTick(FluidState instance, ServerWorld world, BlockPos pos, BlockState state) { + world.scheduleFluidTick(pos, instance.getFluid(), 1); + } + +} diff --git a/c2me-rewrites-chunk-system/src/main/resources/c2me-rewrites-chunk-system.mixins.json b/c2me-rewrites-chunk-system/src/main/resources/c2me-rewrites-chunk-system.mixins.json index 583b3810f..b1860da93 100644 --- a/c2me-rewrites-chunk-system/src/main/resources/c2me-rewrites-chunk-system.mixins.json +++ b/c2me-rewrites-chunk-system/src/main/resources/c2me-rewrites-chunk-system.mixins.json @@ -19,6 +19,7 @@ "async_serialization.MixinChunkSerializer", "async_serialization.MixinProtoChunk", "async_serialization.MixinStorageIoWorker", - "async_serialization.MixinThreadedAnvilChunkStorage" + "async_serialization.MixinThreadedAnvilChunkStorage", + "fluid_postprocessing.MixinWorldChunk" ] }