Set individual view distance

Discussion in 'Spigot Plugin Development' started by totokaka, May 21, 2016.

  1. Hi,

    I'm developing plugins for an event server that will be livestreamed from. In order to maximize performance I would like to set the global view distance quite low, but then have it higher for the clients who will be streaming, so the view distance will be long in the stream.

    Is this possible?

    I have looked through the javadoc, but couldn't find anything. After some searching I found a guy who claimed he had done a permission based individual view distance. How could he have done it?

    It was mentioned (by md_5) that this might cause chunk leaks, but that shouldn't be a problem for me, as I'm considering preloading all chunks.

    Thanks for any help.
  2. I've never seen this done before, but I'm guessing you'd have to do it client-side, no? And the only client-side modifications we can make are with the use of minecraft's protocol packets. So: .

    I have no idea which one though, and how it would be done. But defiantly packets.
  3. -
    #3 AdamJLE, May 21, 2016
    Last edited: Mar 16, 2022
  4. @AdamJLE, you seem to understand what I want, but @ExpDev is a bit off.

    I want to reduce the server side view distance, ie. how many chunks are sent to the players, but have a few players that should receive more chunks. Client side mods shouldn't be necessary, I think.

    I'll look into the possibility of sending chunks to a player in a few hours.
  5. Sounds like you're going to need some hacky ways to change the normal Spigot chunk sending. Haven't seen this ever before, also I can't really think of a reason why this could be of any use, pretty interesting however!
  6. You can do this using packets, basically how you explained and what ExpDev mentioned.
    1. Set server view-distance to low value
    2. When a player connects, check if they're allowed to load more chunks
    3. If a player is allow to see farther than server view-distance, goto 4, otherwise ignore next 3 steps
    4. Within the radius of player location chunk + server view-distance to their allowed distance (up to maximum of 16?, can't really see past that anyway), send the player chunk load packets
    5. When player changes chunks, make sure the server actually loads the chunk server-wide (should happen automatically) and you send a chunk unload packet for farthest chunks (i suggest keeping track of the loaded X,Z values of each players chunks, to better find them)
    As for the player.spigot().setViewDistance(), it appears to have been added to the ChunkComparator and EntityPlayer classes in 1.10. It may exist pre 1.10 in an obfuscated state but I don't care enough to check.
  7. @Klaus It is achieved in Paper by changing the vanilla code which sends and manages chunks, so it would be hard to implement easily in Spigot.

    @CraftedFury That seems like a lot of work, compared to the <50 lines changed in Paper to achieve the same functionality, and the single line to use it in plugins.

    I am already using Paper on my server, so I just went that route. However, it turns out there was a bug in Paper 1.9 and 1.10 that prevented it from working. I have reported the issue and suggested a fix on Paper's GitHub repo.