feat: 添加了防更新抑制时崩服的措施
This commit is contained in:
1 parent
e8dc993ed2
commit
ea91716272
3 files changed
+38
-4
No files matched your search
+34
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"minVersion": "0.8",
|
||||
"package": "com.github.zly2006.carpetslsaddition.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"server": [
|
||||
"block.MixinBlock",
|
||||
"carpet.MixinFakePlayer",
|
||||
"carpet.MixinSettingsManager",
|
||||
@@ -32,6 +32,7 @@
|
||||
"protocol.pcaSyncProtocol.entity.MixinStorageMinecartEntity",
|
||||
"screen.MixinScreenHandler",
|
||||
"screen.MixinSlot",
|
||||
"server.MixinMinecraftServer",
|
||||
"server.MixinPlayerManager",
|
||||
"world.MixinChainRestrictedNeighborUpdater",
|
||||
"world.MixinSpawnHelper"
|
||||
|
||||
Reference in new issue
Block a user