mirror of
https://github.com/SunNetservers/Launchpad.git
synced 2025-03-31 08:46:29 +02:00
Allows specifying different particle effects depending on the material
This commit is contained in:
parent
c5b6588fbf
commit
2829a1af2b
39
README.md
39
README.md
@ -32,22 +32,23 @@ If you alter several launchpad values in succession, they'll all be applied to t
|
|||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
| Node | Type | Description |
|
| Node | Type | Description |
|
||||||
|-------------------------------------------------------------|-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| launchpad.materials | List | A list of materials, or material tags (+TAG_NAME), which are always treated as launchpads, without the need for manual registration. |
|
| launchpad.materials | List | A list of materials, or material tags (+TAG_NAME), which are always treated as launchpads, without the need for manual registration. |
|
||||||
| launchpad.materialWhitelist | List | A list of materials, or material tags (+TAG_NAME), which can be manually turned into launchpads. Use this to prevent unwanted blocks from being turned into launchpads. |
|
| launchpad.materialWhitelist | List | A list of materials, or material tags (+TAG_NAME), which can be manually turned into launchpads. Use this to prevent unwanted blocks from being turned into launchpads. |
|
||||||
| launchpad.verticalVelocity | Decimal number | The vertical (upwards) velocity applied to launchpads if not specified otherwise. |
|
| launchpad.verticalVelocity | Decimal number | The vertical (upwards) velocity applied to launchpads if not specified otherwise. |
|
||||||
| launchpad.horizontalVelocity | Decimal number | The horizontal (sideways) velocity applied to launchpads if not specified otherwise. |
|
| launchpad.horizontalVelocity | Decimal number | The horizontal (sideways) velocity applied to launchpads if not specified otherwise. |
|
||||||
| launchpad.materialVelocities.\<MATERIAL>.horizontalVelocity | Decimal number | The horizontal (sideways) velocity applied to launchpads of type \<MATERIAL> if not overridden for the block. |
|
| launchpad.materialVelocities.\<MATERIAL>.horizontalVelocity | Decimal number | The horizontal (sideways) velocity applied to launchpads of type \<MATERIAL> if not overridden for the block. |
|
||||||
| launchpad.materialVelocities.\<MATERIAL>.verticalVelocity | Decimal number | The vertical (sideways) velocity applied to launchpads of type \<MATERIAL> if not overridden for the block. |
|
| launchpad.materialVelocities.\<MATERIAL>.verticalVelocity | Decimal number | The vertical (sideways) velocity applied to launchpads of type \<MATERIAL> if not overridden for the block. |
|
||||||
| launchpad.particles.enabled | True / False | Whether to display some kind of particle effect above manually added launchpads. |
|
| launchpad.particles.enabled | True / False | Whether to display some kind of particle effect above manually added launchpads. |
|
||||||
| launchpad.particles.mode | SINGLE / SQUARE / PYRAMID / SPHERE / CIRCLE | The mode used for drawing particles. SINGLE directly spawns the particle(s) in one spot above the launchpad. The other ones spawn particles a bunch of times in a pattern. |
|
| launchpad.particles.mode | SINGLE / SQUARE / PYRAMID / SPHERE / CIRCLE | The mode used for drawing particles. SINGLE directly spawns the particle(s) in one spot above the launchpad. The other ones spawn particles a bunch of times in a pattern. |
|
||||||
| launchpad.particles.type | [Particle](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particle.html) | The type of particle to spawn above launchpads. |
|
| launchpad.particles.type | [Particle](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particle.html) | The type of particle to spawn above launchpads. |
|
||||||
| launchpad.particles.amount | Positive integer | The amount of particles to spawn. Use 1 if mode is anything except SINGLE, unless you know what you are doing! |
|
| launchpad.particles.amount | Positive integer | The amount of particles to spawn. Use 1 if mode is anything except SINGLE, unless you know what you are doing! |
|
||||||
| launchpad.particles.offsetX | Decimal number | The offset, or spread of the particles in the X direction, relative to the launchpad |
|
| launchpad.particles.offsetX | Decimal number | The offset, or spread of the particles in the X direction, relative to the launchpad |
|
||||||
| launchpad.particles.offsetY | Decimal number | The offset, or spread of the particles in the Y direction, relative to the launchpad |
|
| launchpad.particles.offsetY | Decimal number | The offset, or spread of the particles in the Y direction, relative to the launchpad |
|
||||||
| launchpad.particles.offsetZ | Decimal number | The offset, or spread of the particles in the Z direction, relative to the launchpad |
|
| launchpad.particles.offsetZ | Decimal number | The offset, or spread of the particles in the Z direction, relative to the launchpad |
|
||||||
| launchpad.particles.heightOffset | Decimal number | The amount of blocks above the launchpad the particle should spawn. 0.5 = half a block. 1 = one block. |
|
| launchpad.particles.heightOffset | Decimal number | The amount of blocks above the launchpad the particle should spawn. 0.5 = half a block. 1 = one block. |
|
||||||
| launchpad.particles.particleDensity | Decimal number | A definition for the number of particles used to draw shapes. The number of particles is basically `distance / particleDensity`, so lower numbers create a more dense shape. |
|
| launchpad.particles.particleDensity | Decimal number | A definition for the number of particles used to draw shapes. The number of particles is basically `distance / particleDensity`, so lower numbers create a more dense shape. |
|
||||||
| launchpad.particles.extra | Decimal number | Extra data for the specific particle. Check the Spigot documentation for details. |
|
| launchpad.particles.extra | Decimal number | Extra data for the specific particle. Check the Spigot documentation for details. |
|
||||||
| launchpad.particles.spawnDelay | Positive integer | The amount of ticks (1 second = 20 ticks) between each time the particle(s) should be spawned again. Depending on the particle, higher values will make the particle(s) completely disappear and reappear. |
|
| launchpad.particles.spawnDelay | Positive integer | The amount of ticks (1 second = 20 ticks) between each time the particle(s) should be spawned again. Depending on the particle, higher values will make the particle(s) completely disappear and reappear. |
|
||||||
|
| launchpad.particles.materialParticles | Configuration section | This section allows specifying different particle configurations for a material or a material tag. So you'd set materialParticles.LIGHT_WEIGHTED_PRESSURE_PLATE.type to set the particle type for LIGHT_WEIGHTED_PRESSURE_PLATE. |
|
@ -6,13 +6,14 @@ import net.knarcraft.launchpad.task.ParticleSpawner;
|
|||||||
import net.knarcraft.launchpad.util.MaterialHelper;
|
import net.knarcraft.launchpad.util.MaterialHelper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Particle;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@ -148,45 +149,51 @@ public class LaunchpadConfiguration {
|
|||||||
}
|
}
|
||||||
boolean previousEnabled = this.particlesEnabled;
|
boolean previousEnabled = this.particlesEnabled;
|
||||||
this.particlesEnabled = particlesSection.getBoolean("enabled", false);
|
this.particlesEnabled = particlesSection.getBoolean("enabled", false);
|
||||||
@NotNull Particle particleType;
|
|
||||||
try {
|
|
||||||
particleType = Particle.valueOf(particlesSection.getString("type"));
|
|
||||||
} catch (IllegalArgumentException exception) {
|
|
||||||
particleType = Particle.ASH;
|
|
||||||
}
|
|
||||||
int particleAmount = particlesSection.getInt("amount", 30);
|
|
||||||
double offsetX = particlesSection.getDouble("offsetX", 0.5);
|
|
||||||
double offsetY = particlesSection.getDouble("offsetY", 1);
|
|
||||||
double offsetZ = particlesSection.getDouble("offsetZ", 0.5);
|
|
||||||
double heightOffset = particlesSection.getDouble("heightOffset", 0.5);
|
|
||||||
double particleDensity = particlesSection.getDouble("particleDensity", 0.1);
|
|
||||||
double extra = particlesSection.getDouble("extra", 0);
|
|
||||||
int spawnDelay = particlesSection.getInt("spawnDelay", 20);
|
|
||||||
ParticleMode particleMode;
|
|
||||||
try {
|
|
||||||
particleMode = ParticleMode.valueOf(particlesSection.getString("mode"));
|
|
||||||
} catch (IllegalArgumentException exception) {
|
|
||||||
particleMode = ParticleMode.SINGLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure particle density is between 1 (inclusive) and 0 (exclusive)
|
|
||||||
if (particleDensity <= 0) {
|
|
||||||
particleDensity = 0.1;
|
|
||||||
} else if (particleDensity > 360) {
|
|
||||||
particleDensity = 360;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Cancel previous particle spawning task if previously enabled
|
||||||
if (previousEnabled) {
|
if (previousEnabled) {
|
||||||
// Cancel previous particle spawning task
|
|
||||||
Bukkit.getScheduler().cancelTask(particleTaskId);
|
Bukkit.getScheduler().cancelTask(particleTaskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start particle spawning if enabled
|
||||||
if (this.particlesEnabled) {
|
if (this.particlesEnabled) {
|
||||||
// Start particle spawning
|
LaunchpadParticleConfig particleConfig = new LaunchpadParticleConfig(particlesSection);
|
||||||
|
|
||||||
|
// Load any per-material configuration options
|
||||||
|
Map<Material, LaunchpadParticleConfig> materialConfigs;
|
||||||
|
ConfigurationSection perMaterialSection = particlesSection.getConfigurationSection("materialParticles");
|
||||||
|
if (perMaterialSection != null) {
|
||||||
|
materialConfigs = loadMaterialParticleConfigs(perMaterialSection);
|
||||||
|
} else {
|
||||||
|
materialConfigs = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
particleTaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(Launchpad.getInstance(),
|
particleTaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(Launchpad.getInstance(),
|
||||||
new ParticleSpawner(particleMode, particleType, particleAmount, particleDensity, heightOffset,
|
new ParticleSpawner(particleConfig, materialConfigs), 20, particleConfig.getSpawnDelay());
|
||||||
offsetX, offsetY, offsetZ, extra), 20, spawnDelay);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads all per-material particle configuration options
|
||||||
|
*
|
||||||
|
* @param perMaterialSection <p>The configuration section containing per-material particle options</p>
|
||||||
|
* @return <p>The loaded per-material particle configuration options</p>
|
||||||
|
*/
|
||||||
|
private @NotNull Map<Material, LaunchpadParticleConfig> loadMaterialParticleConfigs(
|
||||||
|
@NotNull ConfigurationSection perMaterialSection) {
|
||||||
|
Map<Material, LaunchpadParticleConfig> materialConfigs = new HashMap<>();
|
||||||
|
for (String key : perMaterialSection.getKeys(false)) {
|
||||||
|
Set<Material> materials = MaterialHelper.loadMaterialString(key);
|
||||||
|
ConfigurationSection materialSection = perMaterialSection.getConfigurationSection(key);
|
||||||
|
if (materialSection == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LaunchpadParticleConfig materialParticleConfig = new LaunchpadParticleConfig(materialSection);
|
||||||
|
for (Material material : materials) {
|
||||||
|
materialConfigs.put(material, materialParticleConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return materialConfigs;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,151 @@
|
|||||||
|
package net.knarcraft.launchpad.config;
|
||||||
|
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A configuration describing a launchpad
|
||||||
|
*/
|
||||||
|
public class LaunchpadParticleConfig {
|
||||||
|
|
||||||
|
private final ParticleMode particleMode;
|
||||||
|
private final Particle particleType;
|
||||||
|
private final int particleAmount;
|
||||||
|
private final double particleDensity;
|
||||||
|
private final double heightOffset;
|
||||||
|
private final int spawnDelay;
|
||||||
|
private final double offsetX;
|
||||||
|
private final double offsetY;
|
||||||
|
private final double offsetZ;
|
||||||
|
private final double extra;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new particle config
|
||||||
|
*
|
||||||
|
* @param particlesSection <p>The configuration section containing the particle's settings</p>
|
||||||
|
*/
|
||||||
|
public LaunchpadParticleConfig(ConfigurationSection particlesSection) {
|
||||||
|
@NotNull Particle particleType;
|
||||||
|
try {
|
||||||
|
particleType = Particle.valueOf(particlesSection.getString("type"));
|
||||||
|
} catch (IllegalArgumentException | NullPointerException exception) {
|
||||||
|
particleType = Particle.ASH;
|
||||||
|
}
|
||||||
|
this.particleType = particleType;
|
||||||
|
this.particleAmount = particlesSection.getInt("amount", 30);
|
||||||
|
this.offsetX = particlesSection.getDouble("offsetX", 0.5);
|
||||||
|
this.offsetY = particlesSection.getDouble("offsetY", 1);
|
||||||
|
this.offsetZ = particlesSection.getDouble("offsetZ", 0.5);
|
||||||
|
this.heightOffset = particlesSection.getDouble("heightOffset", 0.5);
|
||||||
|
this.extra = particlesSection.getDouble("extra", 0);
|
||||||
|
this.spawnDelay = particlesSection.getInt("spawnDelay", 20);
|
||||||
|
ParticleMode particleMode;
|
||||||
|
try {
|
||||||
|
particleMode = ParticleMode.valueOf(particlesSection.getString("mode"));
|
||||||
|
} catch (IllegalArgumentException | NullPointerException exception) {
|
||||||
|
particleMode = ParticleMode.SINGLE;
|
||||||
|
}
|
||||||
|
this.particleMode = particleMode;
|
||||||
|
|
||||||
|
// Make sure particle density is between 1 (inclusive) and 0 (exclusive)
|
||||||
|
double particleDensity = particlesSection.getDouble("particleDensity", 0.1);
|
||||||
|
if (particleDensity <= 0) {
|
||||||
|
particleDensity = 0.1;
|
||||||
|
} else if (particleDensity > 360) {
|
||||||
|
particleDensity = 360;
|
||||||
|
}
|
||||||
|
this.particleDensity = particleDensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mode to use when drawing/spawning the particle(s)
|
||||||
|
*
|
||||||
|
* @return <p>The particle mode</p>
|
||||||
|
*/
|
||||||
|
public ParticleMode getParticleMode() {
|
||||||
|
return particleMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of particle to spawn
|
||||||
|
*
|
||||||
|
* @return <p>The particle type</p>
|
||||||
|
*/
|
||||||
|
public Particle getParticleType() {
|
||||||
|
return particleType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The amount of particles to spawn
|
||||||
|
*
|
||||||
|
* @return <p>The amount of particles</p>
|
||||||
|
*/
|
||||||
|
public int getParticleAmount() {
|
||||||
|
return particleAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The density of particles to use in shapes closer to 0 causes larger density
|
||||||
|
*
|
||||||
|
* @return <p>The particle density</p>
|
||||||
|
*/
|
||||||
|
public double getParticleDensity() {
|
||||||
|
return particleDensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of blocks above the launchpad the particle(s) should spawn
|
||||||
|
*
|
||||||
|
* @return <p>The y-offset</p>
|
||||||
|
*/
|
||||||
|
public double getHeightOffset() {
|
||||||
|
return heightOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the delay in ticks to wait before spawning the particle(s) again
|
||||||
|
*
|
||||||
|
* @return <p>The spawn delay</p>
|
||||||
|
*/
|
||||||
|
public int getSpawnDelay() {
|
||||||
|
return spawnDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The offset/spread of particles in the x-direction
|
||||||
|
*
|
||||||
|
* @return <p>The x-offset</p>
|
||||||
|
*/
|
||||||
|
public double getOffsetX() {
|
||||||
|
return offsetX;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The offset/spread of particles in the y-direction
|
||||||
|
*
|
||||||
|
* @return <p>The y-offset</p>
|
||||||
|
*/
|
||||||
|
public double getOffsetY() {
|
||||||
|
return offsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The offset/spread of particles in the z-direction
|
||||||
|
*
|
||||||
|
* @return <p>The z-offset</p>
|
||||||
|
*/
|
||||||
|
public double getOffsetZ() {
|
||||||
|
return offsetZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The extra value to set for the particle. Exactly what it does depends on the particle.
|
||||||
|
*
|
||||||
|
* @return <p>The particle's extra value</p>
|
||||||
|
*/
|
||||||
|
public double getExtra() {
|
||||||
|
return extra;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,64 +1,43 @@
|
|||||||
package net.knarcraft.launchpad.task;
|
package net.knarcraft.launchpad.task;
|
||||||
|
|
||||||
import net.knarcraft.launchpad.config.ParticleMode;
|
import net.knarcraft.launchpad.config.LaunchpadParticleConfig;
|
||||||
import net.knarcraft.launchpad.launchpad.LaunchpadBlock;
|
import net.knarcraft.launchpad.launchpad.LaunchpadBlock;
|
||||||
import net.knarcraft.launchpad.launchpad.LaunchpadBlockHandler;
|
import net.knarcraft.launchpad.launchpad.LaunchpadBlockHandler;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.util.BoundingBox;
|
import org.bukkit.util.BoundingBox;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A runnable tasks that spawns particles at every launchpad
|
* A runnable tasks that spawns particles at every launchpad
|
||||||
*/
|
*/
|
||||||
public class ParticleSpawner implements Runnable {
|
public class ParticleSpawner implements Runnable {
|
||||||
|
|
||||||
private final ParticleMode particleMode;
|
|
||||||
private final Particle particleType;
|
|
||||||
private final int particleAmount;
|
|
||||||
private final double particleDensity;
|
|
||||||
private final double heightOffset;
|
|
||||||
private final double offsetX;
|
|
||||||
private final double offsetY;
|
|
||||||
private final double offsetZ;
|
|
||||||
private final double extra;
|
|
||||||
|
|
||||||
private Vector[] pyramidVectors;
|
private Vector[] pyramidVectors;
|
||||||
private double[][] circleCoordinates;
|
private double[][] circleCoordinates;
|
||||||
private double[][] sphereCoordinates;
|
private double[][] sphereCoordinates;
|
||||||
|
|
||||||
|
private final LaunchpadParticleConfig particleConfig;
|
||||||
|
private final Map<Material, LaunchpadParticleConfig> materialConfigs;
|
||||||
private LaunchpadBlock processingLaunchpad = null;
|
private LaunchpadBlock processingLaunchpad = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new particle spawner
|
* Instantiates a new particle spawner
|
||||||
*
|
*
|
||||||
* @param particleMode <p>The mode used when spawning particles</p>
|
* @param particleConfig <p>The configuration for the particle to spawn</p>
|
||||||
* @param particleType <p>The type of particle to spawn</p>
|
|
||||||
* @param particleAmount <p>The amount of particles to spawn at once</p>
|
|
||||||
* @param particleDensity <p>The density of particles for particle shapes. Lower = more particles.</p>
|
|
||||||
* @param heightOffset <p>The height above the launchpad the particle should spawn</p>
|
|
||||||
* @param offsetX <p>The offset of the particle in the X direction</p>
|
|
||||||
* @param offsetY <p>The offset of the particle in the Y direction</p>
|
|
||||||
* @param offsetZ <p>The offset of the particle in the Z direction</p>
|
|
||||||
* @param extra <p>Extra data for the particle</p>
|
|
||||||
*/
|
*/
|
||||||
public ParticleSpawner(@NotNull ParticleMode particleMode, @NotNull Particle particleType, int particleAmount,
|
public ParticleSpawner(LaunchpadParticleConfig particleConfig, Map<Material,
|
||||||
double particleDensity, double heightOffset, double offsetX, double offsetY, double offsetZ,
|
LaunchpadParticleConfig> materialConfigs) {
|
||||||
double extra) {
|
this.particleConfig = particleConfig;
|
||||||
this.particleMode = particleMode;
|
this.materialConfigs = materialConfigs;
|
||||||
this.particleType = particleType;
|
|
||||||
this.particleAmount = particleAmount;
|
|
||||||
this.particleDensity = particleDensity;
|
|
||||||
this.heightOffset = heightOffset;
|
|
||||||
this.offsetX = offsetX;
|
|
||||||
this.offsetY = offsetY;
|
|
||||||
this.offsetZ = offsetZ;
|
|
||||||
this.extra = extra;
|
|
||||||
|
|
||||||
this.pyramidVectors = null;
|
this.pyramidVectors = null;
|
||||||
this.circleCoordinates = null;
|
this.circleCoordinates = null;
|
||||||
|
this.sphereCoordinates = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -78,8 +57,9 @@ public class ParticleSpawner implements Runnable {
|
|||||||
// Store the currently processed launchpad for height calculation
|
// Store the currently processed launchpad for height calculation
|
||||||
processingLaunchpad = launchpad;
|
processingLaunchpad = launchpad;
|
||||||
|
|
||||||
switch (particleMode) {
|
switch (getParticleConfig().getParticleMode()) {
|
||||||
case SINGLE -> spawnParticle(world, location.clone().add(0.5, heightOffset, 0.5));
|
case SINGLE -> spawnParticle(world, location.clone().add(
|
||||||
|
0.5, getParticleConfig().getHeightOffset(), 0.5));
|
||||||
case SQUARE -> drawSquare(world, location);
|
case SQUARE -> drawSquare(world, location);
|
||||||
case CIRCLE -> drawCircle(world, location);
|
case CIRCLE -> drawCircle(world, location);
|
||||||
case PYRAMID -> drawPyramid(world, location);
|
case PYRAMID -> drawPyramid(world, location);
|
||||||
@ -88,6 +68,19 @@ public class ParticleSpawner implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the particle config to use for the current launchpad's material
|
||||||
|
*
|
||||||
|
* @return <p>The particle config to use</p>
|
||||||
|
*/
|
||||||
|
private LaunchpadParticleConfig getParticleConfig() {
|
||||||
|
LaunchpadParticleConfig materialConfig = this.materialConfigs.get(processingLaunchpad.getBlock().getType());
|
||||||
|
if (materialConfig != null) {
|
||||||
|
return materialConfig;
|
||||||
|
}
|
||||||
|
return this.particleConfig;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spawns a sphere of particles at the given location
|
* Spawns a sphere of particles at the given location
|
||||||
*
|
*
|
||||||
@ -97,7 +90,7 @@ public class ParticleSpawner implements Runnable {
|
|||||||
private void drawSphere(@NotNull World world, @NotNull Location location) {
|
private void drawSphere(@NotNull World world, @NotNull Location location) {
|
||||||
// For spheres, densities below 0.1 has weird bugs such as blinking in and out of existence, and floating point
|
// For spheres, densities below 0.1 has weird bugs such as blinking in and out of existence, and floating point
|
||||||
// errors when calculating the length of circleCoordinates
|
// errors when calculating the length of circleCoordinates
|
||||||
double density = Math.max(1, particleDensity);
|
double density = Math.max(1, getParticleConfig().getParticleDensity());
|
||||||
// Store calculations for improved efficiency
|
// Store calculations for improved efficiency
|
||||||
if (sphereCoordinates == null) {
|
if (sphereCoordinates == null) {
|
||||||
int length = (int) Math.ceil((180 / density));
|
int length = (int) Math.ceil((180 / density));
|
||||||
@ -108,11 +101,11 @@ public class ParticleSpawner implements Runnable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sphereCoordinates[i++] = new double[]{(0.5 * Math.sin(x)) + 0.5,
|
sphereCoordinates[i++] = new double[]{(0.5 * Math.sin(x)) + 0.5,
|
||||||
heightOffset + 0.5, (0.5 * Math.cos(x)) + 0.5};
|
getParticleConfig().getHeightOffset() + 0.5, (0.5 * Math.cos(x)) + 0.5};
|
||||||
sphereCoordinates[i++] = new double[]{(0.5 * Math.sin(x)) + 0.5,
|
sphereCoordinates[i++] = new double[]{(0.5 * Math.sin(x)) + 0.5,
|
||||||
heightOffset + 0.5 + (0.5 * Math.cos(x)), 0.5};
|
getParticleConfig().getHeightOffset() + 0.5 + (0.5 * Math.cos(x)), 0.5};
|
||||||
sphereCoordinates[i++] = new double[]{0.5,
|
sphereCoordinates[i++] = new double[]{0.5,
|
||||||
heightOffset + 0.5 + (0.5 * Math.sin(x)), (0.5 * Math.cos(x)) + 0.5};
|
getParticleConfig().getHeightOffset() + 0.5 + (0.5 * Math.sin(x)), (0.5 * Math.cos(x)) + 0.5};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,12 +128,12 @@ public class ParticleSpawner implements Runnable {
|
|||||||
// Store calculations for improved efficiency
|
// Store calculations for improved efficiency
|
||||||
if (pyramidVectors == null) {
|
if (pyramidVectors == null) {
|
||||||
// The 0.5 offsets are required for the angle of the pyramid's 4 lines to be correct
|
// The 0.5 offsets are required for the angle of the pyramid's 4 lines to be correct
|
||||||
double coordinateMin = -0.5 * heightOffset;
|
double coordinateMin = -0.5 * getParticleConfig().getHeightOffset();
|
||||||
double coordinateMax = 1 + (0.5 * heightOffset);
|
double coordinateMax = 1 + (0.5 * getParticleConfig().getHeightOffset());
|
||||||
|
|
||||||
pyramidVectors = new Vector[5];
|
pyramidVectors = new Vector[5];
|
||||||
// The vector from the origin to the top of the pyramid
|
// The vector from the origin to the top of the pyramid
|
||||||
pyramidVectors[0] = new Vector(0.5, 1 + heightOffset, 0.5);
|
pyramidVectors[0] = new Vector(0.5, 1 + getParticleConfig().getHeightOffset(), 0.5);
|
||||||
// The vectors from the top of the pyramid towards each corner
|
// The vectors from the top of the pyramid towards each corner
|
||||||
pyramidVectors[1] = new Vector(coordinateMin, 0, coordinateMin).subtract(pyramidVectors[0]).normalize();
|
pyramidVectors[1] = new Vector(coordinateMin, 0, coordinateMin).subtract(pyramidVectors[0]).normalize();
|
||||||
pyramidVectors[2] = new Vector(coordinateMax, 0, coordinateMin).subtract(pyramidVectors[0]).normalize();
|
pyramidVectors[2] = new Vector(coordinateMax, 0, coordinateMin).subtract(pyramidVectors[0]).normalize();
|
||||||
@ -149,7 +142,7 @@ public class ParticleSpawner implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Location topLocation = location.clone().add(pyramidVectors[0]);
|
Location topLocation = location.clone().add(pyramidVectors[0]);
|
||||||
for (double x = 0; x <= 1.2; x += particleDensity) {
|
for (double x = 0; x <= 1.2; x += getParticleConfig().getParticleDensity()) {
|
||||||
spawnParticle(world, topLocation.clone().add(pyramidVectors[1].clone().multiply(x)));
|
spawnParticle(world, topLocation.clone().add(pyramidVectors[1].clone().multiply(x)));
|
||||||
spawnParticle(world, topLocation.clone().add(pyramidVectors[2].clone().multiply(x)));
|
spawnParticle(world, topLocation.clone().add(pyramidVectors[2].clone().multiply(x)));
|
||||||
spawnParticle(world, topLocation.clone().add(pyramidVectors[3].clone().multiply(x)));
|
spawnParticle(world, topLocation.clone().add(pyramidVectors[3].clone().multiply(x)));
|
||||||
@ -166,7 +159,7 @@ public class ParticleSpawner implements Runnable {
|
|||||||
private void drawCircle(@NotNull World world, @NotNull Location location) {
|
private void drawCircle(@NotNull World world, @NotNull Location location) {
|
||||||
// For circles, densities below 0.1 has weird bugs such as blinking in and out of existence, and floating point
|
// For circles, densities below 0.1 has weird bugs such as blinking in and out of existence, and floating point
|
||||||
// errors when calculating the length of circleCoordinates
|
// errors when calculating the length of circleCoordinates
|
||||||
double density = Math.max(1, particleDensity);
|
double density = Math.max(1, getParticleConfig().getParticleDensity());
|
||||||
// Store calculations for improved efficiency
|
// Store calculations for improved efficiency
|
||||||
if (circleCoordinates == null) {
|
if (circleCoordinates == null) {
|
||||||
circleCoordinates = new double[(int) Math.ceil((180 / density))][];
|
circleCoordinates = new double[(int) Math.ceil((180 / density))][];
|
||||||
@ -181,7 +174,7 @@ public class ParticleSpawner implements Runnable {
|
|||||||
|
|
||||||
// Spawn particles on the stored locations, relative to the launchpad
|
// Spawn particles on the stored locations, relative to the launchpad
|
||||||
for (double[] circleCoordinate : circleCoordinates) {
|
for (double[] circleCoordinate : circleCoordinates) {
|
||||||
spawnParticle(world, location.clone().add(circleCoordinate[0], heightOffset, circleCoordinate[1]));
|
spawnParticle(world, location.clone().add(circleCoordinate[0], getParticleConfig().getHeightOffset(), circleCoordinate[1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,11 +185,11 @@ public class ParticleSpawner implements Runnable {
|
|||||||
* @param location <p>The location of the block to spawn the particles at</p>
|
* @param location <p>The location of the block to spawn the particles at</p>
|
||||||
*/
|
*/
|
||||||
private void drawSquare(@NotNull World world, @NotNull Location location) {
|
private void drawSquare(@NotNull World world, @NotNull Location location) {
|
||||||
for (float x = 0; x <= 1; x += particleDensity) {
|
for (float x = 0; x <= 1; x += getParticleConfig().getParticleDensity()) {
|
||||||
spawnParticle(world, location.clone().add(x, heightOffset, 0));
|
spawnParticle(world, location.clone().add(x, getParticleConfig().getHeightOffset(), 0));
|
||||||
spawnParticle(world, location.clone().add(x, heightOffset, 1));
|
spawnParticle(world, location.clone().add(x, getParticleConfig().getHeightOffset(), 1));
|
||||||
spawnParticle(world, location.clone().add(0, heightOffset, x));
|
spawnParticle(world, location.clone().add(0, getParticleConfig().getHeightOffset(), x));
|
||||||
spawnParticle(world, location.clone().add(1, heightOffset, x));
|
spawnParticle(world, location.clone().add(1, getParticleConfig().getHeightOffset(), x));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,8 +200,10 @@ public class ParticleSpawner implements Runnable {
|
|||||||
* @param location <p>The location to spawn the particle at</p>
|
* @param location <p>The location to spawn the particle at</p>
|
||||||
*/
|
*/
|
||||||
private void spawnParticle(@NotNull World world, @NotNull Location location) {
|
private void spawnParticle(@NotNull World world, @NotNull Location location) {
|
||||||
world.spawnParticle(particleType, location.add(0, getBlockHeight(processingLaunchpad), 0), particleAmount,
|
world.spawnParticle(getParticleConfig().getParticleType(),
|
||||||
offsetX, offsetY, offsetZ, extra);
|
location.add(0, getBlockHeight(processingLaunchpad), 0), getParticleConfig().getParticleAmount(),
|
||||||
|
getParticleConfig().getOffsetX(), getParticleConfig().getOffsetY(), getParticleConfig().getOffsetZ(),
|
||||||
|
getParticleConfig().getExtra());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,18 +33,30 @@ public final class MaterialHelper {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to parse a material tag first
|
parsedMaterials.addAll(loadMaterialString(string));
|
||||||
if (parseMaterialTag(parsedMaterials, string)) {
|
}
|
||||||
continue;
|
return parsedMaterials;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to parse a material name
|
/**
|
||||||
Material matched = Material.matchMaterial(string);
|
* Parses a string representing a material or a material tag
|
||||||
if (matched != null) {
|
*
|
||||||
parsedMaterials.add(matched);
|
* @param materialString <p>The material string to parse</p>
|
||||||
} else {
|
* @return <p>The materials defined by the material string, or an empty list if none were found</p>
|
||||||
Launchpad.log(Level.WARNING, "&cUnable to parse material: " + string);
|
*/
|
||||||
}
|
public static @NotNull Set<Material> loadMaterialString(@NotNull String materialString) {
|
||||||
|
Set<Material> parsedMaterials = new HashSet<>();
|
||||||
|
// Try to parse a material tag first
|
||||||
|
if (parseMaterialTag(parsedMaterials, materialString)) {
|
||||||
|
return parsedMaterials;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to parse a material name
|
||||||
|
Material matched = Material.matchMaterial(materialString);
|
||||||
|
if (matched != null) {
|
||||||
|
parsedMaterials.add(matched);
|
||||||
|
} else {
|
||||||
|
Launchpad.log(Level.WARNING, "&cUnable to parse material: " + materialString);
|
||||||
}
|
}
|
||||||
return parsedMaterials;
|
return parsedMaterials;
|
||||||
}
|
}
|
||||||
|
@ -47,4 +47,7 @@ launchpad:
|
|||||||
extra: 0
|
extra: 0
|
||||||
# The amount of ticks (1 second = 20 ticks) between each time the particle(s) should be spawned again. Depending on
|
# The amount of ticks (1 second = 20 ticks) between each time the particle(s) should be spawned again. Depending on
|
||||||
# the particle, higher values will make the particle(s) completely disappear and reappear.
|
# the particle, higher values will make the particle(s) completely disappear and reappear.
|
||||||
spawnDelay: 20
|
spawnDelay: 20
|
||||||
|
# Particle configurations per material. So you'd set materialParticles.LIGHT_WEIGHTED_PRESSURE_PLATE.type to set the
|
||||||
|
# particle type for LIGHT_WEIGHTED_PRESSURE_PLATE.
|
||||||
|
materialParticles: [ ]
|
Loading…
x
Reference in New Issue
Block a user