Normalize particles for all versions and optimize radius

This commit is contained in:
NotAlexNoyle committed 2026-09-14 01:34:06 -04:00
1 parent 31070db577
commit b9482d55ae
2 files changed
+43 -7

No files matched your search

@@ -1,6 +1,8 @@
package net.trueog.launchpadsog;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -39,6 +41,9 @@ public final class LaunchPadsOG extends JavaPlugin {
// lookup instead of scanning every configured pad on every step.
private static final Map<String, Integer> padsByBlock = new HashMap<>();
// Particle reach, squared. Vanilla un-forced range on modern clients.
private static final double PARTICLE_RANGE_SQUARED = 32 * 32;
@Override
public void onEnable() {
@@ -108,7 +113,7 @@ public final class LaunchPadsOG extends JavaPlugin {
// Use PORTAL, what ViaRewind downgrades DRAGON_BREATH to, so 1.8 and modern
// clients match.
world.spawnParticle(Particle.PORTAL, padLocation, idleParticleCount, 0, 0, 0, 0.05 * idleParticlePower);
spawnParticleForAllClients(Particle.PORTAL, padLocation, idleParticleCount, 0.05 * idleParticlePower);
}
@@ -116,6 +121,38 @@ public final class LaunchPadsOG extends JavaPlugin {
}
// Forced particle within 32 blocks, so 1.8 and modern clients match.
public static void spawnParticleForAllClients(Particle particle, Location location, int count, double speed) {
final World world = location.getWorld();
if (world == null) {
return;
}
final List<Player> receivers = new ArrayList<>();
for (final Player player : world.getPlayers()) {
if (player.getLocation().distanceSquared(location) <= PARTICLE_RANGE_SQUARED) {
receivers.add(player);
}
}
if (receivers.isEmpty()) {
return;
}
world.spawnParticle(particle, receivers, null, location.getX(), location.getY(), location.getZ(), count, 0, 0,
0, speed, null, true);
}
@Override
public void onDisable() {
@@ -160,7 +160,7 @@ public class OnPlayerMove implements Listener {
final double padParticleCount = padConfig.getDouble("padLaunchParticleCount");
final double padParticlePower = padConfig.getDouble("padLaunchParticlePower");
// Visible to everyone nearby, matching the in-air trail below.
player.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, padLocation, (int) padParticleCount, 0, 0, 0,
LaunchPadsOG.spawnParticleForAllClients(Particle.FIREWORKS_SPARK, padLocation, (int) padParticleCount,
0.2 * padParticlePower);
final double playerParticleMult = padConfig.getDouble("playerLaunchParticleCountMultipier");
@@ -173,11 +173,10 @@ public class OnPlayerMove implements Listener {
// \/ --------- \/
for (int j = 0; j < Math.min(yPower * 8 - 15, 25); j++) {
// Max out the number of particles at 50
Bukkit.getScheduler()
.runTaskLater(
LaunchPadsOG.getPlugin(), () -> player.getWorld().spawnParticle(Particle.SPELL,
player.getLocation(), (int) Math.min(xPower * zPower * playerParticleMult, 50)),
// Max out the number of particles at 50, speed 1 as before.
Bukkit.getScheduler().runTaskLater(LaunchPadsOG.getPlugin(),
() -> LaunchPadsOG.spawnParticleForAllClients(Particle.SPELL, player.getLocation(),
(int) Math.min(xPower * zPower * playerParticleMult, 50), 1),
j);
}