Jump to content

[SOLVED][1.15.2] After called mouseHelper.grabMouse(); it doesn't work.


Zen3515

Recommended Posts

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

 

Edited by Zen3515
Solved
Link to comment
Share on other sites

You might want to try looking at the Robot class (java.awt.Robot, I think). This class allows you to generate input actions that get processed exactly as if the user pressed the key etc. themselves.

Have you ever want the new operator to return a type that you didn't ask for? Well, now you can!

Link to comment
Share on other sites

On 5/14/2020 at 5:36 AM, Vinyarion said:

You might want to try looking at the Robot class (java.awt.Robot, I think). This class allows you to generate input actions that get processed exactly as if the user pressed the key etc. themselves.

 

Sorry for late respond, I cannot use Robot, I tried that, and it says java.awt.AWTException: headless environment during Initialization of the Robot.

On 5/14/2020 at 3:00 PM, diesieben07 said:

Show more of your code. This often happens when you reach across logical sides when interacting with the GUI code.

Also, what are you trying to achieve? Do you just want to pause the game? 

I'm trying to play Minecraft with voice, here are my codes Link to Github

To do that I have to have a way to control Minecraft from another process (Likely by python program)

And for this question specifically, I'm trying to close the pause menu.

 

I forgot to mention that this code run in a new thread, I don't know if that's the cause.

Edited by Zen3515
Clarification
Link to comment
Share on other sites

2 hours ago, diesieben07 said:

Yes, it is. You cannot interact with 99% of things in Minecraft from a different thread. You must do things on the main thread, because things are not threadsafe.

 

How could I accomplish that?

I could not find replacement for addScheduledTask

minecraft.addScheduledTask(() -> minecraft.displayGuiScreen((Screen)null));

 

Edited, so the name become more generic, now it is solved. Thanks.

mcInstance.enqueue(() -> mcInstance.displayGuiScreen((Screen)null));

 

Edited by Zen3515
Solved
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.