Search in sources :

Example 6 with EntityTropicraftWaterBase

use of net.tropicraft.core.common.entity.underdasea.atlantoku.EntityTropicraftWaterBase 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)6 Entity (net.minecraft.entity.Entity)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 IPredatorDiet (net.tropicraft.core.common.entity.underdasea.atlantoku.IPredatorDiet)2 MessagePlayerSwimData (net.tropicraft.core.common.network.MessagePlayerSwimData)2 PlayerSwimData (net.tropicraft.core.common.network.MessagePlayerSwimData.PlayerSwimData)2 ArrayList (java.util.ArrayList)1 RenderManager (net.minecraft.client.renderer.entity.RenderManager)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 EntityBeachFloat (net.tropicraft.core.common.entity.placeable.EntityBeachFloat)1