Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Is there any function besides onItemRightClick() to check keybindings? Like if I want to Shift+RightClick

  • Author
23 minutes ago, Differentiation said:

You can subscribe to the KeyInputEvent...

what next? how do I interact with my player inventory or something?

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.

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 by Differentiation

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/

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...

11 minutes ago, Differentiation said:

But he can still just subscribe to the KeyInputEvent...

No, he can't:

  1. That only get's posted on the client side
  2. You don know which key get pressed
  3. You can't interact with anything from there
  4. I don know for sure, but I think KeyInputEvent only get's called when there's no Keybinding for that keycode.

Edited 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/

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 by Differentiation

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 by Differentiation

  • 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

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 :P 

I don't know, I never subscribed to the event in my coding career anyway xD

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.

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.