Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (67 sloc) 2.33 KB
List<Entity> targetList; // The aabb list
List<Entity> friendlyList = new ArrayList<>(); // The friendly list that this entity should ignore selecting as its target
List<Entity> enemyList = new ArrayList<>(); // The enemy list that this entity should choose from
protected boolean canTarget; // A boolean that turns true if the enemy list isn't empty
public EntityUndead(World worldIn)
{
super(worldIn);
this.setSize(0.8F, 2F);
this.experienceValue = 3;
}
@Override
public void setAttackTarget(EntityLivingBase entitylivingbaseIn)
{
if (this.canTarget)
{
this.enemyList.removeAll(this.friendlyList);
Entity enemy = (Entity) this.enemyList.get(0);
double d0 = this.getDistanceSqToEntity((Entity) enemy);
EntityLivingBase entityToAttack = (EntityLivingBase) enemy;
if (d0 < 30.0D && d0 > 0)
{
entitylivingbaseIn = (EntityLivingBase) enemy;
super.setAttackTarget(entitylivingbaseIn);
}
else
{
super.setAttackTarget(null);
}
}
}
@Override
protected void updateAITasks()
{
this.targetList = this.world.getEntitiesWithinAABBExcludingEntity(this, new AxisAlignedBB((double)this.posX - 17.5D, (double)this.posY - 17.5D, (double)this.posZ - 17.5D, (double)this.posX + 17.5D, (double)this.posY + 17.5D, (double)this.posZ + 17.5D));
if (this.getAttackTarget() == null && this.isAlly())
{
for (Entity entity : this.targetList)
{
if (entity instanceof EntityUndead && ((EntityUndead) entity).isAlly() && !this.friendlyList.contains(entity))
{
this.friendlyList.add(entity);
}
if (entity instanceof EntityPlayerMP && !this.friendlyList.contains(entity))
{
this.friendlyList.add(entity);
}
}
for (Entity entity : this.friendlyList)
{
if (entity.isDead)
{
this.friendlyList.remove(entity);
}
}
}
this.targetList.removeAll(this.friendlyList);
this.enemyList.clear();
this.enemyList.addAll(this.targetList);
if (!this.enemyList.isEmpty())
{
this.canTarget = true;
}
else if (this.enemyList.isEmpty())
{
this.canTarget = false;
}
}