use of sanandreasp.mods.ClaySoldiersMod.registry.Upgrades.IUpgradeItem in project ClaySoldiersMod by SanAndreasP.
the class EntityClayMan method updateEntityActionState.
@Override
protected void updateEntityActionState() {
super.updateEntityActionState();
if (!this.worldObj.isRemote) {
if (this.entityToAttack == null) {
List<EntityClayMan> claymen = (List<EntityClayMan>) this.worldObj.getEntitiesWithinAABB(EntityClayMan.class, this.getTargetArea());
for (EntityClayMan uberhaxornova : claymen) {
if (uberhaxornova.getClayTeam() == this.getClayTeam())
continue;
if (uberhaxornova.isDead)
continue;
if (!this.canEntityBeSeen(uberhaxornova))
continue;
if (rand.nextInt(4) != 0)
continue;
this.entityToAttack = uberhaxornova;
for (int id : this.upgrades.keySet()) this.entityToAttack = CSMModRegistry.clayUpgRegistry.getUpgradeByID(id).onTargeting(this, uberhaxornova);
if (this.entityToAttack != null && this.entityToAttack instanceof IUpgradeEntity) {
for (int id2 : ((IUpgradeEntity) this.entityToAttack).getUpgrades()) this.entityToAttack = CSMModRegistry.clayUpgRegistry.getUpgradeByID(id2).onTargeted((IUpgradeEntity) this.entityToAttack, this);
}
break;
}
if (this.entityToAttack == null) {
if (this.targetFollow == null) {
List<EntityItem> items = (List<EntityItem>) this.worldObj.getEntitiesWithinAABB(EntityItem.class, this.getTargetArea());
items: for (EntityItem seamus : items) {
if (!this.canEntityBeSeen(seamus))
continue;
for (IUpgradeItem upgrade : CSMModRegistry.clayUpgRegistry.getUpgrades()) {
if (!CommonUsedStuff.areStacksEqualWithWCV(upgrade.getItemStack(this), seamus.getEntityItem()))
continue;
if (this.upgrades.containsKey(CSMModRegistry.clayUpgRegistry.getIDByUpgrade(upgrade)))
continue;
for (int id : this.upgrades.keySet()) {
if (upgrade.isCompatibleWith(CSMModRegistry.clayUpgRegistry.getUpgradeByID(id)))
continue;
continue items;
}
this.targetFollow = seamus;
break items;
}
}
}
if (this.targetFollow == null && this.ridingEntity == null) {
List<IMount> items = (List<IMount>) this.worldObj.getEntitiesWithinAABB(IMount.class, this.getTargetArea());
for (IMount mount : items) {
if (!(mount instanceof EntityLivingBase))
continue;
if (this.rand.nextInt(4) != 0)
continue;
EntityLivingBase slyfox = (EntityLivingBase) mount;
if (!slyfox.canEntityBeSeen(this))
continue;
if (slyfox.riddenByEntity != null)
continue;
this.targetFollow = slyfox;
break;
}
}
if (this.targetFollow != null) {
if (this.targetFollow.isDead)
this.targetFollow = null;
else if (!this.canEntityBeSeen(this.targetFollow))
this.targetFollow = null;
else if (!hasPath() || rand.nextInt(10) == 0)
setPathToEntity(worldObj.getPathEntityToEntity(this.targetFollow, this, 8.0F, false, false, false, false));
if (this.targetFollow instanceof EntityItem && this.targetFollow.getDistanceToEntity(this) < 0.5F) {
for (IUpgradeItem upgrade : CSMModRegistry.clayUpgRegistry.getUpgrades()) {
if (!CommonUsedStuff.areStacksEqualWithWCV(upgrade.getItemStack(this), ((EntityItem) this.targetFollow).getEntityItem()))
continue;
if (this.upgrades.containsKey(CSMModRegistry.clayUpgRegistry.getIDByUpgrade(upgrade)))
continue;
NBTTagCompound nbt = new NBTTagCompound();
this.upgrades.put(CSMModRegistry.clayUpgRegistry.getIDByUpgrade(upgrade), nbt);
upgrade.onPickup(this, (EntityItem) this.targetFollow, nbt);
this.targetFollow = null;
break;
}
} else if (this.targetFollow instanceof IMount) {
if (this.targetFollow.riddenByEntity != null) {
this.targetFollow = null;
} else if (this.targetFollow.getDistanceToEntity(this) < 0.5D) {
this.mountEntity(this.targetFollow);
this.targetFollow = null;
}
}
}
}
} else {
if (this.entityToAttack.isDead) {
this.entityToAttack = null;
} else {
float atkRng = 0.5F;
for (int id : this.upgrades.keySet()) atkRng = Math.max(CSMModRegistry.clayUpgRegistry.getUpgradeByID(id).getTargetRange(this), atkRng);
if (this.getDistanceToEntity(this.entityToAttack) < atkRng && this.entityToAttack instanceof EntityLivingBase && !this.entityToAttack.isEntityInvulnerable()) {
if (((EntityLivingBase) this.entityToAttack).hurtTime == 0) {
float damage = 1.0F;
List<Integer> currUpgrades = new ArrayList<Integer>(this.upgrades.keySet());
for (int i : currUpgrades) {
IUpgradeItem upg = CSMModRegistry.clayUpgRegistry.getUpgradeByID(i);
damage = upg.onAttack(this, (EntityLivingBase) this.entityToAttack, damage);
}
this.entityToAttack.attackEntityFrom(DamageSource.causeMobDamage(this), damage);
}
}
}
}
}
}
Aggregations