From 811b3406a396b70db21ba767db374250d572dfc8 Mon Sep 17 00:00:00 2001 From: Byteflux Date: Wed, 1 Jul 2015 01:01:42 -0700 Subject: [PATCH] Add player view distance API --- .../Add-player-view-distance-API.patch | 40 +++++ .../Add-player-view-distance-API.patch | 139 ++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 Spigot-API-Patches/Add-player-view-distance-API.patch create mode 100644 Spigot-Server-Patches/Add-player-view-distance-API.patch diff --git a/Spigot-API-Patches/Add-player-view-distance-API.patch b/Spigot-API-Patches/Add-player-view-distance-API.patch new file mode 100644 index 0000000000..e42c9875f1 --- /dev/null +++ b/Spigot-API-Patches/Add-player-view-distance-API.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Byteflux +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 + diff --git a/Spigot-Server-Patches/Add-player-view-distance-API.patch b/Spigot-Server-Patches/Add-player-view-distance-API.patch new file mode 100644 index 0000000000..ae4383bd49 --- /dev/null +++ b/Spigot-Server-Patches/Add-player-view-distance-API.patch @@ -0,0 +1,139 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Byteflux +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 chunkList = new LinkedList(); + +- 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 chunksToLoad = new LinkedList(); // 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 +