Made particles rotate based on initial player rotation if they aren't relative to the player, and current player rotation if they are
This commit is contained in:
parent
426be723b1
commit
7cc66db3ce
|
|
@ -16,18 +16,20 @@ public class FrameSpawnerLocation extends BukkitRunnable {
|
|||
private final List<Frame> frames;
|
||||
private Iterator<Frame> iterator;
|
||||
private final Location location;
|
||||
public FrameSpawnerLocation(int amount, int repeatDelay, List<Frame> frames, Location location) {
|
||||
private final float rotation;
|
||||
public FrameSpawnerLocation(int amount, int repeatDelay, List<Frame> frames, Location location, float rotation) {
|
||||
this.amount = amount;
|
||||
this.repeatDelay = (repeatDelay * 1000L) / 20;
|
||||
this.frames = frames;
|
||||
this.iterator = frames.iterator();
|
||||
this.location = location;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (iterator.hasNext())
|
||||
iterator.next().spawn(location);
|
||||
iterator.next().spawn(location, rotation);
|
||||
else if (amount != 0) {
|
||||
iterator = frames.iterator();
|
||||
amount--;
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
|||
return;
|
||||
}
|
||||
if (iterator.hasNext())
|
||||
iterator.next().spawn(player.getLocation());
|
||||
iterator.next().spawn(player.getLocation(), player.getLocation().getYaw());
|
||||
else if (amount != 0) {
|
||||
iterator = frames.iterator();
|
||||
amount--;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.alttd.objects;
|
||||
|
||||
import com.alttd.config.Config;
|
||||
import com.alttd.storage.PlayerSettings;
|
||||
import com.alttd.util.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
|
|
@ -20,14 +22,21 @@ public class Frame {
|
|||
*
|
||||
* @param location Location to spawn particles at
|
||||
*/
|
||||
public void spawn(Location location) {
|
||||
public void spawn(Location location, float rotation) {
|
||||
Location tmpLocation = location.clone();
|
||||
AParticles.forEach(AParticle -> {
|
||||
ThreadLocalRandom current = ThreadLocalRandom.current();
|
||||
double offsetX = ((AParticle.offset_range() == 0) ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()));
|
||||
double offsetZ = ((AParticle.offset_range() == 0) ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()));
|
||||
double offsetY = ((AParticle.offset_range() == 0) ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()));
|
||||
XZ xz = new XZ(location.getX(), location.getX() + AParticle.x() + offsetX,
|
||||
location.getZ(), location.getZ() + AParticle.z() + offsetZ,
|
||||
rotation);
|
||||
AParticle.particleBuilder()
|
||||
.location(tmpLocation.set(location.getX() + AParticle.x() + ((AParticle.offset_range() == 0) ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range())),
|
||||
location.getY() + AParticle.y() + ((AParticle.offset_range() == 0) ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range())),
|
||||
location.getZ() + AParticle.z() + ((AParticle.offset_range() == 0) ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()))))
|
||||
.location(tmpLocation.set(
|
||||
xz.getRotatedX(),
|
||||
location.getY() + AParticle.y() + offsetY,
|
||||
xz.getRotatedZ()))
|
||||
.receivers(Bukkit.getOnlinePlayers().stream()
|
||||
.filter(player -> {
|
||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(player.getUniqueId());
|
||||
|
|
@ -37,9 +46,40 @@ public class Frame {
|
|||
return false;
|
||||
Location playerLocation = player.getLocation();
|
||||
return location.getWorld().getUID().equals(playerLocation.getWorld().getUID()) && player.getLocation().distance(location) < 100;
|
||||
}).collect(Collectors.toList())
|
||||
)
|
||||
}).collect(Collectors.toList()))
|
||||
.spawn();
|
||||
});
|
||||
}
|
||||
|
||||
private class XZ {
|
||||
private final double cx, cz; //Coordinates to rotate around
|
||||
private double x, z; //Coordinated to rotate
|
||||
|
||||
public XZ(double cx, double x, double cz, double z, float rotation) {
|
||||
this.cx = cx; //X to rotate around
|
||||
this.x = x; //Current X pos to be rotated
|
||||
this.cz = cz; //Z to rotate around
|
||||
this.z = z; //Current Z pos to be rotated
|
||||
if (rotation < 0) //Make sure rotation is positive
|
||||
rotation = (rotation - 180) * -1;
|
||||
rotateCoords(Math.toRadians(rotation)); //Rotate
|
||||
}
|
||||
|
||||
private void rotateCoords(double angle) {
|
||||
double cos = Math.cos(angle);
|
||||
double sin = Math.sin(angle);
|
||||
double temp;
|
||||
temp = ((x - cx) * cos - (z - cz) * sin) + cx;
|
||||
z = ((x - cx) * sin + (z - cz) * cos) + cz;
|
||||
x = temp;
|
||||
}
|
||||
|
||||
public double getRotatedX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getRotatedZ() {
|
||||
return z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class ParticleSet {
|
|||
public void run(Location location, Player player) {
|
||||
if (tooSoon(player.getUniqueId()) || isVanished(player))
|
||||
return;
|
||||
FrameSpawnerLocation frameSpawnerLocation = new FrameSpawnerLocation(repeat, repeatDelay, frames, location);
|
||||
FrameSpawnerLocation frameSpawnerLocation = new FrameSpawnerLocation(repeat, repeatDelay, frames, location, player.getLocation().getYaw());
|
||||
frameSpawnerLocation.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, frameDelay);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user