mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Add player view distance API
This commit is contained in:
parent
498811bfc5
commit
811b3406a3
2 changed files with 179 additions and 0 deletions
40
Spigot-API-Patches/Add-player-view-distance-API.patch
Normal file
40
Spigot-API-Patches/Add-player-view-distance-API.patch
Normal file
|
@ -0,0 +1,40 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Byteflux <byte@byteflux.net>
|
||||
Date: Wed, 1 Jul 2015 00:59:50 -0700
|
||||
Subject: [PATCH] Add player view distance API
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Player.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Player.java
|
||||
@@ -0,0 +0,0 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline
|
||||
{
|
||||
throw new UnsupportedOperationException( "Not supported yet" );
|
||||
}
|
||||
+
|
||||
+ /**
|
||||
+ * Get the view distance for this player
|
||||
+ *
|
||||
+ * @return View distance
|
||||
+ */
|
||||
+ public int getViewDistance()
|
||||
+ {
|
||||
+ throw new UnsupportedOperationException( "Not supported yet" );
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Set the view distance for this player
|
||||
+ *
|
||||
+ * @param viewDistance View distance
|
||||
+ */
|
||||
+ public void setViewDistance(int viewDistance)
|
||||
+ {
|
||||
+ throw new UnsupportedOperationException( "Not supported yet" );
|
||||
+ }
|
||||
}
|
||||
|
||||
Spigot spigot();
|
||||
--
|
||||
1.9.5.msysgit.1
|
||||
|
139
Spigot-Server-Patches/Add-player-view-distance-API.patch
Normal file
139
Spigot-Server-Patches/Add-player-view-distance-API.patch
Normal file
|
@ -0,0 +1,139 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Byteflux <byte@byteflux.net>
|
||||
Date: Wed, 1 Jul 2015 00:59:06 -0700
|
||||
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 {
|
||||
// CraftBukkit end
|
||||
// Spigot start
|
||||
public boolean collidesWithEntities = true;
|
||||
+ public int viewDistance; // PaperSpigot - Player view distance API
|
||||
|
||||
@Override
|
||||
public boolean ad()
|
||||
@@ -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 = worldserver.getServer().getViewDistance(); // PaperSpigot - 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 {
|
||||
// CraftBukkit start - Load nearby chunks first
|
||||
List<ChunkCoordIntPair> chunkList = new LinkedList<ChunkCoordIntPair>();
|
||||
|
||||
- for (int k = i - this.g; k <= i + this.g; ++k) {
|
||||
- for (int l = j - this.g; l <= j + this.g; ++l) {
|
||||
+ // PaperSpigot 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) {
|
||||
+ // PaperSpigot end
|
||||
chunkList.add(new ChunkCoordIntPair(k, l));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class PlayerChunkMap {
|
||||
public void b(EntityPlayer entityplayer) {
|
||||
ArrayList arraylist = Lists.newArrayList(entityplayer.chunkCoordIntPairQueue);
|
||||
int i = 0;
|
||||
- int j = this.g;
|
||||
+ int j = entityplayer.viewDistance; // PaperSpigot - Player view distance API
|
||||
int k = (int) entityplayer.locX >> 4;
|
||||
int l = (int) entityplayer.locZ >> 4;
|
||||
int i1 = 0;
|
||||
@@ -0,0 +0,0 @@ public class PlayerChunkMap {
|
||||
int i = (int) entityplayer.d >> 4;
|
||||
int j = (int) entityplayer.e >> 4;
|
||||
|
||||
- for (int k = i - this.g; k <= i + this.g; ++k) {
|
||||
- for (int l = j - this.g; l <= j + this.g; ++l) {
|
||||
+ // PaperSpigot 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) {
|
||||
+ // PaperSpigot end
|
||||
PlayerChunkMap.PlayerChunk playerchunkmap_playerchunk = this.a(k, l, false);
|
||||
|
||||
if (playerchunkmap_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.g;
|
||||
+ int i1 = entityplayer.viewDistance; // PaperSpigot - Player view distance API
|
||||
int j1 = i - k;
|
||||
int k1 = j - l;
|
||||
List<ChunkCoordIntPair> chunksToLoad = new LinkedList<ChunkCoordIntPair>(); // CraftBukkit
|
||||
@@ -0,0 +0,0 @@ public class PlayerChunkMap {
|
||||
}
|
||||
}
|
||||
|
||||
+ // PaperSpigot 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) {
|
||||
+ PlayerChunkMap.PlayerChunk playerchunkmap_playerchunk = this.a(x, z, true);
|
||||
+
|
||||
+ if (!playerchunkmap_playerchunk.b.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.a(x, z, true).b(player);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ player.viewDistance = viewDistance;
|
||||
+ }
|
||||
+ }
|
||||
+ // PaperSpigot end
|
||||
+
|
||||
public static int getFurthestViewableBlock(int i) {
|
||||
return i * 16 - 16;
|
||||
}
|
||||
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 {
|
||||
getHandle().affectsSpawning = affects;
|
||||
}
|
||||
// PaperSpigot end
|
||||
+
|
||||
+ // PaperSpigot start - Player view distance API
|
||||
+ @Override
|
||||
+ public int getViewDistance() {
|
||||
+ return getHandle().viewDistance;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setViewDistance(int viewDistance) {
|
||||
+ ((WorldServer) getHandle().world).getPlayerChunkMap().updateViewDistance(getHandle(), viewDistance);
|
||||
+ }
|
||||
+ // PaperSpigot end
|
||||
};
|
||||
|
||||
public Player.Spigot spigot()
|
||||
--
|
||||
1.9.5.msysgit.1
|
||||
|
Loading…
Reference in a new issue