Improves particles
Some checks failed
KnarCraft/KnarLib/pipeline/head There was a failure building this commit
Some checks failed
KnarCraft/KnarLib/pipeline/head There was a failure building this commit
Allows specifying separate particle trails for each player. Removes random particles as a class option. Adds a particle config builder for easier particle specification.
This commit is contained in:
@ -0,0 +1,148 @@
|
||||
package net.knarcraft.knarlib.particle;
|
||||
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A builder for creating particle configurations
|
||||
*
|
||||
* <p>The default behavior will spawn a single particle with no offset or extra data, and density 1.</p>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class ParticleConfigBuilder {
|
||||
|
||||
private final Particle particleType;
|
||||
private ParticleMode particleMode = ParticleMode.SINGLE;
|
||||
private int particleAmount = 1;
|
||||
private double particleDensity = 1;
|
||||
private double heightOffset = 0;
|
||||
private double offsetX = 0;
|
||||
private double offsetY = 0;
|
||||
private double offsetZ = 0;
|
||||
private double extra = 0;
|
||||
|
||||
/**
|
||||
* Instantiates a new particle config builder
|
||||
*
|
||||
* @param particleType <p>The type of particle to spawn</p>
|
||||
*/
|
||||
public ParticleConfigBuilder(@NotNull Particle particleType) {
|
||||
this.particleType = particleType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mode to use when spawning the particles
|
||||
*
|
||||
* @param particleMode <p>The mode to use</p>
|
||||
* @return <p>This particle configuration builder</p>
|
||||
*/
|
||||
public @NotNull ParticleConfigBuilder setMode(@NotNull ParticleMode particleMode) {
|
||||
this.particleMode = particleMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the amount of particles to spawn
|
||||
*
|
||||
* @param particleAmount <p>The number/amount of particles to spawn</p>
|
||||
* @return <p>This particle configuration builder</p>
|
||||
*/
|
||||
public @NotNull ParticleConfigBuilder setAmount(int particleAmount) {
|
||||
this.particleAmount = particleAmount;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the density of the particles to spawn
|
||||
*
|
||||
* @param particleDensity <p>The new density</p>
|
||||
* @return <p>This particle configuration builder</p>
|
||||
*/
|
||||
public @NotNull ParticleConfigBuilder setDensity(double particleDensity) {
|
||||
this.particleDensity = particleDensity;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the x,y,z offsets of the spawned particles
|
||||
*
|
||||
* <p>These values control the spread of the spawned particles</p>
|
||||
*
|
||||
* @param offsetX <p>The offset in the x-direction</p>
|
||||
* @param offsetY <p>The offset in the y-direction</p>
|
||||
* @param offsetZ <p>The offset in the z-direction</p>
|
||||
* @return <p>This particle configuration builder</p>
|
||||
*/
|
||||
public @NotNull ParticleConfigBuilder setOffsets(double offsetX, double offsetY, double offsetZ) {
|
||||
this.offsetX = offsetX;
|
||||
this.offsetY = offsetY;
|
||||
this.offsetZ = offsetZ;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the x offset of the spawned particles
|
||||
*
|
||||
* @param offsetX <p>The offset in the x-direction</p>
|
||||
* @return <p>This particle configuration builder</p>
|
||||
*/
|
||||
public @NotNull ParticleConfigBuilder setXOffset(double offsetX) {
|
||||
this.offsetX = offsetX;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the y offset of the spawned particles
|
||||
*
|
||||
* @param offsetY <p>The offset in the y-direction</p>
|
||||
* @return <p>This particle configuration builder</p>
|
||||
*/
|
||||
public @NotNull ParticleConfigBuilder setYOffset(double offsetY) {
|
||||
this.offsetY = offsetY;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the z offset of the spawned particles
|
||||
*
|
||||
* @param offsetZ <p>The offset in the z-direction</p>
|
||||
* @return <p>This particle configuration builder</p>
|
||||
*/
|
||||
public @NotNull ParticleConfigBuilder setZOffset(double offsetZ) {
|
||||
this.offsetZ = offsetZ;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the extra data for the spawned particles
|
||||
*
|
||||
* @param extra <p>The extra data to set</p>
|
||||
* @return <p>This particle configuration builder</p>
|
||||
*/
|
||||
public @NotNull ParticleConfigBuilder setExtra(double extra) {
|
||||
this.extra = extra;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the height offset for the spawned particles
|
||||
*
|
||||
* @param heightOffset <p>The height offset to use</p>
|
||||
* @return <p>This particle configuration builder</p>
|
||||
*/
|
||||
public @NotNull ParticleConfigBuilder setHeightOffset(double heightOffset) {
|
||||
this.heightOffset = heightOffset;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the particle configuration
|
||||
*
|
||||
* @return <p>The built particle configuration</p>
|
||||
*/
|
||||
public @NotNull ParticleConfig build() {
|
||||
return new ParticleConfig(particleMode, particleType, particleAmount, particleDensity, heightOffset, offsetX,
|
||||
offsetY, offsetZ, extra);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user