Jump to content

[solved] Detecting key inputs from render event? - 1.15


Turtledove

Recommended Posts

I'm trying to change the way an item renders whether a player has pressed left or right on their keypad, but I'm not sure what the best way of handling this would be. In the hand's render event there isn't really a way to find out which buttons were pressed, and although I could calculate motion depending on the entity's motionZ, this fails when the player has their shoulder against a wall and can't move side to side. It also behaves strangely when the player quickly looks left or right. The best case would be to detect the keypress itself.

 

I could register a capability to the player and set the flag when the key is input in the client, but is there a better and more direct way of doing this?

Edited by Turtledove
Link to comment
Share on other sites

Assuming you mean when the player strafes left and right, there are KeyBinding for those values in GameSettings. If not, create KeyBindings for those values. That's probably the easiest way as KeyBinding has a boolean method that checks if the key is down (for continuous querying) for if the key is pressed (for the initial press of the key).

 

Also, whenever you handle any input from the keyboard, there should be a KeyBinding assuming that its a feature within the modification you are creating.

Link to comment
Share on other sites

5 minutes ago, ChampionAsh5357 said:

Assuming you mean when the player strafes left and right, there are KeyBinding for those values in GameSettings. If not, create KeyBindings for those values. That's probably the easiest way as KeyBinding has a boolean method that checks if the key is down (for continuous querying) for if the key is pressed (for the initial press of the key).

 

Also, whenever you handle any input from the keyboard, there should be a KeyBinding assuming that its a feature within the modification you are creating.

I'm trying to do different animations when the player strafes (i.e. horizontal slashes), and I don't really want to override the vanilla keybinds. In my hand render event handler, I've just done something like: if (currentposX - prevposX >= 0.1F) cancel event, and render my own, this seems to work better but again it doesn't work when the player physically can't move left or right.

Link to comment
Share on other sites

4 minutes ago, ChampionAsh5357 said:

Why would this override vanilla keybinds? You are calling a method from those already declared KeyBindings to see if that KeyBinding is pressed.

How do I get keybinds from an event that doesn't use them for its event?

Link to comment
Share on other sites

3 minutes ago, ChampionAsh5357 said:

Assuming you are checking the values on the logical client side, get the current instance of Minecraft running (if the event doesn't support it use Minecraft#getInstance) and then call GameSettings#keyBindLeft or GameSettings#keyBindRight from the instance within Minecraft.

Ah that's just what I was looking for, thanks.

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.