Posted May 9, 20205 yr 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 May 9, 20205 yr by Turtledove
May 9, 20205 yr 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.
May 9, 20205 yr Author 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.
May 9, 20205 yr 10 minutes ago, Turtledove said: and I don't really want to override the vanilla keybinds Why would this override vanilla keybinds? You are calling a method from those already declared KeyBindings to see if that KeyBinding is pressed.
May 9, 20205 yr Author 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?
May 9, 20205 yr 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.
May 9, 20205 yr Author 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.
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.