Jump to content

How do I make something happen when I use my item when not looking at a block?


Recommended Posts

Sounds like you want PlayerInteractEvent.


so i looked at the class file of it, im not too sure how to use it. would this be correct?


public PlayerInteractEvent(EntityPlayer player, Action action, BlockPos pos, EnumFacing face, World world){
if (action == RIGHT_CLICK_AIR) {

Link to comment
Share on other sites

I have a vague memory of #onItemUse being the method called when you right-click on a block, and #onItemRightClick being called only when you clicked in the air... but it's been more than 6 months since I've messed with it, so I could be completely mis-remembering that.


But, if it's not your Item class but someone else's (e.g. vanilla item), then yeah, diesieben is right - use PlayerInteractEvent. There are lots of event tutorials online that cover how to do it in detail, more detail than anyone would want to type here.

Link to comment
Share on other sites

Food items can be used without acting upon a block, so what path do they take? Using the debugger, try to trace the execution path of a vanilla food item being eaten.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.

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.


  • Create New...

Important Information

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