Search in sources :

Example 1 with IPredatorDiet

use of net.tropicraft.core.common.entity.underdasea.atlantoku.IPredatorDiet in project Tropicraft by Tropicraft.

the class EntityAISwimTargetPrey method updateTask.

@Override
public void updateTask() {
    super.updateTask();
    // Target selection
    if (entity.ticksExisted % 80 == 0 && entity.aggressTarget == null || !entity.world.loadedEntityList.contains(entity.aggressTarget)) {
        List<Entity> list = entity.world.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().grow(20D, 20D, 20D).offset(0.0D, -8.0D, 0.0D), EntitySelectors.IS_ALIVE);
        if (list.size() > 0) {
            Entity ent = list.get(rand.nextInt(list.size()));
            boolean skip = false;
            if (ent.equals(entity))
                skip = true;
            if (ent.getClass().getName().equals(entity.getClass().getName()))
                skip = true;
            if (entity instanceof IPredatorDiet) {
                Class[] prey = ((IPredatorDiet) entity).getPreyClasses();
                boolean contains = false;
                for (int i = 0; i < prey.length; i++) {
                    if (prey[i].getName().equals(ent.getClass().getName())) {
                        contains = true;
                    }
                }
                if (!contains) {
                    skip = true;
                }
            }
            if (!ent.isInWater())
                skip = true;
            if (!entity.canEntityBeSeen(ent))
                skip = true;
            if (!skip) {
                if (ent instanceof EntityLivingBase) {
                    if (((EntityLivingBase) ent).isInWater()) {
                        entity.aggressTarget = ent;
                    }
                }
            }
        }
    }
    if (rand.nextInt(200) == 0) {
        entity.aggressTarget = null;
        entity.setRandomTargetHeading();
    }
    // Hunt Target and/or Do damage
    if (entity.aggressTarget != null) {
        if (entity.getDistanceSq(entity.aggressTarget) <= entity.width) {
            if (entity.aggressTarget instanceof EntityLivingBase) {
                ((EntityLivingBase) entity.aggressTarget).attackEntityFrom(DamageSource.causeMobDamage(entity), entity.attackDamage);
            }
            if (entity.aggressTarget instanceof EntityTropicraftWaterBase) {
                if (entity.getEntityBoundingBox().maxY - entity.getEntityBoundingBox().minY > entity.aggressTarget.getEntityBoundingBox().maxY - entity.aggressTarget.getEntityBoundingBox().minY) {
                    ((EntityTropicraftWaterBase) entity.aggressTarget).setExpRate(0);
                    entity.aggressTarget.setDropItemsWhenDead(false);
                    entity.aggressTarget.setDead();
                    entity.heal(1);
                    entity.eatenFishAmount++;
                }
            }
            entity.setRandomTargetHeading();
        } else {
            if (entity.canEntityBeSeen(entity.aggressTarget) && entity.ticksExisted % 20 == 0) {
                entity.setTargetHeading(entity.aggressTarget.posX, entity.aggressTarget.posY, entity.aggressTarget.posZ, true);
            }
        }
        if (entity.aggressTarget != null) {
            if (!entity.canEntityBeSeen(entity.aggressTarget) || !entity.aggressTarget.isInWater()) {
                entity.aggressTarget = null;
                entity.setRandomTargetHeading();
            }
        }
    }
    if (!entity.world.loadedEntityList.contains(entity.aggressTarget) || entity.aggressTarget.isDead) {
        entity.aggressTarget = null;
        entity.setRandomTargetHeading();
    }
}
Also used : Entity(net.minecraft.entity.Entity) IPredatorDiet(net.tropicraft.core.common.entity.underdasea.atlantoku.IPredatorDiet) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityTropicraftWaterBase(net.tropicraft.core.common.entity.underdasea.atlantoku.EntityTropicraftWaterBase)

Example 2 with IPredatorDiet

use of net.tropicraft.core.common.entity.underdasea.atlantoku.IPredatorDiet in project Tropicraft by Tropicraft.

the class EntityAISwimAvoidPredator method updateTask.

@Override
public void updateTask() {
    super.updateTask();
    if (!entity.isAggressing && (entity.ticksExisted) % 20 == 0) {
        List<EntityTropicraftWaterBase> ents = entity.world.getEntitiesWithinAABB(EntityTropicraftWaterBase.class, new AxisAlignedBB(entity.getPosition()).grow(distanceToAvoid));
        for (int i = 0; i < ents.size(); i++) {
            EntityTropicraftWaterBase f = ents.get(i);
            if (entity.getDistanceSq(f) < this.distanceToAvoid && entity.canEntityBeSeen(f)) {
                if (f.aggressTarget != null) {
                    if (f.aggressTarget.equals(entity)) {
                        entity.fleeEntity(f);
                        entity.isPanicking = true;
                        // System.out.println("Avoiding!");
                        break;
                    }
                }
                if (f instanceof IPredatorDiet) {
                    if (Arrays.asList(((IPredatorDiet) f).getPreyClasses()).contains(entity.getClass())) {
                        entity.fleeEntity(f);
                        entity.isPanicking = true;
                        break;
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IPredatorDiet(net.tropicraft.core.common.entity.underdasea.atlantoku.IPredatorDiet) EntityTropicraftWaterBase(net.tropicraft.core.common.entity.underdasea.atlantoku.EntityTropicraftWaterBase)

Aggregations

EntityTropicraftWaterBase (net.tropicraft.core.common.entity.underdasea.atlantoku.EntityTropicraftWaterBase)2 IPredatorDiet (net.tropicraft.core.common.entity.underdasea.atlantoku.IPredatorDiet)2 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1