Posted November 18, 20186 yr 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 January 6, 20196 yr by hiotewdew All Projects found here: Website Main Programmer for: Better Animals Plus, Better Animal Models Created independently: QuickHomes, ClaimIt, ClaimIt API, CloneLand, DerpCats, QuickTeleports, QuickSpawns, MCMusicPlayer, MCDevDate, [SBM] Fluid Gun, OpenScreens Work on/Contribute to: Bewitchment Commissioned for: [SBM] Breadstone, [SBM] Infinite Falling, [SBM] Dead Man's Satchel, [SBM] Handheld Piston
November 18, 20186 yr Not sure if it is the best way, but using onUpdate and checking the stack's slot index may work. May also cause way too much lag... The seven became one and the one became two.
November 18, 20186 yr 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.
November 18, 20186 yr Author 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? All Projects found here: Website Main Programmer for: Better Animals Plus, Better Animal Models Created independently: QuickHomes, ClaimIt, ClaimIt API, CloneLand, DerpCats, QuickTeleports, QuickSpawns, MCMusicPlayer, MCDevDate, [SBM] Fluid Gun, OpenScreens Work on/Contribute to: Bewitchment Commissioned for: [SBM] Breadstone, [SBM] Infinite Falling, [SBM] Dead Man's Satchel, [SBM] Handheld Piston
November 18, 20186 yr 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.
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.