Skip to content

Instantly share code, notes, and snippets.

@Exerosis
Created February 20, 2018 17:32
Show Gist options
  • Save Exerosis/7516750d16af2c564b0e1d4c31563212 to your computer and use it in GitHub Desktop.
Save Exerosis/7516750d16af2c564b0e1d4c31563212 to your computer and use it in GitHub Desktop.
public static class Particle {
private final String id;
private int count = 0;
private float data, x, y, z = 0;
public Particle(String id) {
this.id = id;
}
public static Particle create(String id) {
return new Particle(id);
}
@NotNull
public Particle color(@NotNull Color color) {
return color(color.getRed(), color.getGreen(), color.getBlue());
}
@NotNull
public Particle color(@NotNull Number red, @NotNull Number green, @NotNull Number blue) {
x = red.intValue() / 255f;
y = green.intValue() / 255f;
z = blue.intValue() / 255f;
return this;
}
@NotNull
public Particle offset(@NotNull Vector vector) {
x = (float) vector.getX();
y = (float) vector.getY();
z = (float) vector.getZ();
return this;
}
@NotNull
public Particle offset(@NotNull Number randSeed) {
return offset(randSeed, randSeed, randSeed);
}
@NotNull
public Particle offset(@NotNull Number x, @NotNull Number y, @NotNull Number z) {
this.x = x.floatValue();
this.y = y.floatValue();
this.z = z.floatValue();
return this;
}
@NotNull
public Particle data(float data) {
this.data = data;
return this;
}
@NotNull
public Particle count(@NotNull Number count) {
this.count = count.intValue();
return this;
}
}
public static void spawnParticle(@NotNull Particle particle, @NotNull Location location) {
spawnParticle(particle, location.toVector());
}
public static void spawnParticle(@NotNull Particle particle, @NotNull Vector location) {
spawnParticle(null, particle, location);
}
public static void spawnParticle(Player player, @NotNull Particle particle, @NotNull Location location) {
spawnParticle(player, particle, location.toVector());
}
public static void spawnParticle(@Nullable Player player, @NotNull Particle particle, @NotNull Vector location) {
PacketContainer packet = getProtocolManager().createPacket(WORLD_PARTICLES);
packet.getStrings().write(0, particle.id);
packet.getFloat().write(0, (float) location.getX());
packet.getFloat().write(1, (float) location.getY());
packet.getFloat().write(2, (float) location.getZ());
packet.getFloat().write(3, particle.x);
packet.getFloat().write(4, particle.y);
packet.getFloat().write(5, particle.z);
packet.getFloat().write(3, 6f);
packet.getFloat().write(4, 236f);
packet.getFloat().write(5, 233f);
packet.getFloat().write(6, particle.data);
packet.getIntegers().write(0, particle.count);
if (player != null) {
sendSilently(player, packet);
} else {
broadcastSilently(packet);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment