@SideOnly(Side.CLIENT)
public static Vec3d mouseToWorldRay(int mouseX, int mouseY, int width, int height) {
double aspectRatio = ((double) width / (double) height);
double fov = ((Minecraft.getMinecraft().gameSettings.fovSetting / 2d) + 11) * (Math.PI / 180);
Entity renderViewEntity = Minecraft.getMinecraft().getRenderViewEntity();
double a = -((double) mouseX / (double) width - 0.5) * 2;
double b = -((double) mouseY / (double) height - 0.5) * 2;
double tanf = Math.tan(fov);
float yawn = renderViewEntity.rotationYaw;
float pitch = renderViewEntity.rotationPitch;
Matrix4f rot = new Matrix4f();
rot.rotate(yawn * (float) (Math.PI / 180), new Vector3f(0, -1, 0));
rot.rotate(pitch * (float) (Math.PI / 180), new Vector3f(1, 0, 0));
Vector4f foward = new Vector4f(0, 0, 1, 0);
Vector4f up = new Vector4f(0, 1, 0, 0);
Vector4f left = new Vector4f(1, 0, 0, 0);
Matrix4f.transform(rot, foward, foward);
Matrix4f.transform(rot, up, up);
Matrix4f.transform(rot, left, left);
return new Vec3d(foward.x, foward.y, foward.z)
.addVector(left.x * tanf * aspectRatio * a, left.y * tanf * aspectRatio * a, left.z * tanf * aspectRatio * a)
.addVector(up.x * tanf * b, up.y * tanf * b, up.z * tanf * b)
.normalize();
}