Jump to content

[SOLVED] onItemStoppedBeingHeld event with ItemStack parameter?


hiotewdew

Recommended Posts

I'm looking for a method I can override in the item class to detect when the item is moved, dropped, or not being held by the player anymore. I know onItemDropped exists, but I need one for when it is not being held anymore. Does such a method exist? It also needs itemstack as a parameter (or player and hand)

Edited by hiotewdew
Link to comment
Share on other sites

1 hour ago, hiotewdew said:

when the item is moved

Please define moved. Do you mean changes slots? In the player's inventory only or in any container? If you want any container then the best you can do is subscribe to a tick event, iterate all players, look at their open containers(will be the inventory if the player isn't looking at the GUI at the moment), iterate the stacks in that container and check their slot index against the one on the previous tick. If it changed the item was moved.

Keep in mind that it is pretty much impossible to detect slot changes of the item if it happens without the player present, such as a hopper inserting/extracting an item.

 

1 hour ago, hiotewdew said:

dropped

ItemTossEvent

 

1 hour ago, hiotewdew said:

not being held by the player anymore

Check the current slot of your item each tick, compare it to the slot on the previous tick. If the slot changed and was the held one then it's not being held anymore.

Link to comment
Share on other sites

25 minutes ago, V0idWa1k3r said:

Please define moved. Do you mean changes slots? In the player's inventory only or in any container? If you want any container then the best you can do is subscribe to a tick event, iterate all players, look at their open containers(will be the inventory if the player isn't looking at the GUI at the moment), iterate the stacks in that container and check their slot index against the one on the previous tick. If it changed the item was moved.

Keep in mind that it is pretty much impossible to detect slot changes of the item if it happens without the player present, such as a hopper inserting/extracting an item.

 

ItemTossEvent

 

Check the current slot of your item each tick, compare it to the slot on the previous tick. If the slot changed and was the held one then it's not being held anymore.

Is there a way that doesn't involve checking every tick?

Link to comment
Share on other sites

5 minutes ago, hiotewdew said:

Is there a way that doesn't involve checking every tick?

No, not as far as I am aware. You could check every X ticks I suppose but you might then miss something. Do you have issues with checking every tick? Performance should not be a concern since you are not doing much, just comparing ints.

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.