3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00

Add player view distance API

Dieser Commit ist enthalten in:
Byteflux 2015-07-01 01:01:42 -07:00
Ursprung d07fe95b65
Commit 7f032d52e6
2 geänderte Dateien mit 179 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,40 @@
From 53ad29ca507c248633ae0e1e2b0c9ecde5569891 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 9d23835..53abb36 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -1162,6 +1162,26 @@ 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

Datei anzeigen

@ -0,0 +1,139 @@
From 5fdfe6ba2c21440aea2e5227e230f412d25d96ec 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 592fb75..baa08c9 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -64,6 +64,7 @@ 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()
@@ -80,6 +81,7 @@ 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 abb24c8..38586aa 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -129,8 +129,10 @@ 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));
}
}
@@ -148,7 +150,7 @@ 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;
@@ -194,8 +196,10 @@ 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) {
@@ -224,7 +228,7 @@ 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
@@ -309,6 +313,38 @@ 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 23753bb..fc0809a 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1494,6 +1494,18 @@ 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