Skip to content

Commit

Permalink
new: turn fluid postprocessing into scheduled tick
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Nov 16, 2024
1 parent 1c1a64b commit 5b4bb20
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"async_serialization.MixinChunkSerializer",
"async_serialization.MixinProtoChunk",
"async_serialization.MixinStorageIoWorker",
"async_serialization.MixinThreadedAnvilChunkStorage"
"async_serialization.MixinThreadedAnvilChunkStorage",
"fluid_postprocessing.MixinWorldChunk"
]
}

0 comments on commit 5b4bb20

Please sign in to comment.