Skip to content

Instantly share code, notes, and snippets.

@Kr1lle
Last active November 8, 2018 17:16
Show Gist options
  • Save Kr1lle/885eba9d5f4697d81c689f955a382912 to your computer and use it in GitHub Desktop.
Save Kr1lle/885eba9d5f4697d81c689f955a382912 to your computer and use it in GitHub Desktop.
A utility class that allows you to create particle capes. Created by: iSach and Chris/Krille.
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.util.Vector;
public class Cape {
private boolean[][] shape;
private Color color;
public Cape(Color color, boolean[][] shape) {
this.shape = shape;
this.color = color;
}
public void spawn(Location location) {
double space = 0.2;
double defX = location.getX() - (space * shape[0].length / 2) + space / 2;
double x = defX;
double defY = location.getY() + 1.5;
double y = defY;
double angle = -((location.getYaw() + 180) / 60);
angle += (location.getYaw() < -180 ? 3.25 : 2.985);
for (int i = 0; i < shape.length; i++) {
for (int j = 0; j < shape[i].length; j++) {
if (shape[i][j]) {
Location target = location.clone();
target.setX(x);
target.setY(y);
Vector v = target.toVector().subtract(location.toVector());
Vector v2 = getBackVector(location);
v = rotateAroundAxisY(v, angle);
double iT = ((double) i) / 10;
v2.setY(0).multiply(-0.2 - iT);
Location loc = location.clone();
loc.add(v);
loc.add(v2);
for (int k = 0; k < 3; k++)
ParticleEffect.REDSTONE.display(new ParticleEffect.OrdinaryColor(color), loc, 258);
loc.subtract(v2);
loc.subtract(v);
}
x += space;
}
y -= space;
x = defX;
}
}
public Vector rotateAroundAxisY(Vector v, double angle) {
double x, z, cos, sin;
cos = Math.cos(angle);
sin = Math.sin(angle);
x = v.getX() * cos + v.getZ() * sin;
z = v.getX() * -sin + v.getZ() * cos;
return v.setX(x).setZ(z);
}
public final Vector rotateAroundAxisX(Vector v, double angle) {
double y, z, cos, sin;
cos = Math.cos(angle);
sin = Math.sin(angle);
y = v.getY() * cos - v.getZ() * sin;
z = v.getY() * sin + v.getZ() * cos;
return v.setY(y).setZ(z);
}
public final Vector rotateAroundAxisZ(Vector v, double angle) {
double x, y, cos, sin;
cos = Math.cos(angle);
sin = Math.sin(angle);
x = v.getX() * cos - v.getY() * sin;
y = v.getX() * sin + v.getY() * cos;
return v.setX(x).setY(y);
}
public Vector getBackVector(Location loc) {
final float newZ = (float) (loc.getZ() + (1 * Math.sin(Math.toRadians(loc.getYaw() + 90))));
final float newX = (float) (loc.getX() + (1 * Math.cos(Math.toRadians(loc.getYaw() + 90))));
return new Vector(newX - loc.getX(), 0, newZ - loc.getZ());
}
}
@jwpjrdev
Copy link

jwpjrdev commented Nov 8, 2018

Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment