mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-15 07:01:36 +08:00
15cdfc7472
Closes GH-169
114 lines
4.8 KiB
Diff
114 lines
4.8 KiB
Diff
From bae3a766c801e4eac121ce00213b2b8ce57d27fb 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 dffc6d9..2db41bc 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;
|
|
@@ -68,6 +69,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 b618cf1..202085b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1416,6 +1416,16 @@ 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()
|
|
{
|
|
--
|
|
2.8.0
|
|
|