Repository: amblelabs/ait
Pull request #1227: Feat/inventory key GUI exiting
Author: login: MaketendoDev
Labels: name: S: Untriaged
description: Status: Indicates an item has not been triaged and doesn't have appropriate labels.
name: size/S
description: Denotes a PR that changes 10-99 lines.
name: S: Approved
description: Status: Reviewed and approved by at least one maintainer; a PR may require another approval.
Created: 2025-03-17T17:25:43Z | Merged: 2025-03-17T17:44:02Z

## About the PR
Added a QOL Feature where the Inventory key can be used to close the GUI mentioned in #1214

## Why / Balance
QOL

## Requirements
<!-- Confirm the following by placing an X in the brackets [X]: -->
- [X] I have read and am following the [Pull Request and Changelog Guidelines](https://amblelabs.github.io/ait-wiki/guidelines).
- [X] I have added media to this PR or it does not require an ingame showcase.
<!-- You should understand that not following the above may get your PR closed at maintainer’s discretion -->

**Changelog**
<!-- Add a Changelog entry to make players aware of new features or changes that could affect gameplay.
Make sure to read the guidelines and take this Changelog template out of the comment block in order for it to show up.
Changelog must have a :cl: symbol, so the bot recognizes the changes and adds them to the game's changelog. -->
:cl:
- add: Added a QOL feature where if the inventory key is pressed it closes AIT's GUIs!


Diff:
diff --git a/src/main/java/dev/amble/ait/client/screens/AstralMapScreen.java b/src/main/java/dev/amble/ait/client/screens/AstralMapScreen.java
index ce2d7f3e06..6690c1100a 100644
--- a/src/main/java/dev/amble/ait/client/screens/AstralMapScreen.java
+++ b/src/main/java/dev/amble/ait/client/screens/AstralMapScreen.java
@@ -6,6 +6,7 @@
 import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
 import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
 
+import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.gui.DrawContext;
 import net.minecraft.client.gui.screen.Screen;
 import net.minecraft.client.gui.widget.PressableTextWidget;
@@ -55,6 +56,15 @@ protected void init() {
                 this.textRenderer.getWidth(Text.literal("SEARCH")), 10, Text.literal("SEARCH"), button -> this.switcher.sync(null), this.textRenderer));
     }
 
+    @Override
+    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
+        if (keyCode == MinecraftClient.getInstance().options.inventoryKey.getDefaultKey().getCode()) {
+            this.close();
+            return true;
+        }
+        return super.keyPressed(keyCode, scanCode, modifiers);
+    }
+
     @Override
     public void render(DrawContext context, int mouseX, int mouseY, float delta) {
         this.drawBackground(context);
diff --git a/src/main/java/dev/amble/ait/client/screens/ConsoleScreen.java b/src/main/java/dev/amble/ait/client/screens/ConsoleScreen.java
index 205c1d03de..b479e2fcdb 100644
--- a/src/main/java/dev/amble/ait/client/screens/ConsoleScreen.java
+++ b/src/main/java/dev/amble/ait/client/screens/ConsoleScreen.java
@@ -1,7 +1,7 @@
 package dev.amble.ait.client.screens;
 
-import org.jetbrains.annotations.Nullable;
 
+import org.jetbrains.annotations.Nullable;
 import net.minecraft.client.MinecraftClient;
 import net.minecraft.sound.SoundCategory;
 import net.minecraft.sound.SoundEvent;
@@ -37,6 +37,15 @@ protected ConsoleScreen(Text title, ClientTardis tardis, BlockPos console) {
         }
     }
 
+    @Override
+    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
+        if (keyCode == MinecraftClient.getInstance().options.inventoryKey.getDefaultKey().getCode()) {
+            this.close();
+            return true;
+        }
+        return super.keyPressed(keyCode, scanCode, modifiers);
+    }
+
     public BlockPos getConsole() {
         return console;
     }
diff --git a/src/main/java/dev/amble/ait/client/screens/LandingPadScreen.java b/src/main/java/dev/amble/ait/client/screens/LandingPadScreen.java
index 499af6594b..39781ad296 100644
--- a/src/main/java/dev/amble/ait/client/screens/LandingPadScreen.java
+++ b/src/main/java/dev/amble/ait/client/screens/LandingPadScreen.java
@@ -3,6 +3,7 @@
 import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
 import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
 
+import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.gui.DrawContext;
 import net.minecraft.client.gui.screen.Screen;
 import net.minecraft.client.gui.widget.ClickableWidget;
@@ -65,6 +66,23 @@ protected void init() {
         super.init();
     }
 
