mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-21 00:17:56 +01:00
30f02fe6e5
I think its pretty clear that no one uses this given that it didn't work at all before
114 lines
4.8 KiB
Diff
114 lines
4.8 KiB
Diff
From fb8cc16fde7343e4e275abd13e7764dd3b7e0f6f 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 987164e..5b5d1ef 100644
|
|
--- 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
|
|
index fe9e452..4a5de6b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1423,6 +1423,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
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
|
|
|