Stage 14: Polish and utilities
This commit is contained in:
parent
7cbc4e397e
commit
362b791774
3 changed files with 145 additions and 391 deletions
|
|
@ -6,199 +6,94 @@ import org.bukkit.Particle;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class ParticleUtil {
|
||||
|
||||
private static final int DEFAULT_COUNT = 1;
|
||||
private static final double DEFAULT_SPREAD = 0.0;
|
||||
private static final float DEFAULT_SIZE = 1.0f;
|
||||
|
||||
private ParticleUtil() {}
|
||||
|
||||
public static void spawn(Particle particle, Location location) {
|
||||
spawn(particle, location, DEFAULT_COUNT);
|
||||
public static void spawn(Particle p, Location loc, int count) {
|
||||
World w = loc.getWorld(); if (w == null) return;
|
||||
w.spawnParticle(p, loc, count);
|
||||
}
|
||||
|
||||
public static void spawn(Particle particle, Location location, int count) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(particle, location, count);
|
||||
public static void spawn(Particle p, Location loc, int count, double sx, double sy, double sz, double speed) {
|
||||
World w = loc.getWorld(); if (w == null) return;
|
||||
w.spawnParticle(p, loc, count, sx, sy, sz, speed);
|
||||
}
|
||||
|
||||
public static void spawn(Particle particle, Location location, int count, double spreadX, double spreadY, double spreadZ) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(particle, location, count, spreadX, spreadY, spreadZ);
|
||||
public static void spawnDust(Location loc, Color c, float size) {
|
||||
World w = loc.getWorld(); if (w == null) return;
|
||||
w.spawnParticle(Particle.DUST, loc, 1, new Particle.DustOptions(c, size));
|
||||
}
|
||||
|
||||
public static void spawn(Particle particle, Location location, int count, double spreadX, double spreadY, double spreadZ, double speed) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(particle, location, count, spreadX, spreadY, spreadZ, speed);
|
||||
public static void spawnDust(Location loc, Color c, float size, int count) {
|
||||
World w = loc.getWorld(); if (w == null) return;
|
||||
w.spawnParticle(Particle.DUST, loc, count, 0.1, 0.1, 0.1, 0, new Particle.DustOptions(c, size));
|
||||
}
|
||||
|
||||
public static void spawnDust(Location location, Color color, float size) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
Particle.DustOptions dustOptions = new Particle.DustOptions(color, size);
|
||||
world.spawnParticle(Particle.DUST, location, 1, dustOptions);
|
||||
public static void drawLine(Particle p, Location a, Location b, int points) {
|
||||
if (!a.getWorld().equals(b.getWorld())) return;
|
||||
Vector dir = b.toVector().subtract(a.toVector());
|
||||
double dist = dir.length(); dir.normalize();
|
||||
double step = dist / points; Location cur = a.clone();
|
||||
for (int i = 0; i <= points; i++) { spawn(p, cur, 1); cur.add(dir.clone().multiply(step)); }
|
||||
}
|
||||
|
||||
public static void spawnDust(Location location, Color color, float size, int count) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
Particle.DustOptions dustOptions = new Particle.DustOptions(color, size);
|
||||
world.spawnParticle(Particle.DUST, location, count, 0.1, 0.1, 0.1, 0, dustOptions);
|
||||
}
|
||||
|
||||
public static void spawnToPlayer(Particle particle, Player player, Location location, int count) {
|
||||
player.spawnParticle(particle, location, count);
|
||||
}
|
||||
|
||||
public static void spawnToPlayer(Particle particle, Player player, Location location, int count, double spreadX, double spreadY, double spreadZ) {
|
||||
player.spawnParticle(particle, location, count, spreadX, spreadY, spreadZ);
|
||||
}
|
||||
|
||||
public static void drawLine(Particle particle, Location start, Location end, int points) {
|
||||
if (!start.getWorld().equals(end.getWorld())) return;
|
||||
|
||||
Vector direction = end.toVector().subtract(start.toVector());
|
||||
double distance = direction.length();
|
||||
direction.normalize();
|
||||
|
||||
double step = distance / points;
|
||||
Location current = start.clone();
|
||||
|
||||
for (int i = 0; i <= points; i++) {
|
||||
spawn(particle, current);
|
||||
current.add(direction.clone().multiply(step));
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawCircle(Particle particle, Location center, double radius, int points) {
|
||||
World world = center.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
public static void drawCircle(Particle p, Location c, double r, int points) {
|
||||
World w = c.getWorld(); if (w == null) return;
|
||||
for (int i = 0; i < points; i++) {
|
||||
double angle = 2 * Math.PI * i / points;
|
||||
double x = center.getX() + radius * Math.cos(angle);
|
||||
double z = center.getZ() + radius * Math.sin(angle);
|
||||
Location point = new Location(world, x, center.getY(), z);
|
||||
spawn(particle, point);
|
||||
double a = 2 * Math.PI * i / points;
|
||||
spawn(p, new Location(w, c.getX() + r * Math.cos(a), c.getY(), c.getZ() + r * Math.sin(a)), 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawCircle(Particle particle, Location center, double radius, int points, Color color, float size) {
|
||||
World world = center.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
public static void drawCircle(Particle p, Location c, double r, int points, Color col, float size) {
|
||||
World w = c.getWorld(); if (w == null) return;
|
||||
for (int i = 0; i < points; i++) {
|
||||
double angle = 2 * Math.PI * i / points;
|
||||
double x = center.getX() + radius * Math.cos(angle);
|
||||
double z = center.getZ() + radius * Math.sin(angle);
|
||||
Location point = new Location(world, x, center.getY(), z);
|
||||
spawnDust(point, color, size);
|
||||
double a = 2 * Math.PI * i / points;
|
||||
spawnDust(new Location(w, c.getX() + r * Math.cos(a), c.getY(), c.getZ() + r * Math.sin(a)), col, size);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawSphere(Particle particle, Location center, double radius, int points) {
|
||||
World world = center.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
for (int i = 0; i < points; i++) {
|
||||
double theta = Math.random() * 2 * Math.PI;
|
||||
double phi = Math.random() * Math.PI;
|
||||
double x = center.getX() + radius * Math.sin(phi) * Math.cos(theta);
|
||||
double y = center.getY() + radius * Math.cos(phi);
|
||||
double z = center.getZ() + radius * Math.sin(phi) * Math.sin(theta);
|
||||
Location point = new Location(world, x, y, z);
|
||||
spawn(particle, point);
|
||||
}
|
||||
public static void burst(Particle p, Location c, int count, double speed) {
|
||||
World w = c.getWorld(); if (w == null) return;
|
||||
w.spawnParticle(p, c, count, 0.5, 0.5, 0.5, speed);
|
||||
}
|
||||
|
||||
public static void drawBox(Particle particle, Location min, Location max, double step) {
|
||||
if (!min.getWorld().equals(max.getWorld())) return;
|
||||
World world = min.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
for (double x = min.getX(); x <= max.getX(); x += step) {
|
||||
for (double y = min.getY(); y <= max.getY(); y += step) {
|
||||
for (double z = min.getZ(); z <= max.getZ(); z += step) {
|
||||
boolean edge = (x <= min.getX() + step || x >= max.getX() - step) ||
|
||||
(y <= min.getY() + step || y >= max.getY() - step) ||
|
||||
(z <= min.getZ() + step || z >= max.getZ() - step);
|
||||
if (edge) {
|
||||
spawn(particle, new Location(world, x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void burstToPlayers(Particle p, List<Player> players, Location c, int count, double speed) {
|
||||
for (Player pl : players) pl.spawnParticle(p, c, count, 0.5, 0.5, 0.5, speed);
|
||||
}
|
||||
|
||||
public static void burst(Particle particle, Location center, int count, double speed) {
|
||||
World world = center.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(particle, center, count, 0.5, 0.5, 0.5, speed);
|
||||
public static void trail(Particle p, Location start, Vector dir, int len, double spacing) {
|
||||
Location cur = start.clone(); Vector step = dir.clone().normalize().multiply(spacing);
|
||||
for (int i = 0; i < len; i++) { spawn(p, cur, 1); cur.add(step); }
|
||||
}
|
||||
|
||||
public static void burstToPlayers(Particle particle, List<Player> players, Location center, int count, double speed) {
|
||||
for (Player player : players) {
|
||||
player.spawnParticle(particle, center, count, 0.5, 0.5, 0.5, speed);
|
||||
}
|
||||
public static void shockwave(Particle p, Location c, double maxR, int rings, double speed) {
|
||||
for (int i = 1; i <= rings; i++) drawCircle(p, c, (maxR / rings) * i, (int) (16 * (maxR / rings) * i));
|
||||
}
|
||||
|
||||
public static void trail(Particle particle, Location start, Vector direction, int length, double spacing) {
|
||||
Location current = start.clone();
|
||||
Vector step = direction.clone().normalize().multiply(spacing);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
spawn(particle, current);
|
||||
current.add(step);
|
||||
}
|
||||
public static void damage(Location loc) {
|
||||
World w = loc.getWorld(); if (w == null) return;
|
||||
w.spawnParticle(Particle.DAMAGE_INDICATOR, loc, 10, 0.3, 0.3, 0.3, 0);
|
||||
}
|
||||
|
||||
public static void shockwave(Particle particle, Location center, double maxRadius, int rings, double speed) {
|
||||
World world = center.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
for (int ring = 1; ring <= rings; ring++) {
|
||||
double radius = (maxRadius / rings) * ring;
|
||||
int points = (int) (16 * radius);
|
||||
drawCircle(particle, center, radius, points);
|
||||
}
|
||||
}
|
||||
|
||||
public static void damageIndicator(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(Particle.DAMAGE_INDICATOR, location, 10, 0.3, 0.3, 0.3, 0);
|
||||
}
|
||||
|
||||
public static void blood(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(Particle.BLOCK_CRUMBLE, location, 20, 0.2, 0.2, 0.2, 0,
|
||||
public static void blood(Location loc) {
|
||||
World w = loc.getWorld(); if (w == null) return;
|
||||
w.spawnParticle(Particle.BLOCK_CRUMBLE, loc, 20, 0.2, 0.2, 0.2, 0,
|
||||
org.bukkit.Material.REDSTONE_BLOCK.createBlockData());
|
||||
}
|
||||
|
||||
public static void sparks(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(Particle.ELECTRIC_SPARK, location, 5, 0.1, 0.1, 0.1, 0.1);
|
||||
public static void sparks(Location loc) {
|
||||
World w = loc.getWorld(); if (w == null) return;
|
||||
w.spawnParticle(Particle.ELECTRIC_SPARK, loc, 5, 0.1, 0.1, 0.1, 0.1);
|
||||
}
|
||||
|
||||
public static void heal(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
spawnDust(location, Color.LIME, 1.0f, 10);
|
||||
}
|
||||
public static void heal(Location loc) { spawnDust(loc, Color.LIME, 1.0f, 10); }
|
||||
|
||||
public static void teleportEffect(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(Particle.PORTAL, location, 100, 0.5, 1.0, 0.5, 1.0);
|
||||
world.spawnParticle(Particle.REVERSE_PORTAL, location, 50, 0.3, 0.5, 0.3, 0.5);
|
||||
public static void teleportEffect(Location loc) {
|
||||
World w = loc.getWorld(); if (w == null) return;
|
||||
w.spawnParticle(Particle.PORTAL, loc, 100, 0.5, 1.0, 0.5, 1.0);
|
||||
w.spawnParticle(Particle.REVERSE_PORTAL, loc, 50, 0.3, 0.5, 0.3, 0.5);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue