From 1851ed31cdc04517e88b48e5f917fdeeac77bd0c Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Wed, 1 Dec 2021 20:09:38 +0000 Subject: [PATCH] Release keys when opening the offhand pocket computer screen Opening a screen KeyBinding.releaseAll(), which forces all inputs to be considered released. However, our init() function then calls grabMouse(), which calls Keybinding.setAll(), undoing this work. The fix we're going for here is to call releaseAll() one more time[^1] after grabbing the mouse. I think if this becomes any more of a problem, we should roll our own grabMouse which _doesn't_ implement any specific behaviour. Fixes #975 [^1]: Obvious problem here is that we do minecraft.screen=xyz rather than setScreen. We need to - otherwise we'd just hit a stack overflow - but it's not great. --- .../computercraft/client/gui/NoTermComputerScreen.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/dan200/computercraft/client/gui/NoTermComputerScreen.java b/src/main/java/dan200/computercraft/client/gui/NoTermComputerScreen.java index 49f101fb0..05000c837 100644 --- a/src/main/java/dan200/computercraft/client/gui/NoTermComputerScreen.java +++ b/src/main/java/dan200/computercraft/client/gui/NoTermComputerScreen.java @@ -13,6 +13,7 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.IHasContainer; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.IReorderingProcessor; import net.minecraft.util.text.ITextComponent; @@ -43,9 +44,12 @@ public T getMenu() @Override protected void init() { - this.passEvents = true; // to allow gui click events pass through mouseHelper protection (see MouseHelper.OnPres:105 code string) + passEvents = true; // Pass mouse vents through to the game's mouse handler. + // First ensure we're still grabbing the mouse, so the user can look around. Then reset bits of state that + // grabbing unsets. minecraft.mouseHandler.grabMouse(); minecraft.screen = this; + KeyBinding.releaseAll(); super.init(); minecraft.keyboardHandler.setSendRepeatsToGui( true );