public class EntityLook
{
/***/
public static RayTraceResult getMouseOver(EntityLivingBase entity_base, float fasc, double dist, boolean interact)
{
if (entity_base == null || entity_base.world == null) return null;
Entity pointedEntity = null;
double d0 = dist;
double d1 = d0;
Vec3d vec3 = new Vec3d(entity_base.posX,
(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT ? entity_base.posY : entity_base.posY + entity_base.getEyeHeight()),
entity_base.posZ);
Vec3d vec31 = entity_base.getLook(fasc);
Vec3d vec32 = vec3.addVector(vec31.x * d0, vec31.y * d0, vec31.z * d0);
Vec3d vec33 = null;
RayTraceResult objectMouseOver = rayTrace(entity_base, dist, fasc);
if (objectMouseOver != null)
d1 = objectMouseOver.hitVec.distanceTo(vec3);
float f1 = 1.0F;
List list = entity_base.world.getEntitiesWithinAABBExcludingEntity(entity_base, entity_base.getEntityBoundingBox().expand(vec31.x * d0, vec31.y * d0, vec31.z * d0).grow((double)f1));
double d2 = d1;
for (int i = 0; i < list.size(); ++i) {
Entity entity = (Entity)list.get(i);
if (entity.canBeCollidedWith() || interact) {
float f2 = entity.getCollisionBorderSize();
AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expand((double)f2, (double)f2, (double)f2);
RayTraceResult movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
if (axisalignedbb.contains(vec3)) {
if (0.0D < d2 || d2 == 0.0D) {
pointedEntity = entity;
vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
d2 = 0.0D;
}
} else if (movingobjectposition != null) {
double d3 = vec3.distanceTo(movingobjectposition.hitVec);
if (d3 < d2 || d2 == 0.0D) {
if (entity == entity_base.getRidingEntity() && !entity.canRiderInteract()) {
if (d2 == 0.0D) {
pointedEntity = entity;
vec33 = movingobjectposition.hitVec;
}
} else {
pointedEntity = entity;
vec33 = movingobjectposition.hitVec;
d2 = d3;
}
}
}
}
}
if (pointedEntity != null && (d2 < d1 || objectMouseOver == null))
return new RayTraceResult(pointedEntity, vec33);
return null;
}
public static RayTraceResult rayTrace(EntityLivingBase entity, double dist, float fasc) {
Vec3d vec3 = new Vec3d(entity.posX,
(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT ? entity.posY : entity.posY + entity.getEyeHeight()),
entity.posZ);
Vec3d vec31 = entity.getLook(fasc);
Vec3d vec32 = vec3.addVector(vec31.x * dist, vec31.y * dist, vec31.z * dist);
return entity.world.rayTraceBlocks(vec3, vec32, false, false, true);
}
}