Posted June 15, 201411 yr What code should I add to a projectile to make it give a hit player a potion effect? Developer of the WIP Rubies mod.
June 15, 201411 yr 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.
June 15, 201411 yr Author Ok, but what is LivingHurtEvent? I can't seem to find a class or a (static) method by that name. Developer of the WIP Rubies mod.
June 15, 201411 yr 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.
June 15, 201411 yr 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.
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.