+    @Override
+    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
+        // Check if a text field is focused to prevent closing
+        if (this.landingCodeInput.isActive()) {
+            return super.keyPressed(keyCode, scanCode, modifiers);
+        }
+
+        // Close the screen when the inventory key is pressed
+        if (keyCode == MinecraftClient.getInstance().options.inventoryKey.getDefaultKey().getCode()) {
+            this.close();
+            return true;
+        }
+
+        return super.keyPressed(keyCode, scanCode, modifiers);
+    }
+
+
     private void updateLandingCode() {
         PacketByteBuf buf = PacketByteBufs.create();
         if (this.pos == null) return;
diff --git a/src/main/java/dev/amble/ait/client/screens/TardisSecurityScreen.java b/src/main/java/dev/amble/ait/client/screens/TardisSecurityScreen.java
index c1be8bfc8d..0e8a2e47a7 100644
--- a/src/main/java/dev/amble/ait/client/screens/TardisSecurityScreen.java
+++ b/src/main/java/dev/amble/ait/client/screens/TardisSecurityScreen.java
@@ -40,6 +40,22 @@ public boolean shouldPause() {
         return false;
     }
 
+    @Override
+    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
+        // Check if a text field is focused to prevent closing
+        if (this.landingCodeInput.isActive()) {
+            return super.keyPressed(keyCode, scanCode, modifiers);
+        }
+
+        // Close the screen when the inventory key is pressed
+        if (keyCode == MinecraftClient.getInstance().options.inventoryKey.getDefaultKey().getCode()) {
+            this.close();
+            return true;
+        }
+
+        return super.keyPressed(keyCode, scanCode, modifiers);
+    }
+
     @Override
     protected void init() {
         this.top = (this.height - this.bgHeight) / 2; // this means everythings centered and scaling, same for below


Reviews:
user: login: duzos
body: use `this.close()` instead & edit your PR message to say "closes #1214" in the about
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-03-17T17:27:30Z
user: login: duzos
body: LGTM
state: DISMISSED
author_association: MEMBER
submitted_at: 2025-03-17T17:36:55Z
user: login: duzos
body: LGTM
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-17T17:39:14Z

Review comments:
diff_hunk: @@ -55,6 +56,15 @@ protected void init() {
                 this.textRenderer.getWidth(Text.literal("SEARCH")), 10, Text.literal("SEARCH"), button -> this.switcher.sync(null), this.textRenderer));
     }
 
+    @Override
+    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
+        if (keyCode == MinecraftClient.getInstance().options.inventoryKey.getDefaultKey().getCode()) {
+            MinecraftClient.getInstance().setScreen(null);
path: src/main/java/dev/amble/ait/client/screens/AstralMapScreen.java
user: login: duzos
body: use `this.close()`
created_at: 2025-03-17T17:26:24Z
author_association: MEMBER
diff_hunk: @@ -15,6 +16,15 @@ protected ConsoleScreen(Text title, ClientTardis tardis, BlockPos console) {
         this.console = console;
     }
 
+    @Override
+    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
+        if (keyCode == MinecraftClient.getInstance().options.inventoryKey.getDefaultKey().getCode()) {
+            MinecraftClient.getInstance().setScreen(null);
path: src/main/java/dev/amble/ait/client/screens/ConsoleScreen.java
user: login: duzos
body: `this.close()`
created_at: 2025-03-17T17:26:37Z
author_association: MEMBER
diff_hunk: @@ -65,6 +66,23 @@ protected void init() {
         super.init();
     }
 
+    @Override
+    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
+        // Check if a text field is focused to prevent closing
+        if (this.landingCodeInput.isActive()) {
+            return super.keyPressed(keyCode, scanCode, modifiers);
+        }
+
+        // Close the screen when the inventory key is pressed
+        if (keyCode == MinecraftClient.getInstance().options.inventoryKey.getDefaultKey().getCode()) {
+            MinecraftClient.getInstance().setScreen(null);
path: src/main/java/dev/amble/ait/client/screens/LandingPadScreen.java
user: login: duzos
body: `this.close()`
created_at: 2025-03-17T17:26:48Z
author_association: MEMBER
diff_hunk: @@ -40,6 +40,22 @@ public boolean shouldPause() {
         return false;
     }
 
+    @Override
+    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
+        // Check if a text field is focused to prevent closing
+        if (this.landingCodeInput.isActive()) {
+            return super.keyPressed(keyCode, scanCode, modifiers);
+        }
+
+        // Close the screen when the inventory key is pressed
+        if (keyCode == MinecraftClient.getInstance().options.inventoryKey.getDefaultKey().getCode()) {
+            MinecraftClient.getInstance().setScreen(null);
path: src/main/java/dev/amble/ait/client/screens/TardisSecurityScreen.java
user: login: duzos
body: `this.close()`
created_at: 2025-03-17T17:26:57Z
author_association: MEMBER

PR comments:
user: login: github-actions[bot]
created_at: 2025-03-17T17:25:54Z
body: This pull request has conflicts, please resolve those before we can evaluate the pull request.
author_association: NONE
user: login: MaketendoDev
created_at: 2025-03-17T17:30:26Z
body: huh never knew that exists okay!
author_association: CONTRIBUTOR