Jump to content

[1.11] Which sub-event would I use?


Awesome_Spider

Recommended Posts

I would like to, when the player drinks a water bottle, add hydration to an already attached capability on the player. I found an event called LivingEntityUseItemEvent that has a few sub-events. I think the one I want is Finish but I'm not entirely sure. I want the water bottle to be consumed by the player, but I also want to add to the capability when the player is done drinking it. Would this be the right event?

 

My second question is what is the water bottle called in the Minecraft code? Is it under the potion?

Link to comment
Share on other sites

3 hours ago, Awesome_Spider said:

My second question is what is the water bottle called in the Minecraft code? Is it under the potion?

Yes.

 

Potions use an NBT "Potion" tag to indicate the potion type.

http://minecraft.gamepedia.com/Potion#Data_values

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

LivingEntityUseItemEvent.Finish is fired when an entity finishes using an item (i.e. uses it for its full duration), directly after Item#onItemUseFinish is called. This is probably the event you want.

 

If the entity was using a potion, the stack size will have already been reduced by 1 when the event is fired. If the stack was empty after this (i.e. stack size was reduced to 0), it will have been replaced by an ItemStack of Items.GLASS_BOTTLE.

 

If you want access to the original ItemStack, you'd need to subscribe to LivingEntityUseItemEvent.Tick and store a copy of it (not the original) in a capability attached to the entity (if it's a potion).

 

The PotionUtils class has several methods that read PotionEffects from potion item NBT.

Edited by Choonster
  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.