use of de.sanandrew.mods.claysoldiers.api.event.SoldierTargetEnemyEvent in project ClaySoldiersMod by SanAndreasP.
the class EntityClaySoldier method attackEntityFrom.
@Override
public boolean attackEntityFrom(DamageSource source, float damage) {
Entity srcEntity = source.getTrueSource();
MutableFloat dmgMutable = new MutableFloat(damage);
this.callUpgradeFunc(EnumUpgFunctions.ON_DAMAGED, inst -> inst.getUpgrade().onDamaged(this, inst, srcEntity, source, dmgMutable));
damage = dmgMutable.floatValue();
if (!(srcEntity instanceof EntityPlayer) && !Objects.equals(source, IDisruptable.DISRUPT_DAMAGE)) {
if (this.getRidingEntity() != null && MiscUtils.RNG.randomInt(4) == 0) {
this.getRidingEntity().attackEntityFrom(source, damage);
return false;
}
if (this.i58O55 != null && this.i58O55) {
damage /= 3.0F;
}
if (source == DamageSource.FALL) {
damage *= 4.0F;
}
} else {
damage = Float.MAX_VALUE;
}
if (super.attackEntityFrom(source, damage)) {
if (Objects.equals(srcEntity, this.getAttackTarget())) {
this.getNavigator().clearPath();
}
if (srcEntity instanceof EntityLivingBase) {
SoldierTargetEnemyEvent evt = new SoldierTargetEnemyEvent(this, (EntityLivingBase) srcEntity, false);
if (!ClaySoldiersMod.EVENT_BUS.post(evt) && evt.getResult() != Event.Result.DENY) {
this.setAttackTarget((EntityLivingBase) srcEntity);
}
}
final float fnlDamage = damage;
this.callUpgradeFunc(EnumUpgFunctions.ON_DAMAGED_SUCCESS, inst -> inst.getUpgrade().onDamagedSuccess(this, inst, srcEntity, source, fnlDamage));
return true;
}
return false;
}
Aggregations