Use EntityLivingBase#addPotionEffect to add a potion effect to an EntityLivingBase.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Yes, call that method on any EntityLivingBase (e.g. a mob) to add a potion effect to it.
Where you call it from depends on when the potion should be applied.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Where you call it from depends on when the potion should be applied.
If you tell me when the effect should be applied, I can probably tell you where to call the method from.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Is this your own entity class or is it from vanilla/another mod?
If it's your own class, override EntityLiving#onSpawnWithEgg and apply the effect there. If it's not your class, subscribe to EntityJoinWorld, and apply the effect there.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Spiders are always immune to Poison, but you could make your own potion that does the same thing.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Is there a method I can use that can add a potion effect(i.e regeneration) to a hostile mob?
Use EntityLivingBase#addPotionEffect to add a potion effect to an EntityLivingBase.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
/**
* adds a PotionEffect to the entity
*/
public void addPotionEffect(PotionEffect p_70690_1_)
{
if (this.isPotionApplicable(p_70690_1_))
{
if (this.activePotionsMap.containsKey(Integer.valueOf(p_70690_1_.getPotionID())))
{
((PotionEffect)this.activePotionsMap.get(Integer.valueOf(p_70690_1_.getPotionID()))).combine(p_70690_1_);
this.onChangedPotionEffect((PotionEffect)this.activePotionsMap.get(Integer.valueOf(p_70690_1_.getPotionID())), true);
}
else
{
this.activePotionsMap.put(Integer.valueOf(p_70690_1_.getPotionID()), p_70690_1_);
this.onNewPotionEffect(p_70690_1_);
}
}
}
This is what you were talking about correct?
Yes, call that method on any EntityLivingBase (e.g. a mob) to add a potion effect to it.
Where you call it from depends on when the potion should be applied.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Where should I call it from specifically?
If you tell me when the effect should be applied, I can probably tell you where to call the method from.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I think the potion effect should be applied the moment I spawn the mob into the world.
Is this your own entity class or is it from vanilla/another mod?
If it's your own class, override EntityLiving#onSpawnWithEgg and apply the effect there. If it's not your class, subscribe to EntityJoinWorld, and apply the effect there.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Yes, this is for my custom entity class.
I got it to work now.
I have another question. If I wanted to add potion effects to a spider, how can I have it not be immune to its effect?
Spiders are always immune to Poison, but you could make your own potion that does the same thing.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.