mojira.dev
MC-183776

After switching game modes using F3+F4, you need to press F3 twice to toggle the debug screen

The Bug

For some very odd reason you need to click F3 twice now if you change gamemodes this way. Doesn't affect commands. Very good UI for the new gamemode screen I have to say, good work Mojang!

Steps to Reproduce

  • Open the gamemode switcher and switch into any gamemode. (Hold F3 and press F4 to bring up this menu and to navigate between gamemodes).

  • Hit the F3 key in an attempt to enable the debug menu.

  • Take note of whether the F3 debug menu is enabled.

  • Hit the F3 key again.

  • Take note as to whether or not the F3 debug menu is now enabled.

Observed Behavior

After using the gamemode switcher, you are required to press the F3 key twice in order to enable the debug menu.

Expected Behavior

After using the gamemode switcher, you would not be required to press the F3 key twice in order to enable the debug menu. Instead, you should only have to press the F3 key once in order to enable the debug menu after using the gamemode switcher.

Code analysis

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 35

I often noticed that F3 sometimes didn’t toggle debug screen, now I finally know when it happens.

Confirmed for 1.16 Prerelease 1

Confirmed in 1.16 Pre-release 6.

25 more comments

Confirmed for 23w40a

Affects 1.21 Pre-release 3

Affects 1.21 Pre-release 4

Affects 1.21 and the Release Candidate 1

The fix by @TriWonder81 resolves the bug, but it creates a new one:
When pressing F3+F4+ESC and then releasing F3, the debug menu will open, which doesn't happen without the fix. This occurs because when pressing F3+F4, this.switchF3State is set to false, but when pressing ESC to exit the screen, this.switchF3State isn't changed, which means the F3 menu will open when F3 is released.

Both the initial and the new bug can be fixed by adding setSwitchF3State method to net.minecraft.client.Keyboard.java:

public void setSwitchF3State(boolean switchF3State) {
    this.switchF3State = switchF3State; 
}

and changing switchF3State in checkForClose method of net.minecraft.client.gui.screen.GameModeSelectionScreen.java:

private boolean checkForClose() {
    if (!InputUtil.isKeyPressed(this.client.getWindow().getHandle(), GLFW.GLFW_KEY_F3)) {
        this.apply();
        this.client.setScreen(null);
        this.client.keyboard.setSwitchF3State(false); // added
        return true;
    } else {
        return false;
    }
}

so, when GameModeSelectionScreen closes by releasing F3, switchF3State is set to false, otherwise, when ESC is pressed, it is true.

JaloSenpai

Filip Randenbäck

Confirmed

Platform

Normal

Debug, Input

game-mode-switch

20w20a, 20w20b, 20w21a, 20w22a, 1.16 Pre-release 1, ..., 1.21, 24w34a, 24w45a, 24w46a, 1.21.5 Release Candidate 1

25w31a

Retrieved