2016-04-24 01:39:22 +00:00
|
|
|
From a957633c889b9135b6f3a6fc0c9cf28d30beeb4a Mon Sep 17 00:00:00 2001
|
2016-02-29 23:09:49 +00: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
|
2016-04-24 01:39:22 +00:00
|
|
|
index dffc6d9..184b9c2 100644
|
2016-02-29 23:09:49 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
2016-04-24 01:39:22 +00:00
|
|
|
@@ -53,6 +53,15 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
2016-02-29 23:09:49 +00:00
|
|
|
public boolean f;
|
|
|
|
public int ping;
|
|
|
|
public boolean viewingCredits;
|
2016-04-24 01:39:22 +00: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-02-29 23:09:49 +00: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
|
2016-04-24 01:39:22 +00:00
|
|
|
index 8ef7eb2..d7cbe31 100644
|
2016-02-29 23:09:49 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
2016-04-24 01:39:22 +00:00
|
|
|
@@ -43,7 +43,7 @@ public class PlayerChunkMap {
|
|
|
|
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;
|
|
|
|
@@ -284,8 +284,11 @@ public class PlayerChunkMap {
|
2016-02-29 23:09:49 +00: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 01:39:22 +00:00
|
|
|
+ int viewDistance = entityplayer.getViewDistance();
|
|
|
|
+ for (int k = i - viewDistance; k <= i + viewDistance; ++k) {
|
|
|
|
+ for (int l = j - viewDistance; l <= j + viewDistance; ++l) {
|
2016-02-29 23:09:49 +00:00
|
|
|
+ // Paper end
|
|
|
|
PlayerChunk playerchunk = this.b(k, l);
|
|
|
|
|
|
|
|
if (playerchunk != null) {
|
2016-04-24 01:39:22 +00:00
|
|
|
@@ -315,7 +318,9 @@ public class PlayerChunkMap {
|
2016-02-29 23:09:49 +00:00
|
|
|
if (d2 >= 64.0D) {
|
|
|
|
int k = (int) entityplayer.d >> 4;
|
|
|
|
int l = (int) entityplayer.e >> 4;
|
|
|
|
- int i1 = this.j;
|
2016-04-24 01:39:22 +00:00
|
|
|
+ final int viewDistance = entityplayer.getViewDistance(); // Paper - Player view distance API
|
|
|
|
+ int i1 = Math.max(getViewDistance(), viewDistance); // Paper - Player view distance API
|
|
|
|
+
|
2016-02-29 23:09:49 +00:00
|
|
|
int j1 = i - k;
|
|
|
|
int k1 = j - l;
|
|
|
|
|
2016-04-24 01:39:22 +00:00
|
|
|
@@ -324,7 +329,7 @@ public class PlayerChunkMap {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
@@ -471,4 +476,42 @@ public class PlayerChunkMap {
|
2016-02-29 23:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
+
|
|
|
|
+ // Paper start - Player view distance API
|
2016-04-24 01:39:22 +00:00
|
|
|
+ public void updateViewDistance(EntityPlayer player, int toSet) {
|
|
|
|
+ final int oldViewDistance = player.getViewDistance();
|
|
|
|
+
|
|
|
|
+ int viewDistance = MathHelper.clamp(toSet, 3, 32);
|
|
|
|
+ if (viewDistance != oldViewDistance) {
|
2016-02-29 23:09:49 +00:00
|
|
|
+ int cx = (int) player.locX >> 4;
|
|
|
|
+ int cz = (int) player.locZ >> 4;
|
|
|
|
+
|
2016-04-24 01:39:22 +00:00
|
|
|
+ if (viewDistance - oldViewDistance > 0) {
|
2016-02-29 23:09:49 +00:00
|
|
|
+ for (int x = cx - viewDistance; x <= cx + viewDistance; ++x) {
|
|
|
|
+ for (int z = cz - viewDistance; z <= cz + viewDistance; ++z) {
|
|
|
|
+ PlayerChunk playerchunkmap_playerchunk = this.c(x, z);
|
|
|
|
+
|
|
|
|
+ if (!playerchunkmap_playerchunk.c.contains(player)) {
|
|
|
|
+ playerchunkmap_playerchunk.a(player);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
2016-04-24 01:39:22 +00:00
|
|
|
+ for (int x = cx - oldViewDistance; x <= cx + oldViewDistance; ++x) {
|
|
|
|
+ for (int z = cz - oldViewDistance; z <= cz + oldViewDistance; ++z) {
|
2016-02-29 23:09:49 +00:00
|
|
|
+ if (!this.a(x, z, cx, cz, viewDistance)) {
|
|
|
|
+ this.c(x, z).b(player);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2016-04-24 01:39:22 +00:00
|
|
|
+ player.setViewDistance(viewDistance);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (toSet == -1) {
|
|
|
|
+ player.setViewDistance(-1);
|
2016-02-29 23:09:49 +00: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
|
2016-04-24 01:39:22 +00:00
|
|
|
index 64bd053..4abf441 100644
|
2016-02-29 23:09:49 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2016-03-25 23:21:38 +00:00
|
|
|
@@ -1416,6 +1416,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2016-04-13 20:57:34 +00:00
|
|
|
return this.getHandle().affectsSpawning;
|
2016-02-29 23:09:49 +00:00
|
|
|
}
|
2016-04-13 20:57:34 +00:00
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
+ @Override
|
|
|
|
+ public int getViewDistance() {
|
2016-04-24 01:39:22 +00:00
|
|
|
+ return getHandle().getViewDistance();
|
2016-02-29 23:09:49 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setViewDistance(int viewDistance) {
|
|
|
|
+ ((WorldServer) getHandle().world).getPlayerChunkMap().updateViewDistance(getHandle(), viewDistance);
|
|
|
|
+ }
|
2016-04-13 20:57:34 +00:00
|
|
|
+
|
2016-02-29 23:09:49 +00:00
|
|
|
// Spigot start
|
2016-04-13 20:57:34 +00:00
|
|
|
private final Player.Spigot spigot = new Player.Spigot()
|
|
|
|
{
|
2016-02-29 23:09:49 +00:00
|
|
|
--
|
2016-04-24 01:39:22 +00:00
|
|
|
2.8.1
|
2016-02-29 23:09:49 +00:00
|
|
|
|