Edit: Nevermind I fixed it! Should I just use this code after the lightning spawn to make it only fire every half second?
try {
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException e) {
//Handle exception
}
Working Code:
//Attempt at Entity scan and target
if (KeyInputHandler.ArmorOn == true) {
System.out.println("Scanner Activated");
List entities = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(player.posX - 5, player.posY - 5, player.posZ - 5, player.posX + 7, player.posY + 7, player.posZ + 7));
if (entities != null && !entities.isEmpty()) {
Iterator iterator = entities.iterator();
double posX;
double posY;
double posZ;
EntityLivingBase ent;
while (iterator.hasNext())
{
ent = (EntityLivingBase) iterator.next();
posX = ent.posX;
posY = ent.posY;
posZ = ent.posZ;
EntityLightningBolt Lightning = new EntityLightningBolt(world, posX, posY, posZ);
world.spawnEntityInWorld(Lightning);
}
}
}
}
Pre Edit:
Ok, I feel like this should work. However as soon as I activate it my whole game just freezes with no errors
//Attempt at Entity scan and target
if (KeyInputHandler.ArmorOn == true) {
System.out.println("Scanner Activated");
List entities = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(player.posX - 5, player.posY - 5, player.posZ - 5, player.posX + 7, player.posY + 7, player.posZ + 7));
Iterator iterator = entities.iterator();
double posX;
double posY;
double posZ;
EntityLivingBase ent;
while (iterator.hasNext());
ent = (EntityLivingBase)iterator.next();
posX = ent.posX;
posY = ent.posY;
posZ = ent.posZ;
EntityLightningBolt Lightning = new EntityLightningBolt(world, posX, posY, posZ);
world.spawnEntityInWorld(Lightning);