Hi, after I pause the game, I want to close the pause menu too.
I use the code below to pause.
Minecraft.getInstance().displayInGameMenu(false);
The game did pause, but I want to close it too, so I tried
mcInstance.displayGuiScreen((Screen)null);
mcInstance.mouseHelper.grabMouse();
And this
mcInstance.currentScreen.keyPressed(256, 0, 0); // press esc
I did manage to close the pause menu, but it has some unexpected behavior.
The problem is that after the GUI was closed, I can't use mouse to pan around, it is acting like it was still in the menu with invisible pointer. I can click I can walk.
I've looked at source code how it was done, and I just repeat it, but it doesn't work ?.
Edited: solved
Turns out I should not interact with Minecraft from different thread. For 1.15.2 to execute task on the main thread, use enqueue instead
Minecraft.getInstance().enqueue(() -> Minecraft.getInstance().displayGuiScreen((Screen)null));