Skip to content

Commit

Permalink
new: check for async entity loading and unloading
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Feb 7, 2024
1 parent 77aca87 commit 97eef75
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.ishland.c2me.fixes.general.threading_issues.mixin.asynccatchers;

import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.util.thread.ThreadExecutor;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.ConcurrentModificationException;

@Mixin(ThreadedAnvilChunkStorage.class)
public class MixinThreadedAnvilChunkStorage {

@Shadow @Final private ThreadExecutor<Runnable> mainThreadExecutor;

@Inject(method = "loadEntity", at = @At("HEAD"))
private void preventAsyncEntityLoad(CallbackInfo ci) {
if (!this.mainThreadExecutor.isOnThread()) {
throw new ConcurrentModificationException("Async entity load");
}
}

@Inject(method = "unloadEntity", at = @At("HEAD"))
private void preventAsyncEntityUnload(CallbackInfo ci) {
if (!this.mainThreadExecutor.isOnThread()) {
throw new ConcurrentModificationException("Async entity unload");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"MixinChunkTicketManager",
"MixinThreadedAnvilChunkStorage",
"asynccatchers.MixinMinecraftServer",
"asynccatchers.MixinServerChunkManager"
"asynccatchers.MixinServerChunkManager",
"asynccatchers.MixinThreadedAnvilChunkStorage"
]
}

0 comments on commit 97eef75

Please sign in to comment.