2018-04-28 23:31:26 +08:00
|
|
|
From b37938d4ce59d4ae17feb44e60dd1f8124c1a4d8 Mon Sep 17 00:00:00 2001
|
2016-03-01 07:09:49 +08:00
|
|
|
From: Byteflux <byte@byteflux.net>
|
|
|
|
Date: Wed, 2 Mar 2016 14:35:27 -0600
|
|
|
|
Subject: [PATCH] Add player view distance API
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
2018-04-28 23:31:26 +08:00
|
|
|
index dfaab774d..3058dfef0 100644
|
2016-03-01 07:09:49 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
2017-05-31 16:04:52 +08:00
|
|
|
@@ -66,6 +66,15 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
2016-03-01 07:09:49 +08:00
|
|
|
public boolean f;
|
|
|
|
public int ping;
|
|
|
|
public boolean viewingCredits;
|
2016-04-24 09:39:22 +08:00
|
|
|
+ // Paper start - Player view distance API
|
|
|
|
+ private int viewDistance = -1;
|
|
|
|
+ public int getViewDistance() {
|
|
|
|
+ return viewDistance == -1 ? ((WorldServer) world).getPlayerChunkMap().getViewDistance() : viewDistance;
|
|
|
|
+ }
|
|
|
|
+ public void setViewDistance(int viewDistance) {
|
|
|
|
+ this.viewDistance = viewDistance;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2016-03-01 07:09:49 +08:00
|
|
|
|
|
|
|
// 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
|
2018-02-13 02:04:05 +08:00
|
|
|
index e4ed2e991..9627a9be0 100644
|
2016-03-01 07:09:49 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2016-06-05 12:10:50 +08:00
|
|
|
@@ -47,7 +47,7 @@ public class PlayerChunkMap {
|
2016-04-24 09:39:22 +08:00
|
|
|
private final List<PlayerChunk> g = Lists.newLinkedList();
|
|
|
|
private final List<PlayerChunk> h = Lists.newLinkedList();
|
|
|
|
private final List<PlayerChunk> i = Lists.newArrayList();
|
|
|
|
- private int j;
|
|
|
|
+ private int j;public int getViewDistance() { return j; } // Paper OBFHELPER
|
|
|
|
private long k;
|
|
|
|
private boolean l = true;
|
|
|
|
private boolean m = true;
|
2017-01-31 12:33:54 +08:00
|
|
|
@@ -291,8 +291,11 @@ public class PlayerChunkMap {
|
2016-06-19 09:52:11 +08:00
|
|
|
// CraftBukkit start - Load nearby chunks first
|
|
|
|
List<ChunkCoordIntPair> chunkList = new LinkedList<ChunkCoordIntPair>();
|
|
|
|
|
|
|
|
- for (int k = i - this.j; k <= i + this.j; ++k) {
|
|
|
|
- for (int l = j - this.j; l <= j + this.j; ++l) {
|
|
|
|
+ // Paper start - Player view distance API
|
|
|
|
+ int viewDistance = entityplayer.getViewDistance();
|
|
|
|
+ for (int k = i - viewDistance; k <= i + viewDistance; ++k) {
|
|
|
|
+ for (int l = j - viewDistance; l <= j + viewDistance; ++l) {
|
|
|
|
+ // Paper end
|
|
|
|
chunkList.add(new ChunkCoordIntPair(k, l));
|
|
|
|
}
|
|
|
|
}
|
2017-01-31 12:33:54 +08:00
|
|
|
@@ -311,8 +314,11 @@ public class PlayerChunkMap {
|
2016-03-01 07:09:49 +08:00
|
|
|
int i = (int) entityplayer.d >> 4;
|
|
|
|
int j = (int) entityplayer.e >> 4;
|
|
|
|
|
|
|
|
- for (int k = i - this.j; k <= i + this.j; ++k) {
|
|
|
|
- for (int l = j - this.j; l <= j + this.j; ++l) {
|
|
|
|
+ // Paper start - Player view distance API
|
2016-04-24 09:39:22 +08:00
|
|
|
+ int viewDistance = entityplayer.getViewDistance();
|
|
|
|
+ for (int k = i - viewDistance; k <= i + viewDistance; ++k) {
|
|
|
|
+ for (int l = j - viewDistance; l <= j + viewDistance; ++l) {
|
2016-03-01 07:09:49 +08:00
|
|
|
+ // Paper end
|
2016-05-12 10:07:46 +08:00
|
|
|
PlayerChunk playerchunk = this.getChunk(k, l);
|
2016-03-01 07:09:49 +08:00
|
|
|
|
|
|
|
if (playerchunk != null) {
|
2017-01-31 12:33:54 +08:00
|
|
|
@@ -342,7 +348,9 @@ public class PlayerChunkMap {
|
2016-03-01 07:09:49 +08:00
|
|
|
if (d2 >= 64.0D) {
|
|
|
|
int k = (int) entityplayer.d >> 4;
|
|
|
|
int l = (int) entityplayer.e >> 4;
|
|
|
|
- int i1 = this.j;
|
2016-04-24 09:39:22 +08:00
|
|
|
+ final int viewDistance = entityplayer.getViewDistance(); // Paper - Player view distance API
|
|
|
|
+ int i1 = Math.max(getViewDistance(), viewDistance); // Paper - Player view distance API
|
|
|
|
+
|
2016-03-01 07:09:49 +08:00
|
|
|
int j1 = i - k;
|
|
|
|
int k1 = j - l;
|
|
|
|
|
2017-01-31 12:33:54 +08:00
|
|
|
@@ -351,7 +359,7 @@ public class PlayerChunkMap {
|
2016-04-24 09:39:22 +08:00
|
|
|
if (j1 != 0 || k1 != 0) {
|
|
|
|
for (int l1 = i - i1; l1 <= i + i1; ++l1) {
|
|
|
|
for (int i2 = j - i1; i2 <= j + i1; ++i2) {
|
|
|
|
- if (!this.a(l1, i2, k, l, i1)) {
|
|
|
|
+ if (!this.a(l1, i2, k, l, viewDistance)) { // Paper - Player view distance API
|
|
|
|
// this.c(l1, i2).a(entityplayer);
|
|
|
|
chunksToLoad.add(new ChunkCoordIntPair(l1, i2)); // CraftBukkit
|
|
|
|
}
|
2017-01-31 12:33:54 +08:00
|
|
|
@@ -386,6 +394,8 @@ public class PlayerChunkMap {
|
2016-08-14 04:26:40 +08:00
|
|
|
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) {
|
2017-01-31 12:33:54 +08:00
|
|
|
@@ -395,36 +405,55 @@ public class PlayerChunkMap {
|
2016-08-14 04:26:40 +08:00
|
|
|
|
|
|
|
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;
|
2017-11-19 10:45:22 +08:00
|
|
|
@@ -503,4 +532,29 @@ public class PlayerChunkMap {
|
2016-03-01 07:09:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
+
|
|
|
|
+ // Paper start - Player view distance API
|
2017-11-19 10:45:22 +08:00
|
|
|
+ public void updateViewDistance(EntityPlayer player, int distanceIn) {
|
2016-04-24 09:39:22 +08:00
|
|
|
+ final int oldViewDistance = player.getViewDistance();
|
|
|
|
+
|
2017-11-19 10:45:22 +08:00
|
|
|
+ // This represents the view distance that we will set on the player
|
|
|
|
+ // It can exist as a negative value
|
|
|
|
+ int playerViewDistance = MathHelper.clamp(distanceIn, 3, 32);
|
|
|
|
+
|
|
|
|
+ // This value is the one we actually use to update the chunk map
|
|
|
|
+ // We don't ever want this to be a negative
|
|
|
|
+ int toSet = playerViewDistance;
|
|
|
|
+
|
|
|
|
+ if (distanceIn < 0) {
|
|
|
|
+ playerViewDistance = -1;
|
|
|
|
+ toSet = world.getPlayerChunkMap().getViewDistance();
|
2016-05-12 10:07:46 +08:00
|
|
|
+ }
|
2017-11-19 10:45:22 +08:00
|
|
|
+
|
|
|
|
+ if (toSet != oldViewDistance) {
|
2016-08-14 04:26:40 +08:00
|
|
|
+ // Order matters
|
2017-11-19 10:45:22 +08:00
|
|
|
+ this.setViewDistance(player, toSet);
|
|
|
|
+ player.setViewDistance(playerViewDistance);
|
2016-03-01 07:09:49 +08:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2018-02-13 02:04:05 +08:00
|
|
|
index 44d0db180..b2b707305 100644
|
2016-03-01 07:09:49 +08:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2018-02-13 02:04:05 +08:00
|
|
|
@@ -1549,6 +1549,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2016-04-14 04:57:34 +08:00
|
|
|
return this.getHandle().affectsSpawning;
|
2016-03-01 07:09:49 +08:00
|
|
|
}
|
2016-04-14 04:57:34 +08:00
|
|
|
|
2016-03-01 07:09:49 +08:00
|
|
|
+ @Override
|
|
|
|
+ public int getViewDistance() {
|
2016-04-24 09:39:22 +08:00
|
|
|
+ return getHandle().getViewDistance();
|
2016-03-01 07:09:49 +08:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setViewDistance(int viewDistance) {
|
|
|
|
+ ((WorldServer) getHandle().world).getPlayerChunkMap().updateViewDistance(getHandle(), viewDistance);
|
|
|
|
+ }
|
2016-04-14 04:57:34 +08:00
|
|
|
+
|
2016-03-01 07:09:49 +08:00
|
|
|
// Spigot start
|
2016-04-14 04:57:34 +08:00
|
|
|
private final Player.Spigot spigot = new Player.Spigot()
|
|
|
|
{
|
2016-03-01 07:09:49 +08:00
|
|
|
--
|
2018-04-28 23:31:26 +08:00
|
|
|
2.17.0
|
2016-03-01 07:09:49 +08:00
|
|
|
|