Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced the confirmation for exiting the game #1160

Merged
merged 3 commits into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}

}
Loading