1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-07-07 20:34:25 +00:00

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.
This commit is contained in:
Jonathan Coates 2021-12-01 20:09:38 +00:00
parent 3929dba4a5
commit 1851ed31cd
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06

View File

@ -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 );