Jump to content

[1.8] Detecting right click while shifting with item in hand...


dev909

Recommended Posts

I have an item and block that interact with each other just fine. I want to add a little bit more functionality by giving the item another 'mode' aka change behavior if the player is sneaking. So I added an if else block into my code to see if player is sneaking, and then do stuff. However in game my debug code will not fire if I'm sneaking and clicking on the block with the item. When I switch to an empty hand, the debug code fires and then it crashes (because the clause with the logic for sneaking is supposed to be using a certain item, not an empty hand). So this is making me wonder if it is possible to right click a block, while sneaking, with a specific item?

 

All code is done within the block's onBlockActivated() method.

Link to comment
Share on other sites

When you hold an item in your hand right clicking on a block effectively overrides the items onActivated with the blocks onActivated when you are sneaking the items onActivated effectively overrides the blocks onActivated.

 

So you want a sneak right click interaction you have to put that code in your items onActivated.

 

BTW the method probably isn't actually call onActivated but I don't recall the actual name right now.

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

Method is onItemUse(), and it works perfectly, thanks!

 

As a side query, is there any benefit of having the original code in the blocks use method and the sneaking code in the items use method, compared to having all the code in the items use method? Besides for having cleaner looking code?

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.