Jump to content

[1.6.4] Adding Potion Effect/Damage Value to Player When Hit by Arrow From Mob?


saxon564

Recommended Posts

As the long title says, I am trying to get a mob to shoot an arrow and give the player an effect if hit by the arrow, plus set the damage the player recieves to a custom amount.

 

I know i can add

private EntityAIArrowAttack aiArrowAttack = new EntityAIArrowAttack(this,
		1.0D, 20, 60, 15.0F);

and add that task, but i cannot have it put a potion effect on the player.

 

could someone show me how to do this?

Link to comment
Share on other sites

If you look in net.minecraft.entity.EntityLivingBase, in the method attackEntityFrom(DamageSource, float), you'll see a bunch of qualifying statements checking where the damage is coming from and reacting accordingly (for instance, checking if the damage is fire && the player has a fire resistance potion on --> no damage [return false]).

 

This looks like the best place to me to add your code. Note that EntityAIArrowAttack will reach attackEnitityFrom(...) in the form of a DamageSource object (the float parameter appears to be some sort of damage value?). damageSource.getEntity() will be the mob that shot you. Add in some code that checks whether that mob is the mob you want (using instanceof), then I think you can use this.addPotionEffect(PotionEffect) to put your potion effect on them. "this" will be the EntityLivingBase, so if it's you that's shot, I think it should apply the effect to you.

 

*edit* Are you saying you want the damage of the arrow to be custom, or the damage of the potion? You should be able to set the arrow damage in attackEntityFrom(...) a few lines down from where it determines it should damage the entity, although there might be another way to do it involving that float parameter passed in from whatever called attackEntityFrom(...).

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.