Skip to content

Instantly share code, notes, and snippets.

@miketamis
Created May 13, 2012 03:09
Show Gist options
  • Save miketamis/2673481 to your computer and use it in GitHub Desktop.
Save miketamis/2673481 to your computer and use it in GitHub Desktop.
private boolean isInFieldOfVision(vi entityPlayer, ia entity)
{
double d = par1Entity.posX - posX;
double d2 = par1Entity.posZ - posZ;
double d1;
if (par1Entity instanceof EntityLiving)
{
EntityLiving entityliving = (EntityLiving)par1Entity;
d1 = (posY + (double)getEyeHeight()) - (entityliving.posY + (double)entityliving.getEyeHeight());
}
else
{
d1 = (par1Entity.boundingBox.minY + par1Entity.boundingBox.maxY) / 2D - (posY + (double)getEyeHeight());
}
double d3 = MathHelper.sqrt_double(d * d + d2 * d2);
float f123 = (float)((Math.atan2(d2, d) * 180D) / Math.PI) - 90F;
float f1234 = (float)(-((Math.atan2(d1, d3) * 180D) / Math.PI));
float f1 = -updateRotation(rotationPitch, f1234, 360.0);
float f2 = updateRotation(rotationYaw, f123, 360.0F);
float f4 = 70.0F; //horizonal angle
float f5 = 65.0F; //verticle angle
float f6 = entityPlayer.y - f4;
float f7 = entityPlayer.y + f4;
float f8 = entityPlayer.z - f5;
float f9 = entityPlayer.z + f5;
boolean flag = GetFlag(f6, f7, f, 0.0F, 360.0F);
boolean flag1 = GetFlag(f8, f9, f1, -180.0F, 180.0F);
return (flag) && (flag1);
}
public boolean GetFlag(float f, float f1, float f2, float f3, float f4) {
if (f < f3)
{
if (f2 >= f + f4)
{
return true;
}
if (f2 <= f1)
{
return true;
}
}
if (f1 >= f4)
{
if (f2 <= f1 - f4)
{
return true;
}
if (f2 >= f)
{
return true;
}
}
if ((f1 < f4) && (f >= f3))
{
return (f2 <= f1) && (f2 > f);
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment