Skip to content

Commit

Permalink
new: strict detection for scheduled tick access
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Dec 24, 2024
1 parent d17ac66 commit 6bb745a
Showing 1 changed file with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <[email protected]>
Date: Tue, 24 Dec 2024 17:59:16 +0800
Subject: [PATCH] new: strict detection for scheduled tick access


diff --git a/c2me-fixes-worldgen-threading-issues/src/main/java/com/ishland/c2me/fixes/worldgen/threading_issues/mixin/threading_detections/readonly_protection/MixinChunkRegion.java b/c2me-fixes-worldgen-threading-issues/src/main/java/com/ishland/c2me/fixes/worldgen/threading_issues/mixin/threading_detections/readonly_protection/MixinChunkRegion.java
new file mode 100644
index 00000000..d1c5fae4
--- /dev/null
+++ b/c2me-fixes-worldgen-threading-issues/src/main/java/com/ishland/c2me/fixes/worldgen/threading_issues/mixin/threading_detections/readonly_protection/MixinChunkRegion.java
@@ -0,0 +1,49 @@
+package com.ishland.c2me.fixes.worldgen.threading_issues.mixin.threading_detections.readonly_protection;
+
+import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
+import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
+import net.minecraft.fluid.Fluid;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.ChunkPos;
+import net.minecraft.world.ChunkRegion;
+import net.minecraft.world.chunk.Chunk;
+import net.minecraft.world.chunk.ChunkGenerationStep;
+import net.minecraft.world.tick.BasicTickScheduler;
+import net.minecraft.world.tick.EmptyTickSchedulers;
+import org.slf4j.Logger;
+import org.spongepowered.asm.mixin.Final;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+
+@Mixin(ChunkRegion.class)
+public abstract class MixinChunkRegion {
+
+ @Shadow public abstract boolean isValidForSetBlock(BlockPos pos);
+
+ @Shadow @Final private static Logger LOGGER;
+
+ @Shadow @Final private ChunkGenerationStep generationStep;
+
+ @Shadow @Final private Chunk centerPos;
+
+ @WrapMethod(method = "method_14340")
+ private BasicTickScheduler<BlockPos> wrapBlockScheduledTick(BlockPos pos, Operation<BasicTickScheduler<BlockPos>> original) {
+ if (this.isValidForSetBlock(pos)) {
+ return original.call(pos);
+ } else {
+ LOGGER.warn("Detected block scheduled tick access in a far chunk {}, pos: {}, status: {}, currently generating: {}", new ChunkPos(pos), pos, this.generationStep.targetStatus(), this.centerPos.getPos());
+ return EmptyTickSchedulers.getReadOnlyTickScheduler();
+ }
+ }
+
+ @WrapMethod(method = "method_14337")
+ private BasicTickScheduler<Fluid> wrapFluidScheduledTick(BlockPos pos, Operation<BasicTickScheduler<Fluid>> original) {
+ if (this.isValidForSetBlock(pos)) {
+ return original.call(pos);
+ } else {
+ LOGGER.warn("Detected fluid scheduled tick access in a far chunk {}, pos: {}, status: {}, currently generating: {}", new ChunkPos(pos), pos, this.generationStep.targetStatus(), this.centerPos.getPos());
+ return EmptyTickSchedulers.getReadOnlyTickScheduler();
+ }
+ }
+
+}
diff --git a/c2me-fixes-worldgen-threading-issues/src/main/resources/c2me-fixes-worldgen-threading-issues.mixins.json b/c2me-fixes-worldgen-threading-issues/src/main/resources/c2me-fixes-worldgen-threading-issues.mixins.json
index b0ed8d8f..5979b61c 100644
--- a/c2me-fixes-worldgen-threading-issues/src/main/resources/c2me-fixes-worldgen-threading-issues.mixins.json
+++ b/c2me-fixes-worldgen-threading-issues/src/main/resources/c2me-fixes-worldgen-threading-issues.mixins.json
@@ -37,6 +37,7 @@
"threading.MixinWoodlandMansionGeneratorMansionParameters",
"threading.math.MixinAffineTransformation",
"threading.math.MixinDirectionTransformation",
- "threading_detections.random_instances.MixinWorld"
+ "threading_detections.random_instances.MixinWorld",
+ "threading_detections.readonly_protection.MixinChunkRegion"
]
}

0 comments on commit 6bb745a

Please sign in to comment.