|
| 1 | +package io.github.optijava.opt_carpet_addition.mixins.rule.cceSuppressionCrashFix; |
| 2 | + |
| 3 | +import io.github.optijava.opt_carpet_addition.OptCarpetSettings; |
| 4 | +import io.github.optijava.opt_carpet_addition.logger.cceSuppressionCrashLogger.CCESuppressionCrashLogger; |
| 5 | +import io.github.optijava.opt_carpet_addition.logger.cceSuppressionCrashLogger.ThrowableCCESuppression; |
| 6 | +import net.minecraft.server.MinecraftServer; |
| 7 | +import net.minecraft.server.world.ServerWorld; |
| 8 | +import org.spongepowered.asm.mixin.Mixin; |
| 9 | +import org.spongepowered.asm.mixin.injection.At; |
| 10 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 11 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 12 | +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; |
| 13 | + |
| 14 | +import java.util.Iterator; |
| 15 | +import java.util.function.BooleanSupplier; |
| 16 | + |
| 17 | +@Mixin(MinecraftServer.class) |
| 18 | +public class MinecraftServer_Mixin { |
| 19 | + |
| 20 | + @Inject( |
| 21 | + method = {"tickWorlds"}, |
| 22 | + at = {@At( |
| 23 | + value = "INVOKE", |
| 24 | + target = "Lnet/minecraft/util/crash/CrashReport;create(Ljava/lang/Throwable;Ljava/lang/String;)Lnet/minecraft/util/crash/CrashReport;" |
| 25 | + )}, |
| 26 | + locals = LocalCapture.CAPTURE_FAILHARD, |
| 27 | + cancellable = true |
| 28 | + ) |
| 29 | + public void injectTickWorlds(BooleanSupplier shouldKeepTicking, CallbackInfo ci, @SuppressWarnings("all") Iterator var2, ServerWorld serverWorld, Throwable throwable) { |
| 30 | + if (OptCarpetSettings.cceSuppressionCrashFix && (throwable instanceof ThrowableCCESuppression || throwable.getCause() instanceof ThrowableCCESuppression)) { |
| 31 | + try { |
| 32 | + if (throwable instanceof ThrowableCCESuppression) { |
| 33 | + CCESuppressionCrashLogger.INSTANCE.logUpdateSuppression(((ThrowableCCESuppression) throwable).pos); |
| 34 | + } else { |
| 35 | + CCESuppressionCrashLogger.INSTANCE.logUpdateSuppression(((ThrowableCCESuppression) throwable.getCause()).pos); |
| 36 | + } |
| 37 | + } catch (Exception ignored){} |
| 38 | + |
| 39 | + ci.cancel(); |
| 40 | + } |
| 41 | + } |
| 42 | +} |
0 commit comments