From e9de969c6f2015dda478321429bfef10877e322b Mon Sep 17 00:00:00 2001 From: Zach Brown <1254957+zachbr@users.noreply.github.com> Date: Sat, 13 Aug 2016 15:26:40 -0500 Subject: [PATCH] More changes to view distance API implementation Should fix GH-381 --- .../Add-player-view-distance-API.patch | 91 ++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/Spigot-Server-Patches/Add-player-view-distance-API.patch b/Spigot-Server-Patches/Add-player-view-distance-API.patch index 7ba024e537..522844d1cc 100644 --- a/Spigot-Server-Patches/Add-player-view-distance-API.patch +++ b/Spigot-Server-Patches/Add-player-view-distance-API.patch @@ -85,6 +85,93 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 // this.c(l1, i2).a(entityplayer); chunksToLoad.add(new ChunkCoordIntPair(l1, i2)); // CraftBukkit } +@@ -0,0 +0,0 @@ public class PlayerChunkMap { + return playerchunk != null && playerchunk.d(entityplayer) && playerchunk.e(); + } + ++ public final void setViewDistanceForAll(int viewDistance) { this.a(viewDistance); } // Paper - OBFHELPER ++ // Paper start - Separate into two methods + public void a(int i) { + i = MathHelper.clamp(i, 3, 32); + if (i != this.j) { +@@ -0,0 +0,0 @@ public class PlayerChunkMap { + + while (iterator.hasNext()) { + EntityPlayer entityplayer = (EntityPlayer) iterator.next(); +- int k = (int) entityplayer.locX >> 4; +- int l = (int) entityplayer.locZ >> 4; +- int i1; +- int j1; +- +- if (j > 0) { +- for (i1 = k - i; i1 <= k + i; ++i1) { +- for (j1 = l - i; j1 <= l + i; ++j1) { +- PlayerChunk playerchunk = this.c(i1, j1); +- +- if (!playerchunk.d(entityplayer)) { +- playerchunk.a(entityplayer); +- } ++ this.setViewDistance(entityplayer, i, false); // Paper - Split, don't mark sort pending, we'll handle it after ++ } ++ ++ this.j = i; ++ this.e(); ++ } ++ } ++ ++ public void setViewDistance(EntityPlayer entityplayer, int i) { ++ this.setViewDistance(entityplayer, i, true); // Mark sort pending by default so we don't have to remember to do so all the time ++ } ++ ++ // Copied from above with minor changes ++ public void setViewDistance(EntityPlayer entityplayer, int i, boolean markSort) { ++ i = MathHelper.clamp(i, 3, 32); ++ int oldViewDistance = entityplayer.getViewDistance(); ++ if (i != oldViewDistance) { ++ int j = i - oldViewDistance; ++ ++ int k = (int) entityplayer.locX >> 4; ++ int l = (int) entityplayer.locZ >> 4; ++ int i1; ++ int j1; ++ ++ if (j > 0) { ++ for (i1 = k - i; i1 <= k + i; ++i1) { ++ for (j1 = l - i; j1 <= l + i; ++j1) { ++ PlayerChunk playerchunk = this.c(i1, j1); ++ ++ if (!playerchunk.d(entityplayer)) { ++ playerchunk.a(entityplayer); + } + } +- } else { +- for (i1 = k - this.j; i1 <= k + this.j; ++i1) { +- for (j1 = l - this.j; j1 <= l + this.j; ++j1) { +- if (!this.a(i1, j1, k, l, i)) { +- this.c(i1, j1).b(entityplayer); +- } ++ } ++ } else { ++ for (i1 = k - oldViewDistance; i1 <= k + oldViewDistance; ++i1) { ++ for (j1 = l - oldViewDistance; j1 <= l + oldViewDistance; ++j1) { ++ if (!this.a(i1, j1, k, l, i)) { ++ this.c(i1, j1).b(entityplayer); + } + } + } ++ if (markSort) { ++ this.e(); ++ } + } +- +- this.j = i; +- this.e(); + } + } ++ // Paper end + + private void e() { + this.l = true; @@ -0,0 +0,0 @@ public class PlayerChunkMap { } } @@ -99,9 +186,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + viewDistance = -1; + } + if (viewDistance != oldViewDistance) { -+ removePlayer(player); ++ // Order matters ++ this.setViewDistance(player, viewDistance); + player.setViewDistance(viewDistance); -+ addPlayer(player); + } + } + // Paper end