Jump to content

Item Mouse Actions


Recommended Posts

Hello Guys!


I'm creating a special Item, which should have a shooting function if you right klick it and a healing function if you left klick it.


Right Klick short: Shoot

Right Klick long: Aim and shoot

Left klick: Heal


The function should be created in a way that you don't have to select a Block or an Entity before klicking, just klick anywhere.


Any Ideas??

Link to comment
Share on other sites

I'm not sure what you mean by click it.

Do you mean having it in the hand and then clicking?

Yes, exactly.

You hold the Item and perform a klick, either with the left mouse-button or with the right one. And both clicks should lead to a single method. But I could only find methods for the event of klicking at a Block... You should be able to klick right into the air, like wit a bow, but also with the left mouse button.


(Hope, everybody understands)


Link to comment
Share on other sites

There are many functions of the Item which you can look into.


If you look into the Item.java class of the minecraft project you will see many methods, look into them and you will find several interesting ones like onItemUse and so on.


If you press Ctrl+Shift+T inside eclipse and type Item you should be able to find the main Item class rather quickly ;)

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites



The code for handling left & right mouse clicks is in Minecraft.tick() --> Minecraft.clickMouse(int button)


A left click goes to EntityLivingBase.swingItem --> item.onEntitySwing(), so you can probably intercept it here, however the code continues on to do all sorts of other left-click things and you might have trouble stopping it - perhaps overwriting Minecraft.objectMouseOver might do the trick.  Depends what you want to do exactly.





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.