Skip to content

Instantly share code, notes, and snippets.

@IllusionTheDev
Created July 5, 2022 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IllusionTheDev/2a0302c31be1ad037d33d46086118028 to your computer and use it in GitHub Desktop.
Save IllusionTheDev/2a0302c31be1ad037d33d46086118028 to your computer and use it in GitHub Desktop.
Obtain a raytraced body part for a minecraft entity
public enum BodyPart {
RIGHT_LEG,
LEFT_LEG,
HEAD,
BODY;
public static BodyPart rayTrace(RayTraceResult result) {
Entity entity = result.getHitEntity();
if (entity == null)
return null;
Vector hitPosition = result.getHitPosition();
Vector entityPosition = entity.getLocation().toVector();
Vector difference = hitPosition.subtract(entityPosition);
// rotate the difference vector to the entity's rotation
difference = difference.rotateAroundY(entity.getLocation().getYaw());
if (difference.getY() < 1) {
return difference.getX() < 0 ? LEFT_LEG : RIGHT_LEG;
}
double height = Math.abs(difference.getY());
if (height > 1.5) {
return HEAD;
}
// apparently arms are not included in the raytrace
return BODY;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment