using PacketPlayOutViewDistance in code

Discussion in 'Plugin Development' started by pomtom44, Jun 4, 2020.

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

    pomtom44

    Hi all
    im trying to make a dynamic render distance plugin, and following along with https://github.com/froobynooby/ViewDistanceTweaks
    I found the PlayerViewDistance packet

    Disclaimer, im new to packets, so using tutorials and modifying what i know to make it work

    I tried to use the same packet method for what i was shown for the tab list manipulation

    Code:
    PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
    
    ...
    Object header = new ChatComponentText(ChatColor.translateAlternateColorCodes('&', NewHeader));
    Object footer = new ChatComponentText(ChatColor.translateAlternateColorCodes('&', NewFooter));
    
    Field a = packet.getClass().getDeclaredField("header");
    a.setAccessible(true);
    Field b = packet.getClass().getDeclaredField("footer");
    b.setAccessible(true);
    a.set(packet, header);
    b.set(packet, footer);
    if(Bukkit.getOnlinePlayers().size() != 0) {
       for(Player player : Bukkit.getOnlinePlayers()) {
          ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
       }
    }
    And modified it to be this
    Code:
    int dist = Integer.parseInt(args[0]);
    PacketPlayOutViewDistance packet = new PacketPlayOutViewDistance(dist);
     for(Player p : Bukkit.getOnlinePlayers()){
         ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
      }
    When I run my command I can see the render distance changing, but the moment i send the packet the world stops rendering
    The player can move around, and the chunks unload and re-load but they dont generate new chunks
    as if the players "Chunk" location is set on where they were when the packet was sent

    Looking at the protocol FAQ https://wiki.vg/Protocol_FAQ I can see it needs a player location update to load new chunks, but my understanding is thats from the client to the server, not from my plugin to the client

    Im obviously doing something wrong here, but i dont know what im missing?

    Any help would be appreciated

    Thanks in advance
     
Thread Status:
Not open for further replies.

Share This Page