2016-03-03 10:46:26 +01:00
|
|
|
From 58791be2a7a101b811e2c0dce46d0ec39720c5cd Mon Sep 17 00:00:00 2001
|
2016-03-01 00:09:49 +01: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-03-03 10:46:26 +01:00
|
|
|
index 94b487c..3536c34 100644
|
2016-03-01 00:09:49 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
|
|
@@ -53,6 +53,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
|
|
public boolean f;
|
|
|
|
public int ping;
|
|
|
|
public boolean viewingCredits;
|
|
|
|
+ public int viewDistance; // Paper - Player view distance API
|
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
public String displayName;
|
|
|
|
@@ -83,6 +84,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
|
|
|
|
|
|
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
|
|
|
|
super(worldserver, gameprofile);
|
|
|
|
+ this.viewDistance = world.spigotConfig.viewDistance; // Paper - Player view distance API
|
|
|
|
playerinteractmanager.player = this;
|
|
|
|
this.playerInteractManager = playerinteractmanager;
|
|
|
|
BlockPosition blockposition = worldserver.getSpawn();
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
index 8ef7eb2..5421026 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
|
|
|
@@ -284,8 +284,10 @@ public class PlayerChunkMap {
|
|
|
|
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
|
|
|
|
+ for (int k = i - entityplayer.viewDistance; k <= i + entityplayer.viewDistance; ++k) {
|
|
|
|
+ for (int l = j - entityplayer.viewDistance; l <= j + entityplayer.viewDistance; ++l) {
|
|
|
|
+ // Paper end
|
|
|
|
PlayerChunk playerchunk = this.b(k, l);
|
|
|
|
|
|
|
|
if (playerchunk != null) {
|
|
|
|
@@ -315,7 +317,7 @@ public class PlayerChunkMap {
|
|
|
|
if (d2 >= 64.0D) {
|
|
|
|
int k = (int) entityplayer.d >> 4;
|
|
|
|
int l = (int) entityplayer.e >> 4;
|
|
|
|
- int i1 = this.j;
|
|
|
|
+ int i1 = entityplayer.viewDistance; // Paper - Player view distance API
|
|
|
|
int j1 = i - k;
|
|
|
|
int k1 = j - l;
|
|
|
|
|
|
|
|
@@ -471,4 +473,36 @@ public class PlayerChunkMap {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
+
|
|
|
|
+ // Paper start - Player view distance API
|
|
|
|
+ public void updateViewDistance(EntityPlayer player, int viewDistance) {
|
|
|
|
+ viewDistance = MathHelper.clamp(viewDistance, 3, 32);
|
|
|
|
+ if (viewDistance != player.viewDistance) {
|
|
|
|
+ int cx = (int) player.locX >> 4;
|
|
|
|
+ int cz = (int) player.locZ >> 4;
|
|
|
|
+
|
|
|
|
+ if (viewDistance - player.viewDistance > 0) {
|
|
|
|
+ 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 {
|
|
|
|
+ for (int x = cx - player.viewDistance; x <= cx + player.viewDistance; ++x) {
|
|
|
|
+ for (int z = cz - player.viewDistance; z <= cz + player.viewDistance; ++z) {
|
|
|
|
+ if (!this.a(x, z, cx, cz, viewDistance)) {
|
|
|
|
+ this.c(x, z).b(player);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ player.viewDistance = viewDistance;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 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-03-03 10:46:26 +01:00
|
|
|
index 972ead0..1a3c6d7 100644
|
2016-03-01 00:09:49 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2016-03-03 10:46:26 +01:00
|
|
|
@@ -1423,6 +1423,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2016-03-01 00:09:49 +01:00
|
|
|
public void setAffectsSpawning(boolean affects) {
|
|
|
|
getHandle().affectsSpawning = affects;
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int getViewDistance() {
|
|
|
|
+ return getHandle().viewDistance;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setViewDistance(int viewDistance) {
|
|
|
|
+ ((WorldServer) getHandle().world).getPlayerChunkMap().updateViewDistance(getHandle(), viewDistance);
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
// Spigot start
|
|
|
|
--
|
|
|
|
2.7.2
|
|
|
|
|