public static Entity rayTrace(float yaw, float pitch, double range) {
Entity entity = getMc().getRenderViewEntity();
if (entity != null && getWorld() != null) {
getMc().pointedEntity = null;
double d0 = range;
float partialTicks = 1.0F;
getMc().objectMouseOver = entity.rayTrace(d0, partialTicks);
double d1 = d0;
Vec3 vec3 = entity.getPositionEyes(partialTicks);
Vec3 vec31 = getPlayer().getVectorForRotation(pitch, yaw);
Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
Entity pointedEntity = null;
Vec3 vec33 = null;
float f = 1.0F;
List list = getWorld().getEntitiesInAABBexcluding(entity,
entity.getEntityBoundingBox().addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0)
.expand((double) f, (double) f, (double) f),
Predicates.and(EntitySelectors.NOT_SPECTATING, new EntityRenderer1(getMc().entityRenderer)));
double d2 = d1;
for (int i = 0; i < list.size(); ++i) {
Entity entity1 = (Entity) list.get(i);
float f1 = entity1.getCollisionBorderSize();
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand((double) f1, (double) f1,
(double) f1);
MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
if (axisalignedbb.isVecInside(vec3)) {
if (d2 >= 0.0D) {
pointedEntity = entity1;
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) {
boolean flag2 = false;
if (Reflector.ForgeEntity_canRiderInteract.exists()) {
flag2 = Reflector.callBoolean(entity1, Reflector.ForgeEntity_canRiderInteract,
new Object[0]);
}
if (entity1 == entity.ridingEntity && !flag2) {
if (d2 == 0.0D) {
pointedEntity = entity1;
vec33 = movingobjectposition.hitVec;
}
} else {
pointedEntity = entity1;
vec33 = movingobjectposition.hitVec;
d2 = d3;
}
}
}
}
if (pointedEntity != null && (d2 < d1 || getMc().objectMouseOver == null)) {
getMc().objectMouseOver = new MovingObjectPosition(pointedEntity, vec33);
if (pointedEntity instanceof EntityLivingBase || pointedEntity instanceof EntityItemFrame) {
return pointedEntity;
}
}
}
return null;
}