#particle thing
1 messages · Page 1 of 1 (latest)
public static void makeParticleCircle() {
for (Player p : Bukkit.getOnlinePlayers()) {
Location location = p.getPlayer().getLocation();
for (int degree = 0; degree < 360; degree++) {
double radians = Math.toRadians(degree);
double x = Math.cos(radians);
double z = Math.sin(radians);
location.add(x, 0, z);
location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
location.subtract(x, 0, z);
}
}
}
@amber cradle
and now?
You need to parameterize the method with a radius and height-offset
ok
public static void makeParticleCircle(double x, double z, double y, double radius) {
for (Player p : Bukkit.getOnlinePlayers()) {
Location location = p.getPlayer().getLocation();
for (int degree = 0; degree < 360; degree++) {
double radians = Math.toRadians(degree);
x = Math.cos(radians);
z = Math.sin(radians);
location.add(x, 0, z);
location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
location.subtract(x, 0, z);
}
}
}
```this?
You should not use 360 points for every circle. You should scale that based on the radius.
Btw this will create a circle for every player on the server. Do you really want that?
no
i made a thing to make it run only at players wearing a custom helmet
but lets pretend its for all players
You should probably add the player as a parameter too
So you can call that method for each player
ok
public static void makeParticleCircle(double x, double z, double radius, Player p) {
Location location = p.getPlayer().getLocation();
for (int degree = 0; degree < 360; degree++) {
double radians = Math.toRadians(degree);
x = Math.cos(radians);
z = Math.sin(radians);
location.add(x, 0, z);
location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
location.subtract(x, 0, z);
}
}
}
this?
Looks ok.
Now we need to write a second method that generates the sin wave based on the distance from the player
So
input -> distanceFromPlayer
output -> heightOfWave
Then we step from 0 to N in steps of 0.1 or so and then generate a circle with this radius and height
Btw this method is not done. The parameters x and z are useless. You need y for the height offset.
i put input as parameter of method right?
so i can remove them?
x and z made the circle
public static void makeParticleCircle(double heightOffset, double radius, Player player) {
Location location = player.getLocation();
for (int degree = 0; degree < 360; degree++) {
double radians = Math.toRadians(degree);
double x = Math.cos(radians) * radius;
double z = Math.sin(radians) * radius;
location.add(x, heightOffset, z);
location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
location.subtract(x, heightOffset, z);
}
}
ill test it wait
public static void makeParticleCircle(double heightOffset, double radius, Player player) {
Location location = player.getLocation();
for (int degree = 0; degree < 360; degree++) {
double radians = Math.toRadians(degree);
double x = Math.cos(radians) * radius;
double z = Math.sin(radians) * radius;
location.add(x, heightOffset, z);
location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
location.subtract(x, heightOffset, z);
}
}
public static void createParticleSinWaveCircle(Player player, double distance, double amplitude, double freq) {
double height = Math.sin(distance * freq) * amplitude;
makeParticleCircle(height, distance, player);
}
public static void createParticleWave(Player player, double startRad, double endRad, double steps) {
double ampl = 1.0;
double freq = 0.33;
double rad = startRad;
while (rad <= endRad) {
createParticleSinWaveCircle(player, rad, ampl, freq);
rad += steps;
}
}
oh
Usage:
createParticleWave(player, 1.0, 5.0, 0.1);
Creates a wave from distance 1.0 - 5.0 in 0.1 steps
ok
1.0 from player?
1.0 blocks?
and what is steps
also
is there a way to make it take time?
like take 5seconds to complete the circle
um
was this meant to happen?
@amber cradle
@Flo | Gestankbratwurst#4120 ?
i wanted it to make this
@amber cradle ?
Oh this is something completely different
This should be simpler
Try this:
public static void makeParticleSinCircle(double radius, Player player) {
Location location = player.getLocation();
for (int degree = 0; degree < 360; degree++) {
double radians = Math.toRadians(degree);
double x = Math.cos(radians) * radius;
double y = Math.sin(radians);
double z = Math.sin(radians) * radius;
location.add(x, y, z);
location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
location.subtract(x, y, z);
}
}
just it?
Just this yes
kk
It might look a bit odd because its just a single sin wave.
oh wait
this made part of what i wanted
pic pls
i increased the steps amount and it taked time to make the circle
of what
this makes only a normal circle, but takes time to make it
The new method ive sent
yea ok wait
would be very nice if i could mix the new method and the old one
so it would make the waves and take time to make them
Ah i see.
Change
double y = Math.sin(radians);
to
double y = Math.sin(radians * 4);
radians * number
number is waves?
Yes the number should be the amount of waves
so i can add it as parameter?
sure
public static void makeParticleSinCircle(double radius, Player player, int waves) {
Location location = player.getLocation();
for (int degree = 0; degree < 360; degree++) {
double radians = Math.toRadians(degree);
double x = Math.cos(radians) * radius;
double y = Math.sin(radians) * waves;
double z = Math.sin(radians) * radius;
location.add(x, y, z);
location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
location.subtract(x, y, z);
}
}
ty
nah u pro
nice. I would just decrease the number of points a bit.
for (int degree = 0; degree < 360; degree++) {
Could be
for (int degree = 0; degree < 360; degree += 4) {
To have 90 points instead of 360
less particles right?
yeah
kk
not everyone has a non-potato pc
thanks for help
@amber cradle
how do i change the height offset
its too big
double y = Math.sin(radians * waves) * height;
how would i mix this
with this
public static void makeParticleSinCircle(double radius, Player player, int waves, double heightOffset) {
Location location = player.getLocation();
for (double degree = 0.0; degree < 360.0; degree+=4) {
double radians = Math.toRadians(degree);
double x = Math.cos(radians) * radius;
double y = Math.sin(radians * waves) * heightOffset;
double z = Math.sin(radians) * radius;
location.add(x, y, z);
location.getWorld().spawnParticle(Particle.END_ROD, location, 0);
location.subtract(x, y, z);
}
}
@amber cradle?
I want to do the wave circle (that i already have) but with the steps from the other
@amber cradle
Im not he math guy here
This with steps
So you want a wave that goes outwards + has waves on a radial axis?
This will just result in random hills...
No
What do you mean by that? The circle should show instantly.
This one didnt
Steps made it take some time to complete
I want it do "draw" the wave circle
Oh i wont help with that. Its basically the same thing but you create a stateful runnable.
I think i can just mix both things u sent me
Nope
You will need a scheduler for that
I mean
I didnt need it for this
And it still made this
Just increased steps
Thats probably just lags showing. You need a runnable. Trust me on that.
Kk
Tomorrow ill try this with 360 steps
If it doesnt make the circle instantly then its not lag
And i have no idea of how to do this
Im probably already doing it and dont know
public class ArmorTask extends BukkitRunnable
mhm yea it didnt
how would i do it
You will need 2 classes.
For once the task:
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.UUID;
public class WaveParticleTask extends BukkitRunnable {
private final UUID playerID;
private final int waves;
private final double height;
private final double radius;
private int degree = 0;
public WaveParticleTask(UUID playerID, int waves, double height, double radius) {
this.playerID = playerID;
this.waves = waves;
this.height = height;
this.radius = radius;
}
@Override
public void run() {
degree %= 360;
Player player = Bukkit.getPlayer(playerID);
if (player == null) {
this.cancel();
return;
}
double radians = Math.toRadians(degree);
double x = Math.cos(radians) * radius;
double y = Math.sin(radians * waves) * height;
double z = Math.sin(radians) * radius;
Location particleLoc = player.getLocation().add(x, y, z);
player.getWorld().spawnParticle(Particle.END_ROD, particleLoc, 0);
degree += 5;
}
}
Then a manager:
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class WaveParticleManager implements Runnable {
private final Map<Player, WaveParticleTask> runningTasks = new HashMap<>();
public void startTask(Player player) {
runningTasks.put(player, new WaveParticleTask(player.getUniqueId(), 5, 0.66, 2.5));
}
public void stopTask(Player player) {
Optional.ofNullable(runningTasks.get(player)).ifPresent(BukkitRunnable::cancel);
}
@Override
public void run() {
runningTasks.values().forEach(WaveParticleTask::run);
}
}
Then you can do this in your main class:
private final WaveParticleManager waveParticleManager = new WaveParticleManager();
@Override
public void onEnable() {
Bukkit.getScheduler().runTaskTimer(this, waveParticleManager, 1, 1);
}
If you want to start a wave task simply do:
waveParticleManager.startTask(player);
kk
thanks
i found another way
but its very big
Then a manager:
cannot resolve symbol 'Then'
nvm
i copied wrong
onEnable?
if yes: cannot resolve symbol ''player''
public void onEnable() {
instance = this;
CustomArmorManager.startTask(player);
//cannot resolve symbol player
//Non-static method 'startTask(org.bukkit.entity.Player)' cannot be referenced from a static context
Setup.setup(this);
}
i changed some things and got no errors
task
package me.lucasgithuber.obsidianexpansion.utils;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.UUID;
public class CustomArmorTask extends BukkitRunnable {
private final UUID playerID;
private final int waves;
private final double height;
private final double radius;
private int degree = 0;
public CustomArmorTask(UUID playerID, int waves, double height, double radius) {
this.playerID = playerID;
this.waves = waves;
this.height = height;
this.radius = radius;
}
@Override
public void run() {
degree %= 360;
Player player = Bukkit.getPlayer(playerID);
if (player == null) {
this.cancel();
return;
}
double radians = Math.toRadians(degree);
double x = Math.cos(radians) * radius;
double y = Math.sin(radians * waves) * height;
double z = Math.sin(radians) * radius;
Location particleLoc = player.getLocation().add(x, y, z);
player.getWorld().spawnParticle(Particle.END_ROD, particleLoc, 0);
degree += 5;
}
}
manager
package me.lucasgithuber.obsidianexpansion.utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class CustomArmorManager implements Runnable {
private static final Map<Player, CustomArmorTask> runningTasks = new HashMap<>();
public static void startTask() {
for(Player p : Bukkit.getOnlinePlayers()) {
runningTasks.put(p, new CustomArmorTask(p.getUniqueId(), 10, 0.66, 2.5));
}
}
public void stopTask(Player player) {
Optional.ofNullable(runningTasks.get(player)).ifPresent(BukkitRunnable::cancel);
}
@Override
public void run() {
runningTasks.values().forEach(CustomArmorTask::run);
}
}
enable
public void onEnable() {
instance = this;
CustomArmorManager.startTask();
Setup.setup(this);
}
ofc, in the task i will be doing a check for armor so it wont execute at every player in server
it didnt work
it doesnt even fire
This just means you need to write more code 😄
Doesnt get more spoon feedy than that
i didnt put this :p
now it makes the particles but only at 1 place
i did it, now it makes the circle with waves
but instantly
never tought math were this hard
welp i gtg
tomorrow i try to do it
and this makes only one particle
This is what is happening for me
i tried
for(Player player : Bukkit.getOnlinePlayers()){
customArmorManager.startTask(player);
}
it removed the error but it didnt show particles
@Flo | Gestankbratwurst#4120 ?
Nope...
You need more spigot/programming experience. This project is way over your head.
ok
🤷
Because it does
nice