EnumParticle replacement in 1.13 ?

Discussion in 'Spigot Plugin Development' started by Reiika, Jul 25, 2018.

  1. Hi all,

    i want to know how can i replace EnumParticle in 1.13, cause i need it for that:

    Code (Text):
    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.valueOf(particle), true, (float) loc.getX()+x, (float) loc.getY(), (float) loc.getZ()+z, 0,0,0,0,1);
    thanks in advance.
    Reiika
     
  2. The replacement is currently "Particles". All the names are obfuscated tho, so here is what I've found in the sources:

    Code (Text):
    a = (ParticleType)a("ambient_entity_effect");
             b = (ParticleType)a("angry_villager");
             c = (ParticleType)a("barrier");
             d = a("block");
             e = (ParticleType)a("bubble");
             f = (ParticleType)a("bubble_column_up");
             g = (ParticleType)a("cloud");
             h = (ParticleType)a("crit");
             i = (ParticleType)a("damage_indicator");
             j = (ParticleType)a("dragon_breath");
             k = (ParticleType)a("dripping_lava");
             l = (ParticleType)a("dripping_water");
             m = a("dust");
             n = (ParticleType)a("effect");
             o = (ParticleType)a("elder_guardian");
             p = (ParticleType)a("enchanted_hit");
             q = (ParticleType)a("enchant");
             r = (ParticleType)a("end_rod");
             s = (ParticleType)a("entity_effect");
             t = (ParticleType)a("explosion_emitter");
             u = (ParticleType)a("explosion");
             v = a("falling_dust");
             w = (ParticleType)a("firework");
             x = (ParticleType)a("fishing");
             y = (ParticleType)a("flame");
             z = (ParticleType)a("happy_villager");
             A = (ParticleType)a("heart");
             B = (ParticleType)a("instant_effect");
             C = a("item");
             D = (ParticleType)a("item_slime");
             E = (ParticleType)a("item_snowball");
             F = (ParticleType)a("large_smoke");
             G = (ParticleType)a("lava");
             H = (ParticleType)a("mycelium");
             I = (ParticleType)a("note");
             J = (ParticleType)a("poof");
             K = (ParticleType)a("portal");
             L = (ParticleType)a("rain");
             M = (ParticleType)a("smoke");
             N = (ParticleType)a("spit");
             O = (ParticleType)a("sweep_attack");
             P = (ParticleType)a("totem_of_undying");
             Q = (ParticleType)a("underwater");
             R = (ParticleType)a("splash");
             S = (ParticleType)a("witch");
             T = (ParticleType)a("bubble_pop");
             U = (ParticleType)a("current_down");
             V = (ParticleType)a("squid_ink");
             W = (ParticleType)a("nautilus");
             X = (ParticleType)a("dolphin");
     
     
    • Like Like x 1
  3. Why would you use packets? What you're trying is possible with the API, as well as much simpler and version independent.
     
    • Agree Agree x 2
    • Agree Agree x 2
  4. Maybe but i don't know if what i want to do can be created with the api.

    i talk about that :
    Code (Java):
    public void drawCircle(Location loc, float radius, String particle){
             for(double t =0; t<50; t+=0.5){
                 float x = radius*(float)Math.sin(t);
                 float z = radius*(float)Math.cos(t);
                 PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.valueOf(particle), true, (float) loc.getX()+x, (float) loc.getY(), (float) loc.getZ()+z, 0,0,0,0,1);
                 for(Player players : Bukkit.getOnlinePlayers()){
                     ((CraftPlayer)players).getHandle().playerConnection.sendPacket(packet);
                 }
             }
         }
     
  5. You should use packets for particles if you want them to be displayed to certain players for example, I see you want them to be seen by everyone so why bother with packets?
     
  6. @iDoomfull packets isnt needed for that. Player.spawnParticle... just call it on players who need it..

    and these are Async Safe too.

    I can understand keeping older code using reflection for old mc versions, but going forward, just use the API!

    Or least use @inventivetalent's ParticleAPI library.
     
    • Agree Agree x 1
    • Informative Informative x 1
  7. I said he should use it only for special cases, like displaying them to certain players, I didn't encourage him to use it, especially after I've seen the usage of it in his code
     
    • Agree Agree x 1
  8. You dont need it for certain players either. The Player class has a spawnParticle method. It'll only show it to that player.
     
    • Useful Useful x 2
  9. So, you think about what ?

    Something like that ?
    Code (Java):
         public void drawCircle(Location loc, float radius, String particle){
             for(double t =0; t<50; t+=0.5){
                 float x = radius*(float)Math.sin(t);
                 float z = radius*(float)Math.cos(t);
                 for(Player players : Bukkit.getOnlinePlayers()){
                     players.spawnParticle(Particle.valueOf(particle),(float) loc.getX()+x, (float) loc.getY(), (float) loc.getZ()+z, 0,0,0,0,1);
                 }
             }
         }
    }
     
  10. Very much possible, but I have a few remarks to improve your code. :)

    First off, it seems you pass a string for the particle type. I suggest just passing an enum value from the Particle enum directly, so you cant make any typos.

    Furthermore, you loop through all online players to spawn a particle. There's a more efficient way of doing things!
    First, get the world you want to spawn the particle in (loc.getWorld())
    Then, call the exact same method (spawnParticle()) on the World class. It'll show the particle to all players in that world who are close enough to see it. So it wont send the particles to all players, which is more efficient.
     
    • Informative Informative x 1
  11. Actually, doing this will simply do the same thing. The spawnParticle method of the World class points to this one in the WorldServer class:
    Code (Text):

       public int sendParticles(EntityPlayer sender, ParticleParam t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
          PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(t0, false, (float)d0, (float)d1, (float)d2, (float)d3, (float)d4, (float)d5, (float)d6, i);
          int j = 0;

          for(int k = 0; k < this.players.size(); ++k) {
             EntityPlayer entityplayer = (EntityPlayer)this.players.get(k);
             if((sender == null || entityplayer.getBukkitEntity().canSee(sender.getBukkitEntity())) && this.a(entityplayer, false, d0, d1, d2, packetplayoutworldparticles)) {
                ++j;
             }
          }

          return j;
       }
     
    As you can see, it still loops through all online players. Just so you know ^-^
     
    • Informative Informative x 2