Posted June 12, 20178 yr Hello community, I'm struggling with the LivingEntityUseItemEvent.Finish-Event... I want to have a reaction, when the player drinks something, so I made a Listener, that listens to the LivingEntityUseItemEvent.Finish. When I call e.getItem(), then it just returns the ItemStack.EMPTY. The e.getResultStack() works well, but the e.getItem() is buggy, I think. It happens, when I drink a potion (the potion probably gets ItemStack.EMPTY for a tick, when the event gets fired, and then it gets the Glass Bottle Item). is that a bug or am I doing something wrong? @SubscribeEvent public void onItemUse(LivingEntityUseItemEvent.Finish e) { System.out.println(e.getItem()); } Edit 1: I forgot to say, that this happens on both Client and Server Side! Edited June 12, 20178 yr by ThexXTURBOXx Bringing the best mod back alive! Our mod REFORGED! Balkon's Weapons for 1.8: https://github.com/TheOnlySilverClaw/Reforged/releases
June 12, 20178 yr You could, of course, just check if the returned itemstack is empty or not, and then check if it is a glass bottle. I'm not exactly sure what it is you want to do here though. So maybe you could give us a little more information about that (:
June 12, 20178 yr Author 51 minutes ago, tommyte said: You could, of course, just check if the returned itemstack is empty or not, and then check if it is a glass bottle. I'm not exactly sure what it is you want to do here though. So maybe you could give us a little more information about that (: That would be a good beginning though I want to code something like a "Thirst"-System. I would need to check, if the ItemStack was exactly a water bottle (with the NBTTagCompound). Some other potions need other values, so it would be good, if there is any way to get the ItemStack, which were there before c: Bringing the best mod back alive! Our mod REFORGED! Balkon's Weapons for 1.8: https://github.com/TheOnlySilverClaw/Reforged/releases
June 12, 20178 yr If you read the javadocs of the LivingEntityUseItemEvent.Finish you will see the following lines: Fired after an item has fully finished being used. The item has been notified that it was used, and the item/result stacks reflect after that state. Note the item/result stacks reflect after that state. part. If you have used the potion the item is indeed an empty stack - as that is what happens to a potion as you drink it. You can make a workaround by subscribing to either Start or Tick subevents, storing the reference to the stack being used somewhere(presumably in a map, just make sure to not leak memory with your keys), removing that reference on the Stop subevent and using that reference as the item being used originally at your Finish subevent handling. Do not forget to clear that map when needed. That is not a perfect solution and if someone suggests a better one you should use theirs.
June 12, 20178 yr Author 28 minutes ago, V0idWa1k3r said: If you read the javadocs of the LivingEntityUseItemEvent.Finish you will see the following lines: Fired after an item has fully finished being used. The item has been notified that it was used, and the item/result stacks reflect after that state. Note the item/result stacks reflect after that state. part. If you have used the potion the item is indeed an empty stack - as that is what happens to a potion as you drink it. You can make a workaround by subscribing to either Start or Tick subevents, storing the reference to the stack being used somewhere(presumably in a map, just make sure to not leak memory with your keys), removing that reference on the Stop subevent and using that reference as the item being used originally at your Finish subevent handling. Do not forget to clear that map when needed. That is not a perfect solution and if someone suggests a better one you should use theirs. Ah, well, I misunderstood the description... Fail... For now, your workaround works pretty well, so I take it until I find out an other method to do this. Thank you Bringing the best mod back alive! Our mod REFORGED! Balkon's Weapons for 1.8: https://github.com/TheOnlySilverClaw/Reforged/releases
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.