diff --git a/src/main/java/com/dreammaster/mixin/mixins/early/MixinMinecraft_ConfirmExit.java b/src/main/java/com/dreammaster/mixin/mixins/early/MixinMinecraft_ConfirmExit.java index b979e0f61..af4b3cb09 100644 --- a/src/main/java/com/dreammaster/mixin/mixins/early/MixinMinecraft_ConfirmExit.java +++ b/src/main/java/com/dreammaster/mixin/mixins/early/MixinMinecraft_ConfirmExit.java @@ -10,16 +10,18 @@ import net.minecraft.util.StatCollector; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.dreammaster.client.util.IconLoader; import com.dreammaster.coremod.DreamCoreMod; import com.dreammaster.lib.Refstrings; -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; @Mixin(Minecraft.class) -public class MixinMinecraft_ConfirmExit { +public abstract class MixinMinecraft_ConfirmExit { @Unique private boolean dreamcraft$isCloseRequested; @@ -27,19 +29,16 @@ public class MixinMinecraft_ConfirmExit { @Unique private boolean dreamcraft$waitingDialogQuit; - @ModifyExpressionValue( - method = "runGameLoop", - at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/Display;isCloseRequested()Z", remap = false)) - private boolean dreamcraft$confirmGameShutdown(boolean isCloseRequested) { - if (!DreamCoreMod.showConfirmExitWindow) { - return isCloseRequested; - } - if (this.dreamcraft$isCloseRequested) { - return true; + @Shadow + public abstract void shutdown(); + + @Inject(method = "shutdown", at = @At(value = "HEAD"), cancellable = true) + private void dreamcraft$confirmGameShutdown(CallbackInfo ci) { + if (!DreamCoreMod.showConfirmExitWindow || this.dreamcraft$isCloseRequested) { + return; } - if (dreamcraft$waitingDialogQuit) return false; - if (isCloseRequested) { - dreamcraft$waitingDialogQuit = true; + if (!this.dreamcraft$waitingDialogQuit) { + this.dreamcraft$waitingDialogQuit = true; new Thread(() -> { final JFrame frame = new JFrame(); frame.setAlwaysOnTop(true); @@ -60,12 +59,11 @@ public class MixinMinecraft_ConfirmExit { imageIcon); if (result == JOptionPane.YES_OPTION) { this.dreamcraft$isCloseRequested = true; + this.shutdown(); } - dreamcraft$waitingDialogQuit = false; + this.dreamcraft$waitingDialogQuit = false; }).start(); - return false; } - return false; + ci.cancel(); } - }