PaperMC/Spigot-Server-Patches/Add-player-view-distance-API.patch
2016-04-13 15:57:34 -05:00

111 lines
No EOL
4.9 KiB
Diff

From 0000000000000000000000000000000000000000 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
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -0,0 +0,0 @@ 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;
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -0,0 +0,0 @@ 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) {
@@ -0,0 +0,0 @@ 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;
@@ -0,0 +0,0 @@ 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
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return this.getHandle().affectsSpawning;
}
+ @Override
+ public int getViewDistance() {
+ return getHandle().viewDistance;
+ }
+
+ @Override
+ public void setViewDistance(int viewDistance) {
+ ((WorldServer) getHandle().world).getPlayerChunkMap().updateViewDistance(getHandle(), viewDistance);
+ }
+
// Spigot start
private final Player.Spigot spigot = new Player.Spigot()
{
--