Solved Display particles for everyone regardless of location

Discussion in 'Plugin Development' started by Yeowza, Mar 6, 2020.

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

    Yeowza

    Hey guys, when we use particles they are only displayed to players who are nearby. Is there any way to get them to display for everyone? I noticed the playEffect method has an argument for radius but spawnParticle does not have one.

    Code:
    Main.world.spawnParticle(Particle.EXPLOSION_HUGE, e.getHitEntity().getLocation().getX(), e.getHitEntity().getLocation().getY(), e.getHitEntity().getLocation().getZ(), 0, 0, 0, 100);
    I noticed in the docs that each particle has a "data" argument which I guess is unique for each one. How do we figure out what these do?
     
  2. Offline

    Kars

    They are displayed to everyone, just in the same location. I assume you want them to be on the same position on the screen for everyone?
     
  3. Offline

    Machine Maker

    Well I think you probably can't see particles from hundreds of blocks away due to render issues. So if you just mean you want everyone to see a particle in one spot, that probably isn't possible.
     
  4. Offline

    Yeowza

    I am hitting a target about 50 blocks away with an arrow and spawning an explosion but it is not visible. Only the particles that are nearby, 10 blocks ish are visible.

    It should be the same case for everyone. Whatever particles that are spawned in the world are not visible to the player unless the location is nearby the player.
     
  5. Offline

    Kars

    Well that sounds like a property of the client and not something that can be addressed server-side.
     
  6. Offline

    Zombie_Striker

    @Yeowza
    There is a limit to the default distance particles will be displayed for the player. From what I read, the max distance should be 256 blocks away, but I guess it depends on the particle type being used.

    However, you can use packets to display particles that are further away:
    https://wiki.vg/Protocol#Particle_2
     
  7. Offline

    Yeowza

    Thanks Zombie_Striker, that put me in the right direction.

    I downloaded protocolLib and PacketWrapper and set those as dependencies in my plugin.yml and then I was able to get it working with this.

    Code:
                    WrapperPlayServerWorldParticles packet = new WrapperPlayServerWorldParticles();
                    packet.setParticleType(WrappedParticle.create(Particle.EXPLOSION_HUGE, 0));
                    packet.setX((float) e.getHitEntity().getLocation().getX());
                    packet.setY((float) e.getHitEntity().getLocation().getY());
                    packet.setZ((float) e.getHitEntity().getLocation().getZ());
                    packet.setLongDistance(true);
                    for(T4NKUP.Player p : Main.games.get(id).players) {
                        packet.sendPacket(Bukkit.getPlayer(p.name));
                    }
    It took like 6 hours to figure out but I'm so happy now. :p
     
Thread Status:
Not open for further replies.

Share This Page