Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.14 KB | None | 0 0
  1. private ArmorStand stand;
  2.  
  3.     private Location location;
  4.     private float radius;
  5.     private float radPerTick;
  6.     private int tick = 0;
  7.  
  8.     public AroundAxisRotation(ArmorStand stand, Location location, float radius, float radPerSec, long start_after, long stop_after) {
  9.         this.stand = stand;
  10.         this.location = location;
  11.         this.radius = radius;
  12.         this.radPerTick = radPerSec / 10f;
  13.  
  14.         BukkitRunnable animation = this;
  15.  
  16.         new BukkitRunnable() {
  17.             @Override
  18.             public void run() {
  19.                 animation.runTaskTimer(ArmorStandLib.getInstance(), 0, 1);
  20.             }
  21.         }.runTaskLaterAsynchronously(ArmorStandLib.getInstance(), start_after);
  22.  
  23.         if (stop_after < 0) return;
  24.         new BukkitRunnable() {
  25.             @Override
  26.             public void run() {
  27.                 animation.cancel();
  28.                 getArmTip(stand);
  29.                 stand.remove();
  30.             }
  31.         }.runTaskLaterAsynchronously(ArmorStandLib.getInstance(), stop_after);
  32.     }
  33.  
  34.     public void run() {
  35.         ++tick;
  36.  
  37.         Location loc = getLocationAroundCircle(location.clone(), radius, radPerTick * tick);
  38.         // Location loc = getRotationAroundCircle(location.clone(), radius, radPerTick * tick);
  39.         stand.setRightArmPose(new EulerAngle(-1.75, -0.69, 0));
  40.         stand.setVisible(false);
  41.         stand.setGravity(false);
  42.         stand.setVelocity(new Vector(1, 0, 0));
  43.         stand.teleport(loc.clone().add(0, 1, 0));
  44.  
  45.     }
  46.  
  47.     private Location getLocationAroundCircle(Location center, double radius, double angleInRadian) {
  48.         double x = center.getX() + radius * Math.cos(angleInRadian);
  49.         double z = center.getZ() + radius * sin(angleInRadian);
  50.         double y = center.getY();
  51.  
  52.         Location loc = new Location(center.getWorld(), x, y, z);
  53.         Vector difference = center.toVector().clone().subtract(loc.toVector());
  54.         loc.setDirection(difference);
  55.  
  56.         return loc;
  57.     }
  58.  
  59.     public static Location getArmTip(ArmorStand as) {
  60.         // Gets shoulder location
  61.         Location asl = as.getLocation().clone();
  62.         asl.setYaw(asl.getYaw() + 90f);
  63.         Vector dir = asl.getDirection();
  64.         asl.setX(asl.getX() + 5f / 16f * dir.getX());
  65.         asl.setY(asl.getY() + 22f / 16f);
  66.         asl.setZ(asl.getZ() + 5f / 16f * dir.getZ());
  67.         // Get Hand Location
  68.  
  69.         EulerAngle ea = as.getRightArmPose();
  70.         Vector armDir = getDirection(ea.getY(), ea.getX(), -ea.getZ());
  71.         armDir = rotateAroundAxisY(armDir, Math.toRadians(asl.getYaw()-90f));
  72.         asl.setX(asl.getX() + 10f / 16f * armDir.getX());
  73.         asl.setY(asl.getY() + 10f / 16f * armDir.getY());
  74.         asl.setZ(asl.getZ() + 10f / 16f * armDir.getZ());
  75.  
  76.         ParticleEffect.SMOKE_NORMAL.display(
  77.                 0f,
  78.                 0f,
  79.                 0f,
  80.                 0.0F,
  81.                 60,
  82.                 asl,
  83.                 50.0D);
  84.         return asl;
  85.     }
  86.  
  87.     public static Vector getDirection(Double yaw, Double pitch, Double roll) {
  88.         Vector v = new Vector(0, -1, 0);
  89.         v = rotateAroundAxisX(v, pitch);
  90.         v = rotateAroundAxisY(v, yaw);
  91.         v = rotateAroundAxisZ(v, roll);
  92.         return v;
  93.     }
  94.  
  95.     private static Vector rotateAroundAxisX(Vector v, double angle) {
  96.         double y, z, cos, sin;
  97.         cos = Math.cos(angle);
  98.         sin = sin(angle);
  99.         y = v.getY() * cos - v.getZ() * sin;
  100.         z = v.getY() * sin + v.getZ() * cos;
  101.         return v.setY(y).setZ(z);
  102.     }
  103.  
  104.     private static Vector rotateAroundAxisY(Vector v, double angle) {
  105.         angle = -angle;
  106.         double x, z, cos, sin;
  107.         cos = Math.cos(angle);
  108.         sin = sin(angle);
  109.         x = v.getX() * cos + v.getZ() * sin;
  110.         z = v.getX() * -sin + v.getZ() * cos;
  111.         return v.setX(x).setZ(z);
  112.     }
  113.  
  114.     private static Vector rotateAroundAxisZ(Vector v, double angle) {
  115.         double x, y, cos, sin;
  116.         cos = Math.cos(angle);
  117.         sin = sin(angle);
  118.         x = v.getX() * cos - v.getY() * sin;
  119.         y = v.getX() * sin + v.getY() * cos;
  120.         return v.setX(x).setY(y);
  121.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement