Jump to content

[1.11.2] Recommended way of checking KeyBindings for opening a GuiScreen


Recommended Posts

Posted

I recently read somewhere in an answer to an old thread that rarely one should subscribe to KeyInputEvent when handling KeyBindings. That one should subscribe instead to ClientTickEvent. Of course, the answer was fitted to the context of that thread. In my case, in which all I do is open a GuiScreen menu should I subscribe with this

 

@Subscribe
def onKeyInput (keyInputEvent: KeyInputEvent): Unit = {
    // Do my logic here using KeyBinding.isKeyDown()
}



or with this

@Subscribe
def onClientTickEvent (clientTickEvent: ClientTickEvent): Unit = {
    // Do my logic here using KeyBinding.isKeyDown()
}



I have only one KeyBinding, the one for opening the gui.

For my purposes, I currently find no use for the keyInputEvent variable. Also, will subscribing to check for key inputs on the ClientTickEvent consume more processing power than using KeyInputEvent? I somehow feel it does because while I am not moving or doing anything, minecraft would still be checking for the key binding state every tick.

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.