Search in sources :

Example 1 with IMount

use of de.sanandrew.mods.claysoldiers.entity.mount.IMount in project ClaySoldiersMod by SanAndreasP.

the class EntityClayMan method updateEntityActionState.

@Override
protected void updateEntityActionState() {
    // BUGFIX: fixes movement in blocks w/o collision box (snow layer, torches, tall grass, possibly cobweb?, etc.)
    if (!this.hasPath()) {
        if (this.entityToAttack != null) {
            this.setPathToEntity(BugfixHelper.getPathEntityToEntity(this.worldObj, this, this.entityToAttack, 16.0F, true, false, false, true));
        } else if (this.p_targetFollow != null) {
            this.setPathToEntity(BugfixHelper.getPathEntityToEntity(this.worldObj, this, this.p_targetFollow, 16.0F, true, false, false, true));
        } else if ((this.rand.nextInt(180) == 0 || this.rand.nextInt(120) == 0 || this.fleeingTick > 0) && this.entityAge < 100) {
            this.updateWanderPath();
        }
    }
    super.updateEntityActionState();
    if (!this.worldObj.isRemote) {
        this.p_entitiesInRange = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getTargetArea());
        if (this.entityToAttack == null) {
            if (rand.nextInt(4) != 0 && p_targetFollow == null) {
                Collection<EntityClayMan> claymen = this.getSoldiersInRange();
                for (EntityClayMan uberhaxornova : claymen) {
                    if (uberhaxornova.isDead || rand.nextInt(3) != 0) {
                        continue;
                    }
                    if (!this.checkIfValidTarget(uberhaxornova)) {
                        continue;
                    }
                    this.entityToAttack = uberhaxornova;
                    break;
                }
            } else {
                if (this.p_targetFollow == null) {
                    Collection<EntityItem> items = this.getItemsInRange();
                    items: for (EntityItem seamus : items) {
                        if (!this.canEntityBeSeen(seamus)) {
                            continue;
                        }
                        ASoldierUpgrade upgrade = SoldierUpgrades.getUpgrade(seamus.getEntityItem());
                        if (upgrade != null) {
                            if (this.hasUpgrade(upgrade) || !upgrade.canBePickedUp(this, seamus.getEntityItem(), null)) {
                                continue;
                            } else {
                                for (SoldierUpgradeInst upgradeInst : this.p_upgrades.values()) {
                                    if (upgrade == upgradeInst.getUpgrade() || !upgrade.canBePickedUp(this, seamus.getEntityItem(), upgradeInst.getUpgrade())) {
                                        continue items;
                                    }
                                }
                            }
                        } else {
                            continue;
                        }
                        this.p_targetFollow = seamus;
                        break;
                    }
                } else {
                    if (this.p_targetFollow.isDead) {
                        this.p_targetFollow = null;
                    } else if (!this.canEntityBeSeen(this.p_targetFollow)) {
                        this.p_targetFollow = null;
                    }
                    if (this.p_targetFollow instanceof EntityItem && this.p_targetFollow.getDistanceToEntity(this) < 0.5F) {
                        EntityItem itemEntity = (EntityItem) this.p_targetFollow;
                        ASoldierUpgrade upgrade = SoldierUpgrades.getUpgrade(itemEntity.getEntityItem());
                        if (upgrade != null) {
                            this.addUpgrade(upgrade, itemEntity.getEntityItem());
                            if (itemEntity.getEntityItem().stackSize <= 0) {
                                itemEntity.setDead();
                            }
                            this.p_targetFollow = null;
                        }
                    } else if (this.p_targetFollow instanceof IMount) {
                        if (this.p_targetFollow.riddenByEntity != null) {
                            this.p_targetFollow = null;
                        } else if (this.p_targetFollow.getDistanceToEntity(this) < 0.5D) {
                            this.mountEntity(this.p_targetFollow);
                            this.p_targetFollow = null;
                        }
                    }
                }
                if (this.p_targetFollow == null && this.ridingEntity == null) {
                    Collection<IMount> items = this.getMountsInRange();
                    for (IMount mount : items) {
                        EntityLivingBase slyfox = (EntityLivingBase) mount;
                        if (this.rand.nextInt(4) != 0 || !this.canEntityBeSeen(slyfox) || slyfox.riddenByEntity != null) {
                            continue;
                        }
                        this.p_targetFollow = slyfox;
                        break;
                    }
                }
            }
        } else {
            if (this.entityToAttack.isDead || !this.canEntityBeSeen(this.entityToAttack) || (this.entityToAttack instanceof EntityClayMan && !this.checkIfValidTarget((EntityClayMan) this.entityToAttack))) {
                this.entityToAttack = null;
            } else if (this.attackTime == 0) {
                this.attackTime = 5;
                MutableFloat atkRng = new MutableFloat(this.riddenByEntity != null ? 0.6F : 0.7F);
                for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
                    upg.getUpgrade().getAttackRange(this, upg, this.entityToAttack, atkRng);
                }
                if (this.getDistanceToEntity(this.entityToAttack) < atkRng.floatValue() && this.entityToAttack instanceof EntityLivingBase && !this.entityToAttack.isEntityInvulnerable()) {
                    EntityLivingBase target = (EntityLivingBase) this.entityToAttack;
                    if (target.hurtTime == 0) {
                        MutableFloat damage = new MutableFloat(ModConfig.soldierBaseDamage);
                        if (target instanceof EntityClayMan) {
                            EntityClayMan soldierTarget = (EntityClayMan) target;
                            soldierTarget.knockBack = Triplet.with(0.8D, 0.8D, 0.8D);
                            for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
                                upg.getUpgrade().onSoldierAttack(this, upg, soldierTarget, damage);
                            }
                        }
                        if (target.attackEntityFrom(DamageSource.causeMobDamage(this), damage.getValue()) && target instanceof EntityClayMan) {
                            for (SoldierUpgradeInst upg : this.p_upgrades.values()) {
                                upg.getUpgrade().onSoldierDamage(this, upg, (EntityClayMan) target);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) IMount(de.sanandrew.mods.claysoldiers.entity.mount.IMount) ASoldierUpgrade(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SoldierUpgradeInst(de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

IMount (de.sanandrew.mods.claysoldiers.entity.mount.IMount)1 ASoldierUpgrade (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.ASoldierUpgrade)1 SoldierUpgradeInst (de.sanandrew.mods.claysoldiers.util.soldier.upgrade.SoldierUpgradeInst)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 MutableFloat (org.apache.commons.lang3.mutable.MutableFloat)1