Advertisement
JackOUT

Untitled

Feb 27th, 2022
1,297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1.     public static Location getSmallArmTip(final ArmorStand armorStand) {
  2.         // Gets shoulder location
  3.         final Location standLocation = armorStand.getLocation().clone();
  4.         standLocation.setYaw(standLocation.getYaw() + 90f);
  5.         final Vector direction = standLocation.getDirection();
  6.  
  7.         standLocation.setX(standLocation.getX() + 0.22 * direction.getX());
  8.         standLocation.setY(standLocation.getY() + 1);
  9.         standLocation.setZ(standLocation.getZ() + 0.22 * direction.getZ());
  10.  
  11.         // Get Hand Location
  12.         final EulerAngle rightArmPose = armorStand.getRightArmPose();
  13.         Vector armDirection = getDirection(rightArmPose.getY(), rightArmPose.getX(), -rightArmPose.getZ());
  14.         armDirection = rotateAroundAxisY(armDirection, Math.toRadians(standLocation.getYaw() - 90f));
  15.  
  16.         standLocation.setX(standLocation.getX() + 10f / 16f * armDirection.getX());
  17.         standLocation.setY(standLocation.getY() + 10f / 16f * armDirection.getY());
  18.         standLocation.setZ(standLocation.getZ() + 10f / 16f * armDirection.getZ());
  19.  
  20.         return standLocation;
  21.     }
  22.  
  23.     public static Vector getDirection(final Double yaw, final Double pitch, final Double roll) {
  24.         Vector vector = new Vector(0, -1, 0);
  25.         vector = rotateAroundAxisX(vector, pitch);
  26.         vector = rotateAroundAxisY(vector, yaw);
  27.         vector = rotateAroundAxisZ(vector, roll);
  28.         return vector;
  29.     }
  30.  
  31.     private static Vector rotateAroundAxisX(final Vector vector, final double angle) {
  32.         final double y;
  33.         final double z;
  34.         final double cos;
  35.         final double sin;
  36.         cos = Math.cos(angle);
  37.         sin = Math.sin(angle);
  38.         y = vector.getY() * cos - vector.getZ() * sin;
  39.         z = vector.getY() * sin + vector.getZ() * cos;
  40.         return vector.setY(y).setZ(z);
  41.     }
  42.  
  43.     private static Vector rotateAroundAxisY(final Vector vector, double angle) {
  44.         angle = -angle;
  45.         final double x;
  46.         final double z;
  47.         final double cos;
  48.         final double sin;
  49.         cos = Math.cos(angle);
  50.         sin = Math.sin(angle);
  51.         x = vector.getX() * cos + vector.getZ() * sin;
  52.         z = vector.getX() * -sin + vector.getZ() * cos;
  53.         return vector.setX(x).setZ(z);
  54.     }
  55.  
  56.     private static Vector rotateAroundAxisZ(final Vector vector, final double angle) {
  57.         final double x;
  58.         final double y;
  59.         final double cos;
  60.         final double sin;
  61.         cos = Math.cos(angle);
  62.         sin = Math.sin(angle);
  63.         x = vector.getX() * cos - vector.getY() * sin;
  64.         y = vector.getX() * sin + vector.getY() * cos;
  65.         return vector.setX(x).setY(y);
  66.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement