Posted November 26, 20177 yr Is there any function besides onItemRightClick() to check keybindings? Like if I want to Shift+RightClick
November 26, 20177 yr You can subscribe to the KeyInputEvent... Edited November 26, 20177 yr by Differentiation
November 26, 20177 yr Author 23 minutes ago, Differentiation said: You can subscribe to the KeyInputEvent... what next? how do I interact with my player inventory or something?
November 26, 20177 yr What are you front to accomplish? That is, what should happen from the user's perspective, nor how are you trying to code it? Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
November 26, 20177 yr 2 hours ago, LavX64 said: what next? how do I interact with my player inventory or something? Well, then you check for the key you want pressed... and then you write your code block... You... interact with... your... inventory... by pressing 'E???' I'M PREEEEETTTTY SURE........... it's built in for Minecraft...................................... Edited November 26, 20177 yr by Differentiation
November 26, 20177 yr 3 minutes ago, Differentiation said: Well, then you check for the key you want pressed... and then you write your code block... You... interact with... your... inventory... by pressing 'E???' I'M PREEEEETTTTY SURE........... it's built in for Minecraft...................................... Did you really not get that? He's asking how to interact with the player inventory from code, because, you know, he's modding.... @OP, Item::onItemRightClick is called when you right click the Item. If you want to check if the player e.g. is sneaking, you can check if Entity::isSneaking. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
November 26, 20177 yr 6 minutes ago, larsgerrits said: Did you really not get that? He's asking how to interact with the player inventory from code, because, you know, he's modding.... Oh... But he can still just subscribe to the KeyInputEvent...
November 26, 20177 yr 11 minutes ago, Differentiation said: But he can still just subscribe to the KeyInputEvent... No, he can't: That only get's posted on the client side You don know which key get pressed You can't interact with anything from there I don know for sure, but I think KeyInputEvent only get's called when there's no Keybinding for that keycode. Edited November 26, 20177 yr by larsgerrits Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
November 26, 20177 yr 3 minutes ago, larsgerrits said: You don know which key get pressed You can interact with anything from there I don know for sure, but I think KeyInputEvent only get's called when there's no Keybinding for that keycode. All wrong except the one I did not quote, and for that you can just send packets... 1. You can check for the pressed key via Keyboard or Minecraft. 2. Yes you can...??? 3. No, it is called for any SPECIFIED pressed key. ex. Minecraft.getMinecraft().gameSettings.keyBindJump.isKeyDown() Minecraft.getMinecraft().gameSettings.keyBindForward.isKeyDown() etc. Edited November 26, 20177 yr by Differentiation
November 26, 20177 yr Example: /* Event fired when specified keys are pressed */ @SubscribeEvent //Subscribes an event with a normal priority public void onKeyInput(KeyInputEvent eventIn) //Method { EntityPlayer playerIn = (EntityPlayer) Minecraft.getMinecraft.thePlayer; //Gets the player instance if (playerIn != null && playerIn instanceof EntityPlayer) //If the entity is existent and it's a player......... { if (Minecraft.getMinecraft().gameSettings.keyBindDrop.isKeyDown()) //Then if Drop key is down........ (BEWARE!!! CLIENT SIDE HERE!!! From here on, server-side = ded, only packets will make it live again!) { playerIn.motionY = 1.0D; // Boing :) (client) PacketHandler.INSTANCE.sendToServer(new MessageExample()); // To the server-side we Gooooo!!!!! (server) KeyBinding.unPressAllKeys(); //Unpress currently pressed keys playerIn.addChatMessage(new TextComponentString("Ya might want'a pick that BACKKKK up!!!!")); } } } Pretty self-explanatory Edited November 26, 20177 yr by Differentiation
November 26, 20177 yr Author 44 minutes ago, Differentiation said: Example: /* Event fired when specified keys are pressed */ @SubscribeEvent //Subscribes an event with a normal priority public void onKeyInput(KeyInputEvent eventIn) //Method { EntityPlayer playerIn = (EntityPlayer) Minecraft.getMinecraft.thePlayer; //Gets the player instance if (playerIn != null && playerIn instanceof EntityPlayer) //If the entity is existent and it's a player......... { if (Minecraft.getMinecraft().gameSettings.keyBindDrop.isKeyDown()) //Then if Drop key is down........ (BEWARE!!! CLIENT SIDE HERE!!! From here on, server-side = ded, only packets will make it live again!) { playerIn.motionY = 1.0D; // Boing :) (client) PacketHandler.INSTANCE.sendToServer(new MessageExample()); // To the server-side we Gooooo!!!!! (server) KeyBinding.unPressAllKeys(); //Unpress currently pressed keys playerIn.addChatMessage(new TextComponentString("Ya might want'a pick that BACKKKK up!!!!")); } } } Pretty self-explanatory Wow this code is just what I needed, ty! I didn't know I can get playerEntity from Minecraft class. And I didn't know about Minecraft.getMinecraft() either
November 26, 20177 yr 1 hour ago, diesieben07 said: Don't just copy random code snippets, please. I never hinted him to copy anything... Yes, I understand why my usage of the event is wrong because I don't use the event at all I don't know, I never subscribed to the event in my coding career anyway
November 26, 20177 yr 3 hours ago, Differentiation said: (BEWARE!!! CLIENT SIDE HERE!!! Uh... 3 hours ago, Differentiation said: public void onKeyInput(KeyInputEvent eventIn) //Method This is where that comment goes. The event itself apparently exists in common code (net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent) but it's only FIRED on the client. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
November 27, 20177 yr 4 hours ago, diesieben07 said: Great, so you posted copy-paste ready code without even understanding it? Even better... Seriously. Actually, I took it from examples on the Modder Support forum... and yes, I do understand it...
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.