Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ua.prettydude.testplugin;
- import org.bukkit.Location;
- import org.bukkit.Particle;
- import org.bukkit.World;
- import org.bukkit.entity.Projectile;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.util.Vector;
- public class ParticleScheduler extends BukkitRunnable {
- private Projectile proj;
- private World world;
- private int particleCount;
- public static double RADIUS = 1;
- public ParticleScheduler(Projectile proj, int particleCount) {
- this.proj = proj;
- this.particleCount = particleCount;
- this.world = proj.getWorld();
- }
- @Override
- public void run() {
- if (proj.isDead() || proj.isOnGround()) {
- this.cancel();
- return;
- }
- for (int i = 0; i < particleCount; i++) {
- double angle = (2 * Math.PI) / particleCount * i;
- Location loc = preparePoint(proj, RADIUS, angle);
- world.spawnParticle(Particle.VILLAGER_HAPPY, loc, 1, 0.1, 0.1, 0.1, 0.1, null,true);
- }
- }
- private Location preparePoint(Projectile proj, double radius, double angle) {
- Location center = proj.getLocation();
- Vector v = proj.getVelocity().normalize();
- Vector per = getPerpendicular(v);
- Vector rotated = rotateVectorCC(per, v, angle).normalize();
- return center.add(rotated.multiply(radius));
- }
- private Vector getPerpendicular(Vector base) {
- return Math.abs(base.getZ()) < Math.abs(base.getX())
- ? new Vector(base.getY(), -base.getX(), 0)
- : new Vector(0, -base.getZ(), base.getY());
- }
- private Vector rotateVectorCC(Vector vec, Vector axis, double theta) {
- double x = vec.getX(), y = vec.getY(), z = vec.getZ();
- double u = axis.getX(), v = axis.getY(), w = axis.getZ();
- double xPrime = u * (u * x + v * y + w * z) * (1d - Math.cos(theta))
- + x * Math.cos(theta)
- + (-w * y + v * z) * Math.sin(theta);
- double yPrime = v * (u * x + v * y + w * z) * (1d - Math.cos(theta))
- + y * Math.cos(theta)
- + (w * x - u * z) * Math.sin(theta);
- double zPrime = w * (u * x + v * y + w * z) * (1d - Math.cos(theta))
- + z * Math.cos(theta)
- + (-v * x + u * y) * Math.sin(theta);
- return new Vector(xPrime, yPrime, zPrime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement