PacketPlayOutWorldParticle

Discussion in 'Plugin Development' started by Betagear, May 11, 2016.

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

    Betagear

    I've been trying for 5 hours to use it, but it doesn't seems to work.
    Can anyone help me with the parameters ? I just want to send a particle, I have all the rest.
     
  2. Offline

    Sulphate

    I would recommend using an API.
     
  3. Offline

    Betagear

    @Sulphate Yeah, but all I need is to spawn a particle, I can do everything else after I do that, and I try to keep my plugins standalone.
     
  4. Offline

    mcdorli

    What are the arguments' type for the packet?
     
  5. Offline

    Betagear

    @mcdorli There are two kinds : None or PacketPlayOutWorldParticles(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); But the second one, when you fill it accordingly doesn't works (My IDE tells me it's wrong) and corrects to the first one.
     
  6. Offline

    mcdorli

  7. Offline

    Betagear

    @mcdorli Thanks ! Will try this one soon.
    Just, I don't see a way to modify the particle used or the color of it, how can I do this ?
    And how could I give it a velocity (This one is optional) ?
     
  8. Offline

    mcdorli

    Look at the options below the one I posted.
     
  9. Offline

    Betagear

    @mcdorli Is it only 1.9 ? I don't see it in my IDE.
     
  10. Offline

    mcdorli

  11. Offline

    Herowise

    The Packet playout works liek this:

    Code:
    package me.hero.particlesenum;
    
    import net.minecraft.server.v1_8_R1.EnumParticle;
    import net.minecraft.server.v1_8_R1.PacketPlayOutWorldParticles;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Core extends JavaPlugin {
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
                if(cmd.getName().equalsIgnoreCase("herowise")){
                    Player player= (Player) sender;
               
                    createHelix(player);
                }
           
            return false;}
       
            public void createHelix(Player player) {
                Location loc = player.getLocation();
                int radius = 2;
                for(double y = 0; y <= 50; y+=0.05) {
                    double x = radius * Math.cos(y);
                    double z = radius * Math.sin(y);
                    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.BARRIER,true, (float) (loc.getX() + x), (float) (loc.getY() + y), (float) (loc.getZ() + z), 0, 0, 0, 0, 1);
                    for(Player online : Bukkit.getOnlinePlayers()) {
                        ((CraftPlayer)online).getHandle().playerConnection.sendPacket(packet);
                    }
       
                }}}
        
    Thats 1.8 Enum style
    This I geuss is supported in 1.9 as well...


    Now 1.7's Packets!

    Code:
    package me.hero.particles;
    import net.minecraft.server.v1_7_R3.PacketPlayOutWorldParticles;
    
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class Core extends JavaPlugin{
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    
            if(cmd.getName().equalsIgnoreCase("test")){
                Player player= (Player) sender;
           
                 flameEffect(player);
            }
       
        return false;
        }
    private void flameEffect(Player player) {
                    Location l = player.getLocation();
              
                  
                    for (double t = 0; t <= 2*Math.PI; t = t + Math.PI/16) {
                        for (double i = 0; i <= 1; i = i + 1){
                            double phi =+ Math.PI/8;
                       
                        double y = 0.5*t;
                            double  x = 0.4*(2*Math.PI-t)*0.5*Math.cos(t + phi + i*Math.PI);
                            double  z = 0.4*(2*Math.PI-t)*0.5*Math.sin(t + phi + i*Math.PI);
                            PacketPlayOutWorldParticles packet;
                          
                            packet = new PacketPlayOutWorldParticles(
                                            "fireworksSpark",
                                            (float) (l.getX() + x),
                                            ((float) (l.getY() + y)),
                                            (float) (l.getZ() + z),
                                            0, 0, 0, 1, 0);
                            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
                        }                       
                    }
                    }
            }
     
  12. Offline

    Betagear

    @Herowise Thanks, it helped.


    @mcdorli How are the colors handled inside of the data ? Hex code ? Wool color codes ?
     
  13. Offline

    I Al Istannen

    @Betagear
    Maybe there is another way, but the command one is this.
     
  14. Offline

    mcdorli

    wool color codes
     
  15. Offline

    Betagear

    @mcdorli Thanks

    @mcdorli As a last question: Is the data for the colors the int (after the count) or the float (before the count) ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.

    EDIT by author : This multiple posting was done on purpose because the previous message wasn't related to this one.
     
    Last edited: May 13, 2016
  16. Offline

    mcdorli

    THe float
     
  17. Offline

    Betagear

    @mcdorli Thanks. I think that's all :)

    But wait, that doesn't makes sense, as Wool color codes are natural numbers.
     
  18. Offline

    mcdorli

    just pass it one.
     
  19. Offline

    Betagear

    Tried that :
    Code:
        private void throwParticle(Location loc){
            PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(
                    EnumParticle.FIREWORKS_SPARK,
                    true,
                    (float)loc.getX(),(float) loc.getY(),(float) loc.getZ(),
                    0, 0, 0, color, 1);
            ((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);
        }
    Didn't worked, not any particle appeared (Got a test script that spawned particles on my head regularly), with color set to 10.
    What am I missing ?

    @OhYes Lol, nope. It plain doesn't works, my locations aren't null, player isn't null. Everything around is good, except that.

    And for all of those with think i'm an idiot because I don't send it to everyone : I just want one player to see it, because colors and particles location will vary according to the player location and it's rights.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  20. Offline

    Betagear

    Bump. If anyone got it working, please post here how you did it.

    EDIT : May have fount something interesting
    http://wiki.vg/Protocol#Particle

    EDIT 2 : Actually, this code works but the spawned particle have a very high velocity that is random.

    EDIT 3 : It causes very high memory leaks (20 particles = 1mb). Help ?

    Fount a solution : The color is the second int, not the float... Thanks, @mcdorli .
    The memory leaks aren't really related to the particles though.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 17, 2016
  21. Offline

    Betagear

    Got it working :
    PacketPlayOutWorldParticles(EnumParticle.PARTICLE,
    (boolean) visibility,
    (float) X,(float) Y,(float) Z,
    (float) OffsetX, (float) OffsetY, (float) OffsetZ,
    (float) Velocity,(int) Count);

    EnumParticle for the particle you have chosen.
    Visiblity to see the particle from further away
    X, Y, Z for the coordinates.
    OffsetX, Y, Z to randomise the coordinates
    Velocity between 0 and 10, random.
    Count for the amount of particles spawned, spawns 1 with 0.


    However, I didn't find how to change the color.
     
  22. Offline

    I Al Istannen

    You could try this:
    I have no idea though. But it works with command blocks, so you could probably just convert it to your packets.
     
  23. Offline

    Betagear

  24. Offline

    I Al Istannen

    @Betagear
    Then I apologize, but I can't help you :/
     
  25. Offline

    Betagear

    It changed the color only for EnumParticle.REDSTONE, and it was flashing colors.
     
  26. Offline

    Betagear

    Does somebody knows a good particle library that can be incorporated into my plugin ? I'll dissect it, and try to make a tutorial out of it.
     
  27. Offline

    Betagear

    Last edited: May 27, 2016
Thread Status:
Not open for further replies.

Share This Page