Jump to content

onItemLeftClick?


LavX64

Recommended Posts

What are you front to accomplish?  That is, what should happen from the user's perspective, nor how are you trying to code it? 

  • Like 1

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

  • Like 1

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.

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.