More changes to view distance API implementation
Should fix GH-381
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
From 068369d52a9520129daf8c4f175e21d3eff59ec6 Mon Sep 17 00:00:00 2001
|
||||
From 32205193321f857475c11a9e4b1e30a7d9031817 Mon Sep 17 00:00:00 2001
|
||||
From: Byteflux <byte@byteflux.net>
|
||||
Date: Wed, 2 Mar 2016 14:35:27 -0600
|
||||
Subject: [PATCH] Add player view distance API
|
||||
@@ -25,7 +25,7 @@ index 522c7f2..4950db4 100644
|
||||
// CraftBukkit start
|
||||
public String displayName;
|
||||
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
index 797a84f..df6801f 100644
|
||||
index 797a84f..fcd0186 100644
|
||||
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
@@ -47,7 +47,7 @@ public class PlayerChunkMap {
|
||||
@@ -85,7 +85,94 @@ index 797a84f..df6801f 100644
|
||||
// this.c(l1, i2).a(entityplayer);
|
||||
chunksToLoad.add(new ChunkCoordIntPair(l1, i2)); // CraftBukkit
|
||||
}
|
||||
@@ -495,4 +503,20 @@ public class PlayerChunkMap {
|
||||
@@ -378,6 +386,8 @@ 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) {
|
||||
@@ -387,36 +397,55 @@ 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;
|
||||
@@ -495,4 +524,20 @@ public class PlayerChunkMap {
|
||||
}
|
||||
}
|
||||
// CraftBukkit end
|
||||
@@ -99,9 +186,9 @@ index 797a84f..df6801f 100644
|
||||
+ viewDistance = -1;
|
||||
+ }
|
||||
+ if (viewDistance != oldViewDistance) {
|
||||
+ removePlayer(player);
|
||||
+ // Order matters
|
||||
+ this.setViewDistance(player, viewDistance);
|
||||
+ player.setViewDistance(viewDistance);
|
||||
+ addPlayer(player);
|
||||
+ }
|
||||
+ }
|
||||
+ // Paper end
|
||||
@@ -128,5 +215,5 @@ index 64c9c1c..e09dc78 100644
|
||||
private final Player.Spigot spigot = new Player.Spigot()
|
||||
{
|
||||
--
|
||||
2.9.0.windows.1
|
||||
2.9.2.windows.1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user