|
| 1 | +package de.slikey.effectlib.effect; |
| 2 | + |
| 3 | +import org.bukkit.Location; |
| 4 | +import org.bukkit.util.Vector; |
| 5 | + |
| 6 | +import de.slikey.effectlib.EffectManager; |
| 7 | +import de.slikey.effectlib.EffectType; |
| 8 | +import de.slikey.effectlib.util.ParticleEffect; |
| 9 | +import de.slikey.effectlib.util.VectorUtils; |
| 10 | + |
| 11 | +public class CubeLocationEffect extends LocationEffect { |
| 12 | + |
| 13 | + /** |
| 14 | + * Particle of the cube |
| 15 | + */ |
| 16 | + public ParticleEffect particle = ParticleEffect.FLAME; |
| 17 | + |
| 18 | + /** |
| 19 | + * Lenght of the edges |
| 20 | + */ |
| 21 | + public float edgeLenght = 3; |
| 22 | + |
| 23 | + /** |
| 24 | + * Turns the cube by this angle each iteration around the x-axis |
| 25 | + */ |
| 26 | + public double angularVelocityX = Math.PI / 200; |
| 27 | + |
| 28 | + /** |
| 29 | + * Turns the cube by this angle each iteration around the y-axis |
| 30 | + */ |
| 31 | + public double angularVelocityY = Math.PI / 170; |
| 32 | + |
| 33 | + /** |
| 34 | + * Turns the cube by this angle each iteration around the z-axis |
| 35 | + */ |
| 36 | + public double angularVelocityZ = Math.PI / 155; |
| 37 | + |
| 38 | + /** |
| 39 | + * Particles in each row |
| 40 | + */ |
| 41 | + public int particles = 8; |
| 42 | + |
| 43 | + /** |
| 44 | + * Current step. Works as counter |
| 45 | + */ |
| 46 | + protected int step = 0; |
| 47 | + |
| 48 | + public CubeLocationEffect(EffectManager effectManager, Location location) { |
| 49 | + super(effectManager, location); |
| 50 | + type = EffectType.REPEATING; |
| 51 | + period = 5; |
| 52 | + iterations = 200; |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void onRun() { |
| 57 | + double xRotation, yRotation, zRotation; |
| 58 | + xRotation = step * angularVelocityX; |
| 59 | + yRotation = step * angularVelocityY; |
| 60 | + zRotation = step * angularVelocityZ; |
| 61 | + float a = edgeLenght / 2; |
| 62 | + for (int x = 0; x <= particles; x++) { |
| 63 | + float posX = edgeLenght * ((float) x / particles) - a; |
| 64 | + for (int y = 0; y <= particles; y++) { |
| 65 | + float posY = edgeLenght * ((float) y / particles) - a; |
| 66 | + for (int z = 0; z <= particles; z++) { |
| 67 | + if (x != 0 && x != particles && y != 0 && y != particles && z != 0 && z != particles) |
| 68 | + continue; |
| 69 | + float posZ = edgeLenght * ((float) z / particles) - a; |
| 70 | + Vector v = new Vector(posX, posY, posZ); |
| 71 | + VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); |
| 72 | + particle.display(location.add(v), visibleRange); |
| 73 | + location.subtract(v); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + step++; |
| 78 | + } |
| 79 | +} |
0 commit comments