Search in sources :

Example 1 with IMount

use of sanandreasp.mods.ClaySoldiersMod.entity.mount.IMount in project ClaySoldiersMod by SanAndreasP.

the class EntityClayNexus method isMaxSpawningReached.

private boolean isMaxSpawningReached() {
    List<Entity> el = worldObj.loadedEntityList;
    int count = 0;
    for (Entity entity : el) {
        if (entity instanceof EntityClayMan) {
            if (((EntityClayMan) entity).getClayTeam() == getColor() && ((EntityClayMan) entity).spawnedFromNexus())
                count++;
        } else if (getSpawnMount() && (entity instanceof IMount) && ((IMount) entity).getType() == nexusIS[1].getItemDamage()) {
            if (entity instanceof EntityPegasus && nexusIS[1].getItem() instanceof ItemHorses && ((ItemHorses) nexusIS[1].getItem()).horseType == 1) {
                count++;
            } else if (entity instanceof EntityHorse && nexusIS[1].getItem() instanceof ItemHorses && ((ItemHorses) nexusIS[1].getItem()).horseType == 0) {
                count++;
            } else if (entity instanceof EntityTurtle && nexusIS[1].getItem() instanceof ItemTurtle) {
                count++;
            } else if (entity instanceof EntityBunny && nexusIS[1].getItem() instanceof ItemBunny) {
                count++;
            } else if (entity instanceof EntityGecko && nexusIS[1].getItem() instanceof ItemGecko) {
                count++;
            }
        }
    }
    return count >= getMaxLvngSoldiers();
}
Also used : Entity(net.minecraft.entity.Entity) ItemTurtle(sanandreasp.mods.ClaySoldiersMod.item.ItemTurtle) EntityPegasus(sanandreasp.mods.ClaySoldiersMod.entity.mount.EntityPegasus) ItemHorses(sanandreasp.mods.ClaySoldiersMod.item.ItemHorses) EntityTurtle(sanandreasp.mods.ClaySoldiersMod.entity.mount.EntityTurtle) ItemBunny(sanandreasp.mods.ClaySoldiersMod.item.ItemBunny) ItemGecko(sanandreasp.mods.ClaySoldiersMod.item.ItemGecko) EntityHorse(sanandreasp.mods.ClaySoldiersMod.entity.mount.EntityHorse) IMount(sanandreasp.mods.ClaySoldiersMod.entity.mount.IMount) EntityGecko(sanandreasp.mods.ClaySoldiersMod.entity.mount.EntityGecko) EntityBunny(sanandreasp.mods.ClaySoldiersMod.entity.mount.EntityBunny)

Example 2 with IMount

use of sanandreasp.mods.ClaySoldiersMod.entity.mount.IMount 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);
                    }
                }
            }
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ArrayList(java.util.ArrayList) IMount(sanandreasp.mods.ClaySoldiersMod.entity.mount.IMount) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ArrayList(java.util.ArrayList) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) IUpgradeEntity(sanandreasp.mods.ClaySoldiersMod.registry.Upgrades.IUpgradeEntity) IUpgradeItem(sanandreasp.mods.ClaySoldiersMod.registry.Upgrades.IUpgradeItem) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

IMount (sanandreasp.mods.ClaySoldiersMod.entity.mount.IMount)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 EntityBunny (sanandreasp.mods.ClaySoldiersMod.entity.mount.EntityBunny)1 EntityGecko (sanandreasp.mods.ClaySoldiersMod.entity.mount.EntityGecko)1 EntityHorse (sanandreasp.mods.ClaySoldiersMod.entity.mount.EntityHorse)1 EntityPegasus (sanandreasp.mods.ClaySoldiersMod.entity.mount.EntityPegasus)1 EntityTurtle (sanandreasp.mods.ClaySoldiersMod.entity.mount.EntityTurtle)1 ItemBunny (sanandreasp.mods.ClaySoldiersMod.item.ItemBunny)1 ItemGecko (sanandreasp.mods.ClaySoldiersMod.item.ItemGecko)1 ItemHorses (sanandreasp.mods.ClaySoldiersMod.item.ItemHorses)1 ItemTurtle (sanandreasp.mods.ClaySoldiersMod.item.ItemTurtle)1 IUpgradeEntity (sanandreasp.mods.ClaySoldiersMod.registry.Upgrades.IUpgradeEntity)1 IUpgradeItem (sanandreasp.mods.ClaySoldiersMod.registry.Upgrades.IUpgradeItem)1