Solved How To Spawn Particles At Certain Locations

Discussion in 'Plugin Development' started by mkezar, Nov 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    mkezar

    Hi i am trying to make a particle cape plugin. The code i have now will make it so ANGRY_VILLAGER will spawn 2 blocks behind me no matter where i turn. The particles are not in order so they are spread out. i want to have every single one of them be in cape form. here is the code i have:

    Code:java
    1. package plugins.mkezar;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.Location;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12. import org.bukkit.util.Vector;
    13. import org.bukkit.command.Command;
    14. import org.bukkit.command.CommandSender;
    15. import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
    16.  
    17. import de.slikey.effectlib.particle.ParticlePacket.ParticleType;
    18.  
    19. public class FlameEntityEffect extends JavaPlugin {
    20.  
    21. private HashMap<Player, String> capes = new HashMap<Player, String>();
    22.  
    23. public void onEnable() {
    24. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    25.  
    26. public void run() {
    27. for (Player owner : capes.keySet()) {
    28. String ParticleType = capes.get(owner);
    29. if (ParticleType == null) {
    30. capes.remove(owner);
    31. return;
    32. }
    33. for (Player online : Bukkit.getOnlinePlayers()) {
    34. Location loc = owner.getEyeLocation();
    35. Vector direction = loc.getDirection().normalize();
    36. direction.multiply(2);
    37. loc.subtract(direction);
    38. if (loc.distance(online.getLocation()) < 50)
    39. ((CraftPlayer) online).getHandle().playerConnection
    40. .sendPacket(new PacketPlayOutWorldParticles(
    41. ParticleType, (float) loc.getX(),
    42. (float) loc.getY(), (float) loc
    43. .getZ(), 0.5f, 0.5f, 0.5f,
    44. 1f, 6));
    45. }
    46. }
    47. }
    48.  
    49. }, 0, 1);
    50. }
    51.  
    52. @Override
    53. public boolean onCommand(CommandSender sender, Command cmd,
    54. String commandLabel, String[] args) {
    55. if (sender instanceof Player) {
    56. Player player = (Player) sender;
    57.  
    58. if (commandLabel.equalsIgnoreCase("cape")) {
    59. capes.put(player, ParticleType.ANGRY_VILLAGER.getId());
    60. player.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD
    61. + "The Particles Are Working");
    62. }
    63. }
    64. return false;
    65. }
    66. }
    67.  


    The Spawning the particles in specific order is kind of out of my ability math wise. any tips? Thanks! :D
     
  2. Offline

    Asecta

    mkezar Sorry, but this is a really bad idea. You're both going to have to do annoying math and have the client render a ton of particles. This can't end well.

    At the very least, try using the spigotAPI for spawning particles.
     
  3. Offline

    mkezar

    Bukkit = SpigotAPI

    but seriously... dat math doe... im in the 7th grade and never really touched on trigonometry. Could someone tutor me a tiny bit of how to accomplish this?

    <Edit by mrCookieSlime: Merged Posts. Please dont double post. There is an Edit-Button right next to the Date.>
     
    Skionz likes this.
  4. Offline

    Skionz

    Use the players pitch and yaw and hardcode the particles.
     
  5. Offline

    Asecta

    mkezar No, there are differences. Especially when dealing with particles, hence why I mentioned it.
     
  6. Offline

    mkezar

    oh yes. thank you! :D
     
  7. Offline

    Asecta

    mkezar I can go ahead and code a method to spawn all the particles for you if you want, I've already started.
     
  8. Offline

    mkezar

    ok. but bukkit is the same as spigot but spigot just has a tiny bit better performance.

    Skionz so should i try:
    Code:java
    1. loc.setPitch(90F);
    2. loc.setYaw(90F);


    <Edit by mrCookieSlime: Merged Posts. Please dont double post. There is an Edit-Button right next to the Date.>
     
  9. Offline

    Asecta

    mkezar Bukkit is NOT the same as spigot, otherwise I wouldn't be saying it was.

    if you want to get the location 1 block behind the player, this is a start:

    Code:java
    1. player.getEyeLocation().getDirection().multiply(-1).add(player.getEyeLocation().toVector());


    Also:

    Code:java
    1. player.getWorld().spigot().playEffect(player.getLocation(), Effect.VILLAGER_THUNDERCLOUD);
     
  10. Offline

    mkezar

    i dont really want to argue. but for now im sticking with bukkit.
     
Thread Status:
Not open for further replies.

Share This Page