feat: 添加了防更新抑制时崩服的措施

This commit is contained in:
Disy authored and zly2006 committed 2024-07-11 12:14:02 +08:00
1 parent e8dc993ed2
commit ea91716272
3 files changed
+38 -4

No files matched your search

@@ -0,0 +1,34 @@
package com.github.zly2006.carpetslsaddition.mixin.server;
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.function.BooleanSupplier;
@Mixin(MinecraftServer.class)
public abstract class MixinMinecraftServer {
@Redirect(method = "runServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;tick(Ljava/util/function/BooleanSupplier;)V"))
private void redirectTicking(MinecraftServer instance, BooleanSupplier shouldKeepTicking) {
if (SLSCarpetSettings.maxUpdateQueueSize != -1) {
try {
instance.tick(shouldKeepTicking);
}
catch (Throwable throwable) {
if (throwable instanceof OutOfMemoryError oom) {
if (!oom.getMessage().startsWith("Create by Carpet-SLS-Addition")) {
throw throwable;
}
}
else {
throw throwable;
}
}
}
else {
instance.tick(shouldKeepTicking);
}
}
}
@@ -18,13 +18,12 @@ public class MixinChainRestrictedNeighborUpdater {
@Final
private ArrayDeque<?> queue;
@Inject(method = "runQueuedUpdates", at = @At(value = "INVOKE", target = "Ljava/util/List;clear()V", ordinal = 0, shift = At.Shift.BEFORE), cancellable = true)
@Inject(method = "runQueuedUpdates", at = @At(value = "INVOKE", target = "Ljava/util/List;clear()V", ordinal = 0, shift = At.Shift.BEFORE))
public void injectRunQueuedUpdates(CallbackInfo ci) {
int maxSize = SLSCarpetSettings.maxUpdateQueueSize;
if (maxSize > 0) {
if (this.queue.size() > maxSize) {
ci.cancel();
// throw new OutOfMemoryError("The update queue exceeded the maximum allowed allocation of heap space set by SLS Addition!");
throw new OutOfMemoryError("Create by Carpet-SLS-Addition: The update queue exceeded the maximum allowed allocation of heap space set by SLS Addition!");
}
}
}