Search in sources :

Example 1 with SoldierTargetEnemyEvent

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;
}
Also used : Entity(net.minecraft.entity.Entity) MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) SoldierTargetEnemyEvent(de.sanandrew.mods.claysoldiers.api.event.SoldierTargetEnemyEvent) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

SoldierTargetEnemyEvent (de.sanandrew.mods.claysoldiers.api.event.SoldierTargetEnemyEvent)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 MutableFloat (org.apache.commons.lang3.mutable.MutableFloat)1