Jump to content

Giving players potion effects when hit by a projectile


Sear_Heat

Recommended Posts

There is no event for when a projectile hits an entity of any type.

 

However. You can use LivingHurtEvent - check if the event's entity (event.entity) is instance of the Player.

If I remember correctly, there is another a field where you can see the damage source, check if the damage source is from the Arrow before giving the entity (Player) a potion effect.

 

 

Link to comment
Share on other sites

Read up tutorials on event handling for Minecraft forge. And yes, event.entity is the entity hurt, and event.source.getEntity() is the entity that caused the damage.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

Not sure what type of projectile you've got going there, but if it extends EntityThrowable then you can override the onImpact method. You can see how vanilla's EntityEnderPearl deals damage to what it hits there.

 

If it's more like an arrow, then perhaps you can override onCollideWithPlayer. Not sure how that will work out, though. EntityArrow does it but only for letting players pick up their arrows again, not to deal damage. You'd probably instead have to override onUpdate and handle the flying through the air and all that yourself (you could mostly copy EntityArrow so it shouldn't be too bad) or use a method like that suggested above.

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.