Advertisement
JackOUT

Untitled

Mar 1st, 2022
1,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. package games.coob.smp.util;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.entity.ArmorStand;
  5. import org.bukkit.util.EulerAngle;
  6. import org.bukkit.util.Vector;
  7.  
  8. public class ArmourStandUtil {
  9.  
  10.     public static Location getSmallArmTip(final ArmorStand armorStand) {
  11.         // Gets shoulder location
  12.         final Location standLocation = armorStand.getLocation().clone();
  13.         standLocation.setYaw(standLocation.getYaw() + 90f);
  14.         final Vector direction = standLocation.getDirection();
  15.  
  16.         standLocation.setX(standLocation.getX() + 4f / 16f * direction.getX());
  17.         standLocation.setY(standLocation.getY() + 11f / 16f);
  18.         standLocation.setZ(standLocation.getZ() + 4f / 16f * direction.getZ());
  19.  
  20.         // Get Hand Location
  21.         final EulerAngle rightArmPose = armorStand.getRightArmPose();
  22.         Vector armDirection = getDirection(rightArmPose.getY(), rightArmPose.getX(), -rightArmPose.getZ());
  23.         armDirection = rotateAroundAxisY(armDirection, Math.toRadians(standLocation.getYaw() - 90f));
  24.  
  25.         standLocation.setX(standLocation.getX() + 5f / 16f * armDirection.getX());
  26.         standLocation.setY(standLocation.getY() + 5f / 16f * armDirection.getY());
  27.         standLocation.setZ(standLocation.getZ() + 5f / 16f * armDirection.getZ());
  28.  
  29.         return standLocation;
  30.     }
  31.  
  32.     public static Location getArmTip(final ArmorStand armorStand) {
  33.         // Gets shoulder location
  34.         final Location standLocation = armorStand.getLocation().clone();
  35.         standLocation.setYaw(standLocation.getYaw() + 90f);
  36.         final Vector direction = standLocation.getDirection();
  37.  
  38.         standLocation.setX(standLocation.getX() + 5f / 16f * direction.getX());
  39.         standLocation.setY(standLocation.getY() + 22f / 16f);
  40.         standLocation.setZ(standLocation.getZ() + 5f / 16f * direction.getZ());
  41.  
  42.         // Get Hand Location
  43.         final EulerAngle rightArmPose = armorStand.getRightArmPose();
  44.         Vector armDirection = getDirection(rightArmPose.getY(), rightArmPose.getX(), -rightArmPose.getZ());
  45.         armDirection = rotateAroundAxisY(armDirection, Math.toRadians(standLocation.getYaw() - 90f));
  46.  
  47.         standLocation.setX(standLocation.getX() + 10f / 16f * armDirection.getX());
  48.         standLocation.setY(standLocation.getY() + 10f / 16f * armDirection.getY());
  49.         standLocation.setZ(standLocation.getZ() + 10f / 16f * armDirection.getZ());
  50.  
  51.         return standLocation;
  52.     }
  53.  
  54.     public static Vector getDirection(final Double yaw, final Double pitch, final Double roll) {
  55.         Vector vector = new Vector(0, -1, 0);
  56.         vector = rotateAroundAxisX(vector, pitch);
  57.         vector = rotateAroundAxisY(vector, yaw);
  58.         vector = rotateAroundAxisZ(vector, roll);
  59.         return vector;
  60.     }
  61.  
  62.     private static Vector rotateAroundAxisX(final Vector vector, final double angle) {
  63.         final double y;
  64.         final double z;
  65.         final double cos;
  66.         final double sin;
  67.         cos = Math.cos(angle);
  68.         sin = Math.sin(angle);
  69.         y = vector.getY() * cos - vector.getZ() * sin;
  70.         z = vector.getY() * sin + vector.getZ() * cos;
  71.         return vector.setY(y).setZ(z);
  72.     }
  73.  
  74.     private static Vector rotateAroundAxisY(final Vector vector, double angle) {
  75.         angle = -angle;
  76.         final double x;
  77.         final double z;
  78.         final double cos;
  79.         final double sin;
  80.         cos = Math.cos(angle);
  81.         sin = Math.sin(angle);
  82.         x = vector.getX() * cos + vector.getZ() * sin;
  83.         z = vector.getX() * -sin + vector.getZ() * cos;
  84.         return vector.setX(x).setZ(z);
  85.     }
  86.  
  87.     private static Vector rotateAroundAxisZ(final Vector vector, final double angle) {
  88.         final double x;
  89.         final double y;
  90.         final double cos;
  91.         final double sin;
  92.         cos = Math.cos(angle);
  93.         sin = Math.sin(angle);
  94.         x = vector.getX() * cos - vector.getY() * sin;
  95.         y = vector.getX() * sin + vector.getY() * cos;
  96.         return vector.setX(x).setY(y);
  97.     }
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement