Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private ArmorStand stand;
- private Location location;
- private float radius;
- private float radPerTick;
- private int tick = 0;
- public AroundAxisRotation(ArmorStand stand, Location location, float radius, float radPerSec, long start_after, long stop_after) {
- this.stand = stand;
- this.location = location;
- this.radius = radius;
- this.radPerTick = radPerSec / 10f;
- BukkitRunnable animation = this;
- new BukkitRunnable() {
- @Override
- public void run() {
- animation.runTaskTimer(ArmorStandLib.getInstance(), 0, 1);
- }
- }.runTaskLaterAsynchronously(ArmorStandLib.getInstance(), start_after);
- if (stop_after < 0) return;
- new BukkitRunnable() {
- @Override
- public void run() {
- animation.cancel();
- getArmTip(stand);
- stand.remove();
- }
- }.runTaskLaterAsynchronously(ArmorStandLib.getInstance(), stop_after);
- }
- public void run() {
- ++tick;
- Location loc = getLocationAroundCircle(location.clone(), radius, radPerTick * tick);
- // Location loc = getRotationAroundCircle(location.clone(), radius, radPerTick * tick);
- stand.setRightArmPose(new EulerAngle(-1.75, -0.69, 0));
- stand.setVisible(false);
- stand.setGravity(false);
- stand.setVelocity(new Vector(1, 0, 0));
- stand.teleport(loc.clone().add(0, 1, 0));
- }
- private Location getLocationAroundCircle(Location center, double radius, double angleInRadian) {
- double x = center.getX() + radius * Math.cos(angleInRadian);
- double z = center.getZ() + radius * sin(angleInRadian);
- double y = center.getY();
- Location loc = new Location(center.getWorld(), x, y, z);
- Vector difference = center.toVector().clone().subtract(loc.toVector());
- loc.setDirection(difference);
- return loc;
- }
- public static Location getArmTip(ArmorStand as) {
- // Gets shoulder location
- Location asl = as.getLocation().clone();
- asl.setYaw(asl.getYaw() + 90f);
- Vector dir = asl.getDirection();
- asl.setX(asl.getX() + 5f / 16f * dir.getX());
- asl.setY(asl.getY() + 22f / 16f);
- asl.setZ(asl.getZ() + 5f / 16f * dir.getZ());
- // Get Hand Location
- EulerAngle ea = as.getRightArmPose();
- Vector armDir = getDirection(ea.getY(), ea.getX(), -ea.getZ());
- armDir = rotateAroundAxisY(armDir, Math.toRadians(asl.getYaw()-90f));
- asl.setX(asl.getX() + 10f / 16f * armDir.getX());
- asl.setY(asl.getY() + 10f / 16f * armDir.getY());
- asl.setZ(asl.getZ() + 10f / 16f * armDir.getZ());
- ParticleEffect.SMOKE_NORMAL.display(
- 0f,
- 0f,
- 0f,
- 0.0F,
- 60,
- asl,
- 50.0D);
- return asl;
- }
- public static Vector getDirection(Double yaw, Double pitch, Double roll) {
- Vector v = new Vector(0, -1, 0);
- v = rotateAroundAxisX(v, pitch);
- v = rotateAroundAxisY(v, yaw);
- v = rotateAroundAxisZ(v, roll);
- return v;
- }
- private static Vector rotateAroundAxisX(Vector v, double angle) {
- double y, z, cos, sin;
- cos = Math.cos(angle);
- sin = sin(angle);
- y = v.getY() * cos - v.getZ() * sin;
- z = v.getY() * sin + v.getZ() * cos;
- return v.setY(y).setZ(z);
- }
- private static Vector rotateAroundAxisY(Vector v, double angle) {
- angle = -angle;
- double x, z, cos, sin;
- cos = Math.cos(angle);
- sin = sin(angle);
- x = v.getX() * cos + v.getZ() * sin;
- z = v.getX() * -sin + v.getZ() * cos;
- return v.setX(x).setZ(z);
- }
- private static Vector rotateAroundAxisZ(Vector v, double angle) {
- double x, y, cos, sin;
- cos = Math.cos(angle);
- sin = sin(angle);
- x = v.getX() * cos - v.getY() * sin;
- y = v.getX() * sin + v.getY() * cos;
- return v.setX(x).setY(y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement