Skip to content

Commit 66eb651

Browse files
authored
fix(GUIMove): restrict Inventory mode to container screens and respect skip() for key suppression (#6726)
1 parent ab3c086 commit 66eb651

1 file changed

Lines changed: 50 additions & 13 deletions

File tree

  • src/main/java/meteordevelopment/meteorclient/systems/modules/movement

‎src/main/java/meteordevelopment/meteorclient/systems/modules/movement/GUIMove.java‎

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import meteordevelopment.meteorclient.events.meteor.KeyInputEvent;
99
import meteordevelopment.meteorclient.events.meteor.MouseClickEvent;
1010
import meteordevelopment.meteorclient.events.render.Render3DEvent;
11+
import meteordevelopment.meteorclient.gui.GuiKeyEvents;
1112
import meteordevelopment.meteorclient.gui.WidgetScreen;
1213
import meteordevelopment.meteorclient.mixin.CreativeModeInventoryScreenAccessor;
1314
import meteordevelopment.meteorclient.settings.*;
@@ -19,7 +20,9 @@
1920
import meteordevelopment.meteorclient.utils.misc.input.KeyAction;
2021
import meteordevelopment.orbit.EventHandler;
2122
import net.minecraft.client.KeyMapping;
23+
import net.minecraft.client.gui.components.EditBox;
2224
import net.minecraft.client.gui.screens.ChatScreen;
25+
import net.minecraft.client.gui.screens.Screen;
2326
import net.minecraft.client.gui.screens.inventory.*;
2427
import net.minecraft.util.Mth;
2528
import net.minecraft.world.item.CreativeModeTabs;
@@ -87,12 +90,26 @@ public enum Screens {
8790
.build()
8891
);
8992

93+
private boolean wasSkipped = true;
94+
9095
public GUIMove() {
9196
super(Categories.Movement, "gui-move", "Allows you to perform various actions while in GUIs.");
9297
}
9398

99+
@Override
100+
public void onActivate() {
101+
wasSkipped = true;
102+
}
103+
94104
@Override
95105
public void onDeactivate() {
106+
wasSkipped = true;
107+
unpress();
108+
}
109+
110+
private void unpress() {
111+
if (mc == null || mc.options == null) return;
112+
96113
mc.options.keyUp.setDown(false);
97114
mc.options.keyDown.setDown(false);
98115
mc.options.keyLeft.setDown(false);
@@ -104,11 +121,11 @@ public void onDeactivate() {
104121
}
105122

106123
public boolean disableSpace() {
107-
return isActive() && jump.get() && mc.options.keyJump.isDefault();
124+
return isActive() && jump.get() && mc.options.keyJump.isDefault() && !skip();
108125
}
109126

110127
public boolean disableArrows() {
111-
return isActive() && arrowsRotate.get();
128+
return isActive() && arrowsRotate.get() && !skip();
112129
}
113130

114131
@EventHandler
@@ -122,7 +139,7 @@ private void onButton(MouseClickEvent event) {
122139
}
123140

124141
private void onInput(int key, KeyAction action) {
125-
if (skip()) return;
142+
if (checkSkip()) return;
126143

127144
pass(mc.options.keyUp, key, action);
128145
pass(mc.options.keyDown, key, action);
@@ -136,7 +153,7 @@ private void onInput(int key, KeyAction action) {
136153

137154
@EventHandler
138155
private void onRender3D(Render3DEvent event) {
139-
if (skip()) return;
156+
if (checkSkip()) return;
140157

141158
float rotationDelta = Math.min((float) (rotateSpeed.get() * event.frameTime * 20f), 100);
142159

@@ -175,15 +192,35 @@ private void pass(KeyMapping bind, int key, KeyAction action) {
175192
if (action == KeyAction.Release) bind.setDown(false);
176193
}
177194

195+
private boolean checkSkip() {
196+
if (skip()) {
197+
if (!wasSkipped) {
198+
wasSkipped = true;
199+
if (mc != null && mc.gui != null && mc.gui.screen() != null) unpress();
200+
}
201+
return true;
202+
}
203+
204+
wasSkipped = false;
205+
return false;
206+
}
207+
178208
public boolean skip() {
179-
if (mc.gui.screen() == null ||
180-
(mc.gui.screen() instanceof CreativeModeInventoryScreen && CreativeModeInventoryScreenAccessor.meteor$getSelectedTab() == CreativeModeTabs.searchTab())
181-
|| mc.gui.screen() instanceof ChatScreen
182-
|| mc.gui.screen() instanceof SignEditScreen
183-
|| mc.gui.screen() instanceof AnvilScreen
184-
|| mc.gui.screen() instanceof AbstractCommandBlockEditScreen
185-
|| mc.gui.screen() instanceof StructureBlockEditScreen) return true;
186-
if (screens.get() == Screens.GUI && !(mc.gui.screen() instanceof WidgetScreen)) return true;
187-
return screens.get() == Screens.Inventory && mc.gui.screen() instanceof WidgetScreen;
209+
return mc == null || mc.gui == null || skip(mc.gui.screen());
210+
}
211+
212+
public boolean skip(Screen screen) {
213+
if (screen == null
214+
|| !GuiKeyEvents.canUseKeys
215+
|| (screen instanceof CreativeModeInventoryScreen && CreativeModeInventoryScreenAccessor.meteor$getSelectedTab() == CreativeModeTabs.searchTab())
216+
|| screen instanceof ChatScreen
217+
|| screen instanceof AbstractSignEditScreen
218+
|| screen instanceof AnvilScreen
219+
|| screen instanceof AbstractCommandBlockEditScreen
220+
|| screen instanceof StructureBlockEditScreen
221+
|| (screen.getFocused() instanceof EditBox editBox && editBox.canConsumeInput())) return true;
222+
if (screens.get() == Screens.GUI) return !(screen instanceof WidgetScreen);
223+
if (screens.get() == Screens.Inventory) return !(screen instanceof AbstractContainerScreen<?>);
224+
return !(screen instanceof WidgetScreen || screen instanceof AbstractContainerScreen<?>);
188225
}
189226
}

0 commit comments

Comments
 (0)