Created
July 5, 2022 11:30
-
-
Save IllusionTheDev/2a0302c31be1ad037d33d46086118028 to your computer and use it in GitHub Desktop.
Obtain a raytraced body part for a minecraft entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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