Program: 34733
Project: 34733
Buggy source:
@Override public void onLivingUpdate(){
  entityAge=0;
  if (worldObj.isRemote) {
    refreshRoles();
    int chance=1 + (int)Math.floor(HardcoreEnderExpansion.proxy.getClientSidePlayer().getDistanceToEntity(this) / 20F);
    if (rand.nextInt(chance) == 0) {
      float colFactor=rand.nextFloat() * 0.6F + 0.4F;
      HardcoreEnderExpansion.fx.portalColor(worldObj,posX + (rand.nextDouble() - 0.5D) * width,posY + rand.nextDouble() * height - 0.25D,posZ + (rand.nextDouble() - 0.5D) * width,(rand.nextDouble() - 0.5D) * 2D,-rand.nextDouble(),(rand.nextDouble() - 0.5D) * 2D,colFactor * 0.9F,colFactor * 0.3F,colFactor);
      if (homelandRole != null && rand.nextInt(3) == 0) {
        HardcoreEnderExpansion.fx.portalColor(worldObj,posX + (rand.nextDouble() - 0.5D) * width,posY + rand.nextDouble() * height - 0.25D,posZ + (rand.nextDouble() - 0.5D) * width,(rand.nextDouble() - 0.5D) * 2D,-rand.nextDouble(),(rand.nextDouble() - 0.5D) * 2D,homelandRole.red,homelandRole.green,homelandRole.blue);
      }
      if (overtakeGroupRole != null && rand.nextInt(7) == 0) {
        HardcoreEnderExpansion.fx.portalColor(worldObj,posX + (rand.nextDouble() - 0.5D) * width,posY + rand.nextDouble() * height - 0.25D,posZ + (rand.nextDouble() - 0.5D) * width,(rand.nextDouble() - 0.5D) * 2D,-rand.nextDouble(),(rand.nextDouble() - 0.5D) * 2D,0.3F,0.3F,0.3F);
      }
    }
  }
 else   if (isEntityAlive()) {
    if (isWet())     attackEntityFrom(DamageSource.drown,1F);
    if (isWet() || isBurning()) {
      setTarget(null);
      setScreaming(false);
    }
    if (!onGround && ++fallTimer > 17 + rand.nextInt(15)) {
      fallTimer=0;
      for (int attempt=0; attempt < 500; attempt++) {
        if (teleportRandomly(48D)) {
          resetTask();
          break;
        }
      }
    }
    prevTeleportAttempt=null;
    if (attackedRecentlyTimer > 0)     attackedRecentlyTimer-=rand.nextInt(2);
    long overtakeGroup=HomelandEndermen.getOvertakeGroup(this);
    if (currentTask == EndermanTask.WAIT || currentTask == EndermanTask.GET_TNT) {
      moveForward=moveStrafing=0F;
      fallDistance=0F;
      fallTimer=0;
      posY=10000D;
      if (--currentTaskTimer == 0) {
        int tpX, tpY, tpZ;
        for (int attempt=0; attempt < 100; attempt++) {
          tpX=(int)Math.floor(posX) + rand.nextInt(41) - 20;
          tpZ=(int)Math.floor(posZ) + rand.nextInt(41) - 20;
          tpY=worldObj.getTopSolidOrLiquidBlock(tpX,tpZ) - 1;
          if (worldObj.getBlock(tpX,tpY,tpZ) == BlockList.end_terrain) {
            teleportTo(tpX + 0.3D + rand.nextDouble() * 0.4D,tpY + 1D,tpZ + 0.3D + rand.nextDouble() * 0.4D,true);
            PacketPipeline.sendToAllAround(this,256D,new C20Effect(FXType.Basic.HOMELAND_ENDERMAN_TP_OVERWORLD,this));
            if (overtakeGroupRole == OvertakeGroupRole.CHAOSMAKER) {
              setCarrying(new ItemStack(Blocks.tnt));
            }
 else             if (homelandRole == HomelandRole.COLLECTOR && rand.nextInt(4) != 0) {
              setCarrying(new ItemStack(endermanBlockList[rand.nextInt(endermanBlockList.length)]));
            }
            break;
          }
        }
        resetTask();
      }
    }
    if (overtakeGroup == -1) {
      if (currentTask != EndermanTask.NONE && currentTask != EndermanTask.WAIT) {
        --currentTaskTimer;
        if (currentTask == EndermanTask.LISTEN_TO_RECRUITER || currentTask == EndermanTask.RECRUIT_TO_GROUP) {
          moveForward=moveStrafing=0F;
          if (currentTaskTimer == 0 && currentTask == EndermanTask.RECRUIT_TO_GROUP) {
            int chance=50, reportChance=10;
            EntityMobHomelandEnderman target=(EntityMobHomelandEnderman)currentTaskData;
switch (target.homelandRole) {
case WORKER:
              chance=30;
            break;
case GUARD:
          chance=15;
        reportChance=35;
      break;
case INTELLIGENCE:
    chance=80;
  reportChance=22;
break;
case BUSINESSMAN:
chance=40;
reportChance=14;
break;
default :
}
if (rand.nextInt(100) < chance) {
target.setGroupMember(groupId,OvertakeGroupRole.getRandomMember(rand));
PacketPipeline.sendToAllAround(this,64D,new C21EffectEntity(FXType.Entity.HOMELAND_ENDERMAN_RECRUIT,this));
PacketPipeline.sendToAllAround(this,64D,new C21EffectEntity(FXType.Entity.HOMELAND_ENDERMAN_RECRUIT,target));
for (int attempt=0; attempt < 50; attempt++) {
if (teleportRandomly()) break;
}
}
 else if (rand.nextInt(100) < reportChance) {
boolean escaped=false;
double oldX=posX, oldY=posY, oldZ=posZ;
if (rand.nextInt(5) != 0) {
for (int attempt=0; attempt < 20; attempt++) {
if (teleportRandomly()) {
escaped=true;
break;
}
}
}
List<EntityMobHomelandEnderman> guards=HomelandEndermen.getByHomelandRole(this,HomelandRole.GUARD);
for (int a=0, amt=Math.max(3,(int)Math.round(guards.size() * 0.3D)); a < amt; a++) {
EntityMobHomelandEnderman guard=guards.get(rand.nextInt(guards.size()));
guard.setScreaming(true);
PacketPipeline.sendToAllAround(this,256D,new C22EffectLine(FXType.Line.HOMELAND_ENDERMAN_GUARD_CALL,target,guard));
if (!escaped) guard.setTarget(this);
 else if (rand.nextInt(4) != 0) guard.teleportTo(oldX + 4D * (rand.nextDouble() - 0.5D),oldY + 2D + rand.nextDouble() * 4D,oldZ + 4D * (rand.nextDouble() - 0.5D));
}
}
recruitCooldown=120;
}
}
 else if (currentTask == EndermanTask.STROLL) {
if (currentTaskTimer > 0 && currentTaskTimer < 20 && rand.nextInt(3) == 0) {
Vec3 obj=(Vec3)currentTaskData;
if ((obj.distanceTo(Vec3.createVectorHelper(posX,posY,posZ)) <= 0.5D || rand.nextInt(10) == 0) && randomTpTimer > 30) {
for (int attempt=0; attempt < 30; attempt++) {
if (teleportRandomly(48D)) {
currentTaskData=Vec3.createVectorHelper(posX,posY,posZ);
randomTpTimer-=40 + rand.nextInt(30);
break;
}
}
}
}
if (currentTaskTimer == 0 && rand.nextInt(5) == 0) {
currentTaskTimer=10 + rand.nextInt(60);
}
}
 else if (currentTask == EndermanTask.WALK) {
ChunkPosition pos=(ChunkPosition)currentTaskData;
if (MathUtil.distance(posX - pos.chunkPosX,posY - pos.chunkPosY,posZ - pos.chunkPosZ) < 3D) resetTask();
}
 else if (currentTask == EndermanTask.COMMUNICATE) {
moveForward=moveStrafing=0F;
}
if (currentTaskTimer <= 0) resetTask();
}
 else if (entityToAttack == null) {
if (groupId != -1 && rand.nextInt(400) == 0 && (recruitCooldown < -120 || --recruitCooldown < -120)) {
List<EntityMobHomelandEnderman> total=HomelandEndermen.getAll(this);
int groupAmt=HomelandEndermen.getInSameGroup(this).size();
int totalAmt=total.size();
if (totalAmt > 8 && (rand.nextInt(5) <= 2 || groupAmt < (totalAmt >> 2) + rand.nextInt(totalAmt >> 3) - rand.nextInt(4))) {
for (int attempt=0; attempt < 5; attempt++) {
EntityMobHomelandEnderman enderman=total.get(rand.nextInt(totalAmt));
if (enderman == this || enderman.groupId != -1 || !enderman.onGround || enderman.homelandRole == HomelandRole.ISLAND_LEADERS || enderman.getDistanceToEntity(this) > 80D) continue;
if (groupAmt > 3 && ((enderman.homelandRole == HomelandRole.GUARD || enderman.homelandRole == HomelandRole.WORKER) && rand.nextInt(5) != 0)) continue;
boolean tp=false;
for (int tpAttempt=0; tpAttempt < 30; tpAttempt++) {
if (teleportTo(enderman.posX + (rand.nextDouble() - 0.5D) * 2D,enderman.posY,enderman.posZ + (rand.nextDouble() - 0.5D) * 2D)) {
tp=true;
break;
}
}
if (!tp) continue;
currentTask=EndermanTask.RECRUIT_TO_GROUP;
currentTaskData=enderman;
enderman.currentTask=EndermanTask.LISTEN_TO_RECRUITER;
enderman.currentTaskTimer=currentTaskTimer=20 + rand.nextInt(60);
break;
}
}
}
if (currentTask == EndermanTask.NONE && rand.nextInt(80) == 0) {
switch (homelandRole) {
case ISLAND_LEADERS:
if (rand.nextInt(13) == 0) {
teleportRandomly();
}
 else {
Vec3 look=getLookVec();
for (int attempt=0, pathX, pathY, pathZ; attempt < 12; attempt++) {
if (attempt > 8 || rand.nextInt(6) == 0) look=Vec3.createVectorHelper(rand.nextDouble() - 0.5D,0D,rand.nextDouble() - 0.5D).normalize();
pathX=(int)(posX + look.xCoord * 16D + (rand.nextDouble() - 0.5D) * 5D);
pathZ=(int)(posZ + look.zCoord * 16D + (rand.nextDouble() - 0.5D) * 5D);
pathY=worldObj.getTopSolidOrLiquidBlock(pathX,pathZ) - 1;
if (worldObj.getBlock(pathX,pathY,pathZ) == BlockList.end_terrain && MathUtil.distance(posX - pathX,posY - pathY,posZ - pathZ) > 5D) {
setPathToEntity(worldObj.getEntityPathToXYZ(this,pathX,pathY + 1,pathZ,30F,true,false,false,true));
currentTask=EndermanTask.STROLL;
currentTaskTimer=65 + rand.nextInt(60);
currentTaskData=Vec3.createVectorHelper(posX,posY,posZ);
break;
}
}
}
break;
case BUSINESSMAN:
if (rand.nextInt(18) == 0) {
List<EntityMobHomelandEnderman> businessmen=HomelandEndermen.getByHomelandRole(this,HomelandRole.BUSINESSMAN);
if (!businessmen.isEmpty()) {
EntityMobHomelandEnderman enderman=businessmen.get(rand.nextInt(businessmen.size()));
if (enderman.currentTask == EndermanTask.NONE) {
for (int tpAttempt=0; tpAttempt < 20; tpAttempt++) {
if (teleportTo(enderman.posX + (rand.nextDouble() - 0.5D) * 2D,enderman.posY,enderman.posZ + (rand.nextDouble() - 0.5D) * 2D)) {
currentTask=enderman.currentTask=EndermanTask.COMMUNICATE;
currentTaskTimer=enderman.currentTaskTimer=30 + rand.nextInt(50 + rand.nextInt(80));
break;
}
}
}
}
}
 else if (rand.nextInt(10) == 0) {
int walkToX, walkToY, walkToZ;
for (int attempt=0; attempt < 10; attempt++) {
walkToX=(int)posX + rand.nextInt(251) - 125;
walkToZ=(int)posZ + rand.nextInt(251) - 125;
walkToY=worldObj.getTopSolidOrLiquidBlock(walkToX,walkToZ) - 1;
if (worldObj.getBlock(walkToX,walkToY,walkToZ) == BlockList.end_terrain) {
setPathToEntity(worldObj.getEntityPathToXYZ(this,walkToX,walkToY + 1,walkToZ,100F,true,false,false,true));
currentTask=EndermanTask.WALK;
currentTaskTimer=200 + rand.nextInt(100);
currentTaskData=new ChunkPosition(walkToX,walkToY,walkToZ);
break;
}
}
}
break;
case WORKER:
if (rand.nextInt(270) == 0 && worldObj.getBlock((int)Math.floor(posX),(int)Math.floor(posY) + 1,(int)Math.floor(posZ)) != BlockList.ender_goo) {
for (int attempt=0, tpX, tpY, tpZ; attempt < 50; attempt++) {
tpX=(int)posX + rand.nextInt(71) - 35;
tpZ=(int)posZ + rand.nextInt(71) - 35;
tpY=worldObj.getTopSolidOrLiquidBlock(tpX,tpZ) - 1;
if (worldObj.getBlock(tpX,tpY,tpZ) == BlockList.ender_goo) {
teleportTo(tpX + 0.5D + (rand.nextDouble() - 0.5D) * 0.3D,tpY + 1D,tpZ + 0.5D + (rand.nextDouble() - 0.5D) * 0.3D,true);
break;
}
}
}
break;
case COLLECTOR:
if (rand.nextInt(50) == 0 && (!isCarrying() || rand.nextInt(4) == 0)) {
currentTask=EndermanTask.WAIT;
currentTaskTimer=150 + rand.nextInt(600 + rand.nextInt(1800));
setCarrying(null);
teleportTo(posX,10000D,posZ,true);
PacketPipeline.sendToAllAround(this,256D,new C20Effect(FXType.Basic.HOMELAND_ENDERMAN_TP_OVERWORLD,this));
}
break;
case OVERWORLD_EXPLORER:
if (rand.nextInt(200) == 0) {
currentTask=EndermanTask.WAIT;
currentTaskTimer=500 + rand.nextInt(800) + rand.nextInt(1000) * (1 + rand.nextInt(4));
List<EntityMobHomelandEnderman> explorers=HomelandEndermen.getByHomelandRole(this,HomelandRole.OVERWORLD_EXPLORER);
for (int a=0; a < 1 + rand.nextInt(7) && !explorers.isEmpty(); a++) {
if (rand.nextInt(3) == 0) break;
EntityMobHomelandEnderman enderman=explorers.remove(rand.nextInt(explorers.size()));
if (enderman == this) continue;
enderman.currentTask=EndermanTask.WAIT;
enderman.currentTaskTimer=currentTaskTimer + rand.nextInt(500);
enderman.teleportTo(enderman.posX,10000D,enderman.posZ,true);
PacketPipeline.sendToAllAround(this,256D,new C20Effect(FXType.Basic.HOMELAND_ENDERMAN_TP_OVERWORLD,enderman));
}
teleportTo(posX,10000D,posZ,true);
PacketPipeline.sendToAllAround(this,256D,new C20Effect(FXType.Basic.HOMELAND_ENDERMAN_TP_OVERWORLD,this));
}
break;
default :
}
}
}
}
if (overtakeGroup != -1) {
if (overtakeGroup == groupId) {
if (currentTask == EndermanTask.NONE) {
switch (overtakeGroupRole) {
case TELEPORTER:
if (rand.nextInt(8) == 0) teleportRandomly(12D);
break;
case CHAOSMAKER:
if (isCarrying() && getCarrying().getItem() == Item.getItemFromBlock(Blocks.tnt)) {
if (rand.nextInt(50) == 0) {
for (int attempt=0, xx, yy, zz; attempt < 30; attempt++) {
xx=(int)Math.floor(posX) + rand.nextInt(7) - 3;
yy=(int)Math.floor(posY) + rand.nextInt(3) - 1;
zz=(int)Math.floor(posZ) + rand.nextInt(7) - 3;
if (worldObj.getBlock(xx,yy,zz) == BlockList.end_terrain && worldObj.isAirBlock(xx,yy + 1,zz)) {
worldObj.spawnEntityInWorld(new EntityTNTPrimed(worldObj,xx + 0.5D,yy + 1.5D,zz + 0.5D,this));
setCarrying(null);
break;
}
}
}
}
 else {
currentTask=EndermanTask.GET_TNT;
currentTaskTimer=30 + rand.nextInt(80);
setPosition(posX,10000D,posZ);
PacketPipeline.sendToAllAround(this,256D,new C20Effect(FXType.Basic.HOMELAND_ENDERMAN_TP_OVERWORLD,this));
}
break;
case LEADER:
case FIGHTER:
if (!(entityToAttack instanceof EntityMobHomelandEnderman)) {
EntityMobHomelandEnderman target=null;
if (overtakeGroupRole == OvertakeGroupRole.LEADER || rand.nextInt(4) == 0) {
List<EntityMobHomelandEnderman> list=HomelandEndermen.getByHomelandRole(this,HomelandRole.ISLAND_LEADERS);
if (!list.isEmpty()) target=list.get(rand.nextInt(list.size()));
}
if (target == null) {
List<EntityMobHomelandEnderman> other=HomelandEndermen.getAll(this);
for (int attempt=0, size=other.size(); attempt < 10; attempt++) {
EntityMobHomelandEnderman potentialTarget=other.get(rand.nextInt(size));
if (potentialTarget == this || potentialTarget.isInSameGroup(this)) continue;
HomelandRole role=potentialTarget.homelandRole;
if (role == HomelandRole.GUARD && rand.nextInt(3) != 0) target=potentialTarget;
 else if (role != HomelandRole.WORKER || rand.nextInt(5) <= 1) target=potentialTarget;
break;
}
}
setTarget(target);
}
break;
default :
}
}
if (!worldObj.getEntitiesWithinAABB(EntityTNTPrimed.class,boundingBox.expand(5D,3D,5D)).isEmpty()) teleportRandomly();
}
 else if (groupId != -1) {
if (rand.nextInt(3) == 0) setGroupMember(overtakeGroup,OvertakeGroupRole.getRandomMember(rand));
 else setGroupMember(-1,null);
}
 else if (entityToAttack == null && ((homelandRole == HomelandRole.GUARD && rand.nextInt(30) == 0) || rand.nextInt(200) == 0)) {
List<EntityMobHomelandEnderman> all=HomelandEndermen.getAll(this);
for (int attempt=0; attempt < 4 && !all.isEmpty(); attempt++) {
EntityMobHomelandEnderman enderman=all.remove(rand.nextInt(all.size()));
if (enderman.groupId == overtakeGroup) {
setTarget(enderman);
break;
}
}
}
}
if (entityToAttack != null) {
++attackTpTimer;
if (((attackTpTimer > 50 + rand.nextInt(30) && rand.nextInt(20) == 0) || attackTpTimer > 120) && entityToAttack.getDistanceSqToEntity(this) < 16D) {
teleportRandomly(8D);
attackTpTimer=-80;
}
 else if (entityToAttack.getDistanceSqToEntity(this) > 256D && attackTpTimer > 30 && teleportToEntity(entityToAttack)) {
attackTpTimer=-80;
}
}
 else {
attackTpTimer=-80;
if (currentTask == EndermanTask.NONE && entityToAttack == null && ++randomTpTimer > 70 + rand.nextInt(50)) {
if (rand.nextInt(19) == 0) {
for (int attempt=0; attempt < 5; attempt++) {
if (teleportRandomly(10D)) break;
}
}
randomTpTimer-=110 + rand.nextInt(40);
}
if (screamTimer > 0 && --screamTimer == 0 && isScreaming()) setScreaming(false);
}
if (lastEntityToAttack != entityToAttack) {
IAttributeInstance attribute=getEntityAttribute(SharedMonsterAttributes.movementSpeed);
attribute.removeModifier(attackingSpeedBoostModifier);
if (entityToAttack != null) attribute.applyModifier(attackingSpeedBoostModifier);
lastEntityToAttack=entityToAttack;
}
}
isJumping=false;
if (entityToAttack != null) faceEntity(entityToAttack,100F,100F);
super.onLivingUpdate();
}

Fixed version (ground truth):
@Override public void onLivingUpdate(){
  entityAge=0;
  if (worldObj.isRemote) {
    refreshRoles();
    int chance=1 + (int)Math.floor(HardcoreEnderExpansion.proxy.getClientSidePlayer().getDistanceToEntity(this) / 20F);
    if (rand.nextInt(chance) == 0) {
      float colFactor=rand.nextFloat() * 0.6F + 0.4F;
      HardcoreEnderExpansion.fx.portalColor(worldObj,posX + (rand.nextDouble() - 0.5D) * width,posY + rand.nextDouble() * height - 0.25D,posZ + (rand.nextDouble() - 0.5D) * width,(rand.nextDouble() - 0.5D) * 2D,-rand.nextDouble(),(rand.nextDouble() - 0.5D) * 2D,colFactor * 0.9F,colFactor * 0.3F,colFactor);
      if (homelandRole != null && rand.nextInt(3) == 0) {
        HardcoreEnderExpansion.fx.portalColor(worldObj,posX + (rand.nextDouble() - 0.5D) * width,posY + rand.nextDouble() * height - 0.25D,posZ + (rand.nextDouble() - 0.5D) * width,(rand.nextDouble() - 0.5D) * 2D,-rand.nextDouble(),(rand.nextDouble() - 0.5D) * 2D,homelandRole.red,homelandRole.green,homelandRole.blue);
      }
      if (overtakeGroupRole != null && rand.nextInt(7) == 0) {
        HardcoreEnderExpansion.fx.portalColor(worldObj,posX + (rand.nextDouble() - 0.5D) * width,posY + rand.nextDouble() * height - 0.25D,posZ + (rand.nextDouble() - 0.5D) * width,(rand.nextDouble() - 0.5D) * 2D,-rand.nextDouble(),(rand.nextDouble() - 0.5D) * 2D,0.3F,0.3F,0.3F);
      }
    }
  }
 else   if (isEntityAlive()) {
    if (isWet())     attackEntityFrom(DamageSource.drown,1F);
    if (isWet() || isBurning()) {
      setTarget(null);
      setScreaming(false);
    }
    if (!onGround && ++fallTimer > 17 + rand.nextInt(15)) {
      fallTimer=0;
      for (int attempt=0; attempt < 500; attempt++) {
        if (teleportRandomly(48D)) {
          resetTask();
          break;
        }
      }
    }
    prevTeleportAttempt=null;
    if (attackedRecentlyTimer > 0)     attackedRecentlyTimer-=rand.nextInt(2);
    long overtakeGroup=HomelandEndermen.getOvertakeGroup(this);
    if (currentTask == EndermanTask.WAIT || currentTask == EndermanTask.GET_TNT) {
      moveForward=moveStrafing=0F;
      fallDistance=0F;
      fallTimer=0;
      posY=10000D;
      if (--currentTaskTimer == 0) {
        int tpX, tpY, tpZ;
        for (int attempt=0; attempt < 100; attempt++) {
          tpX=(int)Math.floor(posX) + rand.nextInt(41) - 20;
          tpZ=(int)Math.floor(posZ) + rand.nextInt(41) - 20;
          tpY=worldObj.getTopSolidOrLiquidBlock(tpX,tpZ) - 1;
          if (worldObj.getBlock(tpX,tpY,tpZ) == BlockList.end_terrain) {
            teleportTo(tpX + 0.3D + rand.nextDouble() * 0.4D,tpY + 1D,tpZ + 0.3D + rand.nextDouble() * 0.4D,true);
            PacketPipeline.sendToAllAround(this,256D,new C20Effect(FXType.Basic.HOMELAND_ENDERMAN_TP_OVERWORLD,this));
            if (overtakeGroupRole == OvertakeGroupRole.CHAOSMAKER) {
              setCarrying(new ItemStack(Blocks.tnt));
            }
 else             if (homelandRole == HomelandRole.COLLECTOR && rand.nextInt(4) != 0) {
              setCarrying(new ItemStack(endermanBlockList[rand.nextInt(endermanBlockList.length)]));
            }
            break;
          }
        }
        resetTask();
      }
    }
    if (overtakeGroup == -1) {
      if (currentTask != EndermanTask.NONE && currentTask != EndermanTask.WAIT) {
        --currentTaskTimer;
        if (currentTask == EndermanTask.LISTEN_TO_RECRUITER || currentTask == EndermanTask.RECRUIT_TO_GROUP) {
          moveForward=moveStrafing=0F;
          if (currentTaskTimer == 0 && currentTask == EndermanTask.RECRUIT_TO_GROUP) {
            int chance=50, reportChance=10;
            EntityMobHomelandEnderman target=(EntityMobHomelandEnderman)currentTaskData;
switch (target.homelandRole) {
case WORKER:
              chance=30;
            break;
case GUARD:
          chance=15;
        reportChance=35;
      break;
case INTELLIGENCE:
    chance=80;
  reportChance=22;
break;
case BUSINESSMAN:
chance=40;
reportChance=14;
break;
default :
}
if (rand.nextInt(100) < chance) {
target.setGroupMember(groupId,OvertakeGroupRole.getRandomMember(rand));
PacketPipeline.sendToAllAround(this,64D,new C21EffectEntity(FXType.Entity.HOMELAND_ENDERMAN_RECRUIT,this));
PacketPipeline.sendToAllAround(this,64D,new C21EffectEntity(FXType.Entity.HOMELAND_ENDERMAN_RECRUIT,target));
for (int attempt=0; attempt < 50; attempt++) {
if (teleportRandomly()) break;
}
}
 else if (rand.nextInt(100) < reportChance) {
boolean escaped=false;
double oldX=posX, oldY=posY, oldZ=posZ;
if (rand.nextInt(5) != 0) {
for (int attempt=0; attempt < 20; attempt++) {
if (teleportRandomly()) {
escaped=true;
break;
}
}
}
List<EntityMobHomelandEnderman> guards=HomelandEndermen.getByHomelandRole(this,HomelandRole.GUARD);
for (int a=0, amt=Math.max(3,(int)Math.round(guards.size() * 0.3D)); a < amt; a++) {
EntityMobHomelandEnderman guard=guards.get(rand.nextInt(guards.size()));
guard.setScreaming(true);
PacketPipeline.sendToAllAround(this,256D,new C22EffectLine(FXType.Line.HOMELAND_ENDERMAN_GUARD_CALL,target,guard));
if (!escaped) guard.setTarget(this);
 else if (rand.nextInt(4) != 0) guard.teleportTo(oldX + 4D * (rand.nextDouble() - 0.5D),oldY + 2D + rand.nextDouble() * 4D,oldZ + 4D * (rand.nextDouble() - 0.5D));
}
}
recruitCooldown=120;
}
}
 else if (currentTask == EndermanTask.STROLL) {
if (currentTaskTimer > 0 && currentTaskTimer < 20 && rand.nextInt(3) == 0) {
Vec3 obj=(Vec3)currentTaskData;
if ((obj.distanceTo(Vec3.createVectorHelper(posX,posY,posZ)) <= 0.5D || rand.nextInt(10) == 0) && randomTpTimer > 30) {
for (int attempt=0; attempt < 30; attempt++) {
if (teleportRandomly(48D)) {
currentTaskData=Vec3.createVectorHelper(posX,posY,posZ);
randomTpTimer-=40 + rand.nextInt(30);
break;
}
}
}
}
if (currentTaskTimer == 0 && rand.nextInt(5) == 0) {
currentTaskTimer=10 + rand.nextInt(60);
}
}
 else if (currentTask == EndermanTask.WALK) {
ChunkPosition pos=(ChunkPosition)currentTaskData;
if (MathUtil.distance(posX - pos.chunkPosX,posY - pos.chunkPosY,posZ - pos.chunkPosZ) < 3D) resetTask();
}
 else if (currentTask == EndermanTask.COMMUNICATE) {
moveForward=moveStrafing=0F;
}
if (currentTaskTimer <= 0) resetTask();
}
 else if (entityToAttack == null) {
if (groupId != -1 && rand.nextInt(400) == 0 && (recruitCooldown < -120 || --recruitCooldown < -120)) {
List<EntityMobHomelandEnderman> total=HomelandEndermen.getAll(this);
int groupAmt=HomelandEndermen.getInSameGroup(this).size();
int totalAmt=total.size();
if (totalAmt > 8 && (rand.nextInt(5) <= 2 || groupAmt < (totalAmt >> 2) + rand.nextInt(totalAmt >> 3) - rand.nextInt(4))) {
for (int attempt=0; attempt < 5; attempt++) {
EntityMobHomelandEnderman enderman=total.get(rand.nextInt(totalAmt));
if (enderman == this || enderman.groupId != -1 || !enderman.onGround || enderman.homelandRole == HomelandRole.ISLAND_LEADERS || enderman.getDistanceToEntity(this) > 80D) continue;
if (groupAmt > 3 && ((enderman.homelandRole == HomelandRole.GUARD || enderman.homelandRole == HomelandRole.WORKER) && rand.nextInt(5) != 0)) continue;
boolean tp=false;
for (int tpAttempt=0; tpAttempt < 30; tpAttempt++) {
if (teleportTo(enderman.posX + (rand.nextDouble() - 0.5D) * 2D,enderman.posY,enderman.posZ + (rand.nextDouble() - 0.5D) * 2D)) {
tp=true;
break;
}
}
if (!tp) continue;
currentTask=EndermanTask.RECRUIT_TO_GROUP;
currentTaskData=enderman;
enderman.currentTask=EndermanTask.LISTEN_TO_RECRUITER;
enderman.currentTaskTimer=currentTaskTimer=20 + rand.nextInt(60);
break;
}
}
}
if (currentTask == EndermanTask.NONE && rand.nextInt(80) == 0) {
switch (homelandRole) {
case ISLAND_LEADERS:
if (rand.nextInt(13) == 0) {
teleportRandomly();
}
 else {
Vec3 look=getLookVec();
for (int attempt=0, pathX, pathY, pathZ; attempt < 12; attempt++) {
if (attempt > 8 || rand.nextInt(6) == 0) look=Vec3.createVectorHelper(rand.nextDouble() - 0.5D,0D,rand.nextDouble() - 0.5D).normalize();
pathX=(int)(posX + look.xCoord * 16D + (rand.nextDouble() - 0.5D) * 5D);
pathZ=(int)(posZ + look.zCoord * 16D + (rand.nextDouble() - 0.5D) * 5D);
pathY=worldObj.getTopSolidOrLiquidBlock(pathX,pathZ) - 1;
if (worldObj.getBlock(pathX,pathY,pathZ) == BlockList.end_terrain && MathUtil.distance(posX - pathX,posY - pathY,posZ - pathZ) > 5D) {
setPathToEntity(worldObj.getEntityPathToXYZ(this,pathX,pathY + 1,pathZ,30F,true,false,false,true));
currentTask=EndermanTask.STROLL;
currentTaskTimer=65 + rand.nextInt(60);
currentTaskData=Vec3.createVectorHelper(posX,posY,posZ);
break;
}
}
}
break;
case BUSINESSMAN:
if (rand.nextInt(18) == 0) {
List<EntityMobHomelandEnderman> businessmen=HomelandEndermen.getByHomelandRole(this,HomelandRole.BUSINESSMAN);
if (!businessmen.isEmpty()) {
EntityMobHomelandEnderman enderman=businessmen.get(rand.nextInt(businessmen.size()));
if (enderman.currentTask == EndermanTask.NONE) {
for (int tpAttempt=0; tpAttempt < 20; tpAttempt++) {
if (teleportTo(enderman.posX + (rand.nextDouble() - 0.5D) * 2D,enderman.posY,enderman.posZ + (rand.nextDouble() - 0.5D) * 2D)) {
currentTask=enderman.currentTask=EndermanTask.COMMUNICATE;
currentTaskTimer=enderman.currentTaskTimer=30 + rand.nextInt(50 + rand.nextInt(80));
break;
}
}
}
}
}
 else if (rand.nextInt(10) == 0) {
int walkToX, walkToY, walkToZ;
for (int attempt=0; attempt < 10; attempt++) {
walkToX=(int)posX + rand.nextInt(251) - 125;
walkToZ=(int)posZ + rand.nextInt(251) - 125;
walkToY=worldObj.getTopSolidOrLiquidBlock(walkToX,walkToZ) - 1;
if (worldObj.getBlock(walkToX,walkToY,walkToZ) == BlockList.end_terrain) {
setPathToEntity(worldObj.getEntityPathToXYZ(this,walkToX,walkToY + 1,walkToZ,100F,true,false,false,true));
currentTask=EndermanTask.WALK;
currentTaskTimer=200 + rand.nextInt(100);
currentTaskData=new ChunkPosition(walkToX,walkToY,walkToZ);
break;
}
}
}
break;
case WORKER:
if (rand.nextInt(270) == 0 && worldObj.getBlock((int)Math.floor(posX),(int)Math.floor(posY) + 1,(int)Math.floor(posZ)) != BlockList.ender_goo) {
for (int attempt=0, tpX, tpY, tpZ; attempt < 50; attempt++) {
tpX=(int)posX + rand.nextInt(71) - 35;
tpZ=(int)posZ + rand.nextInt(71) - 35;
tpY=worldObj.getTopSolidOrLiquidBlock(tpX,tpZ) - 1;
if (worldObj.getBlock(tpX,tpY,tpZ) == BlockList.ender_goo) {
tpX+=0.5D + (rand.nextDouble() - 0.5D) * 0.3D;
tpY+=1D;
tpZ+=0.5D + (rand.nextDouble() - 0.5D) * 0.3D;
PacketPipeline.sendToAllAround(this,256D,new C22EffectLine(FXType.Line.ENDERMAN_TELEPORT,posX,posY,posZ,tpX,tpY,tpZ));
teleportTo(tpX,tpY,tpZ,true);
break;
}
}
}
break;
case COLLECTOR:
if (rand.nextInt(30) == 0 && (!isCarrying() || rand.nextInt(4) == 0)) {
PacketPipeline.sendToAllAround(this,256D,new C20Effect(FXType.Basic.HOMELAND_ENDERMAN_TP_OVERWORLD,this));
currentTask=EndermanTask.WAIT;
currentTaskTimer=150 + rand.nextInt(600 + rand.nextInt(1800));
setCarrying(null);
teleportTo(posX,10000D,posZ,true);
}
break;
case OVERWORLD_EXPLORER:
if (rand.nextInt(140) == 0) {
currentTask=EndermanTask.WAIT;
currentTaskTimer=500 + rand.nextInt(800) + rand.nextInt(1000) * (1 + rand.nextInt(4));
List<EntityMobHomelandEnderman> explorers=HomelandEndermen.getByHomelandRole(this,HomelandRole.OVERWORLD_EXPLORER);
for (int a=0; a < 1 + rand.nextInt(7) && !explorers.isEmpty(); a++) {
if (rand.nextInt(3) == 0) break;
EntityMobHomelandEnderman enderman=explorers.remove(rand.nextInt(explorers.size()));
if (enderman == this) continue;
PacketPipeline.sendToAllAround(this,256D,new C20Effect(FXType.Basic.HOMELAND_ENDERMAN_TP_OVERWORLD,enderman));
enderman.currentTask=EndermanTask.WAIT;
enderman.currentTaskTimer=currentTaskTimer + rand.nextInt(500);
enderman.teleportTo(enderman.posX,10000D,enderman.posZ,true);
}
PacketPipeline.sendToAllAround(this,256D,new C20Effect(FXType.Basic.HOMELAND_ENDERMAN_TP_OVERWORLD,this));
teleportTo(posX,10000D,posZ,true);
}
break;
default :
}
}
}
}
if (overtakeGroup != -1) {
if (overtakeGroup == groupId) {
if (currentTask == EndermanTask.NONE) {
switch (overtakeGroupRole) {
case TELEPORTER:
if (rand.nextInt(8) == 0) teleportRandomly(12D);
break;
case CHAOSMAKER:
if (isCarrying() && getCarrying().getItem() == Item.getItemFromBlock(Blocks.tnt)) {
if (rand.nextInt(50) == 0) {
for (int attempt=0, xx, yy, zz; attempt < 30; attempt++) {
xx=(int)Math.floor(posX) + rand.nextInt(7) - 3;
yy=(int)Math.floor(posY) + rand.nextInt(3) - 1;
zz=(int)Math.floor(posZ) + rand.nextInt(7) - 3;
if (worldObj.getBlock(xx,yy,zz) == BlockList.end_terrain && worldObj.isAirBlock(xx,yy + 1,zz)) {
worldObj.spawnEntityInWorld(new EntityTNTPrimed(worldObj,xx + 0.5D,yy + 1.5D,zz + 0.5D,this));
setCarrying(null);
break;
}
}
}
}
 else {
PacketPipeline.sendToAllAround(this,256D,new C20Effect(FXType.Basic.HOMELAND_ENDERMAN_TP_OVERWORLD,this));
currentTask=EndermanTask.GET_TNT;
currentTaskTimer=30 + rand.nextInt(80);
setPosition(posX,10000D,posZ);
}
break;
case LEADER:
case FIGHTER:
if (!(entityToAttack instanceof EntityMobHomelandEnderman)) {
EntityMobHomelandEnderman target=null;
if (overtakeGroupRole == OvertakeGroupRole.LEADER || rand.nextInt(4) == 0) {
List<EntityMobHomelandEnderman> list=HomelandEndermen.getByHomelandRole(this,HomelandRole.ISLAND_LEADERS);
if (!list.isEmpty()) target=list.get(rand.nextInt(list.size()));
}
if (target == null) {
List<EntityMobHomelandEnderman> other=HomelandEndermen.getAll(this);
for (int attempt=0, size=other.size(); attempt < 10; attempt++) {
EntityMobHomelandEnderman potentialTarget=other.get(rand.nextInt(size));
if (potentialTarget == this || potentialTarget.isInSameGroup(this)) continue;
HomelandRole role=potentialTarget.homelandRole;
if (role == HomelandRole.GUARD && rand.nextInt(3) != 0) target=potentialTarget;
 else if (role != HomelandRole.WORKER || rand.nextInt(5) <= 1) target=potentialTarget;
break;
}
}
setTarget(target);
}
break;
default :
}
}
if (!worldObj.getEntitiesWithinAABB(EntityTNTPrimed.class,boundingBox.expand(5D,3D,5D)).isEmpty()) teleportRandomly();
}
 else if (groupId != -1) {
if (rand.nextInt(3) == 0) setGroupMember(overtakeGroup,OvertakeGroupRole.getRandomMember(rand));
 else setGroupMember(-1,null);
}
 else if (entityToAttack == null && ((homelandRole == HomelandRole.GUARD && rand.nextInt(30) == 0) || rand.nextInt(200) == 0)) {
List<EntityMobHomelandEnderman> all=HomelandEndermen.getAll(this);
for (int attempt=0; attempt < 4 && !all.isEmpty(); attempt++) {
EntityMobHomelandEnderman enderman=all.remove(rand.nextInt(all.size()));
if (enderman.groupId == overtakeGroup) {
setTarget(enderman);
break;
}
}
}
}
if (entityToAttack != null) {
++attackTpTimer;
if (((attackTpTimer > 50 + rand.nextInt(30) && rand.nextInt(20) == 0) || attackTpTimer > 120) && entityToAttack.getDistanceSqToEntity(this) < 16D) {
teleportRandomly(8D);
attackTpTimer=-80;
}
 else if (entityToAttack.getDistanceSqToEntity(this) > 256D && attackTpTimer > 30 && teleportToEntity(entityToAttack)) {
attackTpTimer=-80;
}
}
 else {
attackTpTimer=-80;
if (currentTask == EndermanTask.NONE && entityToAttack == null && ++randomTpTimer > 70 + rand.nextInt(50)) {
if (rand.nextInt(19) == 0) {
for (int attempt=0; attempt < 5; attempt++) {
if (teleportRandomly(10D)) break;
}
}
randomTpTimer-=110 + rand.nextInt(40);
}
if (screamTimer > 0 && --screamTimer == 0 && isScreaming()) setScreaming(false);
}
if (lastEntityToAttack != entityToAttack) {
IAttributeInstance attribute=getEntityAttribute(SharedMonsterAttributes.movementSpeed);
attribute.removeModifier(attackingSpeedBoostModifier);
if (entityToAttack != null) attribute.applyModifier(attackingSpeedBoostModifier);
lastEntityToAttack=entityToAttack;
}
}
isJumping=false;
if (entityToAttack != null) faceEntity(entityToAttack,100F,100F);
super.onLivingUpdate();
}