Skip to content

Commit

Permalink
Merge remote-tracking branch 'paulzzh/confirm-exit' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Jan 15, 2025
2 parents 2302c62 + 1254eed commit 4f3270e
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,35 @@
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;

@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);
Expand All @@ -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();
}

}

0 comments on commit 4f3270e

Please sign in to comment.