Plain and simple, I’m trying to figure out how to get the Direction an entity is looking. I know that the Direction enum has a getClosest(Vector3d) method, which is what I’ve been trying to use. So I was simply taking the two values found in Entity's .getHeadRotation() and passed that to Direction.getClosest(Vectord3d), setting one value as that Vector argument’s x and the other as the z. While testing this, my client was showing me looking at Northeast (specifically North-Northeast), yet Direction.getClosest(Vector3d) was saying I was looking DOWN.
<p>The format of the rotation is represented by:</p>
* <ul><code>x -> pitch</code>, <code>y -> yaw</code>, <code>z -> roll
* </code></ul>
*
* <p>Note that the pitch will be the same x value returned by
* {@link Entity#getRotation()} and Minecraft does not currently support
* head roll so the z value will always be zero.</p>
Pitch, Yaw, Roll is NOT a direction vector.
" Gets the closest direction from the given vector" The assumption being a direction vector.
In order to do what you want, you will first need to transform the head rotation into a direction vector in the direction the head is facing.
final Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection();
Will give you a direction vector given the head rotation.
Passing this into getClosest should do what you want.