mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 10:35:38 +01:00
Fix Player View Distance API corrupting Chunk Sending - Fixes #207
The Player View Distance patch has been screwing with the configured world view distance. The world a player was created in would set the players view distance, which would be locked to that distance. Then switching worlds would not give you an updated view distance. This then caused issues with what view distance the player should have in the chunk map and did not send chunks to the client correctly during movement. This patch has now been changed to use a -1 default for "default" and will not override view distance until someone has actually used the API to change it.
This commit is contained in:
parent
392d05c63d
commit
2cbd400e17
@ -1,68 +1,91 @@
|
||||
From bae3a766c801e4eac121ce00213b2b8ce57d27fb Mon Sep 17 00:00:00 2001
|
||||
From a957633c889b9135b6f3a6fc0c9cf28d30beeb4a 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
|
||||
index dffc6d9..184b9c2 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 {
|
||||
@@ -53,6 +53,15 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
||||
public boolean f;
|
||||
public int ping;
|
||||
public boolean viewingCredits;
|
||||
+ public int viewDistance; // Paper - Player view distance API
|
||||
+ // Paper start - Player view distance API
|
||||
+ private int viewDistance = -1;
|
||||
+ public int getViewDistance() {
|
||||
+ return viewDistance == -1 ? ((WorldServer) world).getPlayerChunkMap().getViewDistance() : viewDistance;
|
||||
+ }
|
||||
+ public void setViewDistance(int viewDistance) {
|
||||
+ this.viewDistance = viewDistance;
|
||||
+ }
|
||||
+ // Paper end
|
||||
|
||||
// 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
|
||||
index 8ef7eb2..d7cbe31 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 {
|
||||
@@ -43,7 +43,7 @@ public class PlayerChunkMap {
|
||||
private final List<PlayerChunk> g = Lists.newLinkedList();
|
||||
private final List<PlayerChunk> h = Lists.newLinkedList();
|
||||
private final List<PlayerChunk> i = Lists.newArrayList();
|
||||
- private int j;
|
||||
+ private int j;public int getViewDistance() { return j; } // Paper OBFHELPER
|
||||
private long k;
|
||||
private boolean l = true;
|
||||
private boolean m = true;
|
||||
@@ -284,8 +284,11 @@ 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) {
|
||||
+ int viewDistance = entityplayer.getViewDistance();
|
||||
+ for (int k = i - viewDistance; k <= i + viewDistance; ++k) {
|
||||
+ for (int l = j - viewDistance; l <= j + viewDistance; ++l) {
|
||||
+ // Paper end
|
||||
PlayerChunk playerchunk = this.b(k, l);
|
||||
|
||||
if (playerchunk != null) {
|
||||
@@ -315,7 +317,7 @@ public class PlayerChunkMap {
|
||||
@@ -315,7 +318,9 @@ 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
|
||||
+ final int viewDistance = entityplayer.getViewDistance(); // Paper - Player view distance API
|
||||
+ int i1 = Math.max(getViewDistance(), viewDistance); // Paper - Player view distance API
|
||||
+
|
||||
int j1 = i - k;
|
||||
int k1 = j - l;
|
||||
|
||||
@@ -471,4 +473,36 @@ public class PlayerChunkMap {
|
||||
@@ -324,7 +329,7 @@ public class PlayerChunkMap {
|
||||
if (j1 != 0 || k1 != 0) {
|
||||
for (int l1 = i - i1; l1 <= i + i1; ++l1) {
|
||||
for (int i2 = j - i1; i2 <= j + i1; ++i2) {
|
||||
- if (!this.a(l1, i2, k, l, i1)) {
|
||||
+ if (!this.a(l1, i2, k, l, viewDistance)) { // Paper - Player view distance API
|
||||
// this.c(l1, i2).a(entityplayer);
|
||||
chunksToLoad.add(new ChunkCoordIntPair(l1, i2)); // CraftBukkit
|
||||
}
|
||||
@@ -471,4 +476,42 @@ 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) {
|
||||
+ public void updateViewDistance(EntityPlayer player, int toSet) {
|
||||
+ final int oldViewDistance = player.getViewDistance();
|
||||
+
|
||||
+ int viewDistance = MathHelper.clamp(toSet, 3, 32);
|
||||
+ if (viewDistance != oldViewDistance) {
|
||||
+ int cx = (int) player.locX >> 4;
|
||||
+ int cz = (int) player.locZ >> 4;
|
||||
+
|
||||
+ if (viewDistance - player.viewDistance > 0) {
|
||||
+ if (viewDistance - oldViewDistance > 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);
|
||||
@ -73,8 +96,8 @@ index 8ef7eb2..5421026 100644
|
||||
+ }
|
||||
+ }
|
||||
+ } else {
|
||||
+ for (int x = cx - player.viewDistance; x <= cx + player.viewDistance; ++x) {
|
||||
+ for (int z = cz - player.viewDistance; z <= cz + player.viewDistance; ++z) {
|
||||
+ for (int x = cx - oldViewDistance; x <= cx + oldViewDistance; ++x) {
|
||||
+ for (int z = cz - oldViewDistance; z <= cz + oldViewDistance; ++z) {
|
||||
+ if (!this.a(x, z, cx, cz, viewDistance)) {
|
||||
+ this.c(x, z).b(player);
|
||||
+ }
|
||||
@ -82,13 +105,17 @@ index 8ef7eb2..5421026 100644
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ player.viewDistance = viewDistance;
|
||||
+ player.setViewDistance(viewDistance);
|
||||
+ }
|
||||
+
|
||||
+ if (toSet == -1) {
|
||||
+ player.setViewDistance(-1);
|
||||
+ }
|
||||
+ }
|
||||
+ // 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
|
||||
index 64bd053..4abf441 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 {
|
||||
@ -97,7 +124,7 @@ index b618cf1..202085b 100644
|
||||
|
||||
+ @Override
|
||||
+ public int getViewDistance() {
|
||||
+ return getHandle().viewDistance;
|
||||
+ return getHandle().getViewDistance();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
@ -109,5 +136,5 @@ index b618cf1..202085b 100644
|
||||
private final Player.Spigot spigot = new Player.Spigot()
|
||||
{
|
||||
--
|
||||
2.8.0
|
||||
2.8.1
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
From 110bf1e5d3f0fae847488faaabb4e5aacce9c575 Mon Sep 17 00:00:00 2001
|
||||
From 76e860a49ebe0052a395fbbc5d908147fbdd123a Mon Sep 17 00:00:00 2001
|
||||
From: Sudzzy <originmc@outlook.com>
|
||||
Date: Wed, 2 Mar 2016 23:34:44 -0600
|
||||
Subject: [PATCH] Configurable container update tick rate
|
||||
@ -19,18 +19,18 @@ index abed8ea..8b76052 100644
|
||||
+ }
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
index ed307bc..2681aa5 100644
|
||||
index 184b9c2..4bf8344 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
@@ -54,6 +54,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
||||
public int ping;
|
||||
public boolean viewingCredits;
|
||||
public int viewDistance; // Paper - Player view distance API
|
||||
@@ -62,6 +62,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
||||
this.viewDistance = viewDistance;
|
||||
}
|
||||
// Paper end
|
||||
+ private int containerUpdateDelay; // Paper
|
||||
|
||||
// CraftBukkit start
|
||||
public String displayName;
|
||||
@@ -200,7 +201,12 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
||||
@@ -207,7 +208,12 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
||||
--this.noDamageTicks;
|
||||
}
|
||||
|
||||
@ -45,5 +45,5 @@ index ed307bc..2681aa5 100644
|
||||
this.closeInventory();
|
||||
this.activeContainer = this.defaultContainer;
|
||||
--
|
||||
2.7.4
|
||||
2.8.1
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
From 25599d1fbdd4d7a7098bb0b3c2d2d685ea27113c Mon Sep 17 00:00:00 2001
|
||||
From 5771cd988dda8603f0a922e5c61648c6ff2f6b6e Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Ennis <dennis@icontact.com>
|
||||
Date: Sun, 20 Mar 2016 15:22:42 -0400
|
||||
Subject: [PATCH] Catch Async PlayerChunkMap operations
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
index 5421026..7100710 100644
|
||||
index d7cbe31..17d0c81 100644
|
||||
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
|
||||
@@ -415,10 +415,12 @@ public class PlayerChunkMap {
|
||||
@@ -418,10 +418,12 @@ public class PlayerChunkMap {
|
||||
}
|
||||
|
||||
public void a(PlayerChunk playerchunk) {
|
||||
@ -22,5 +22,5 @@ index 5421026..7100710 100644
|
||||
long i = d(chunkcoordintpair.x, chunkcoordintpair.z);
|
||||
|
||||
--
|
||||
2.8.0
|
||||
2.8.1
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
From 08477cd64ad64ec8bf8c743d68fcbf161f26a9ed Mon Sep 17 00:00:00 2001
|
||||
From 807032786429cbaf3985e457d83dfdb46a195348 Mon Sep 17 00:00:00 2001
|
||||
From: Isaac Moore <rmsy@me.com>
|
||||
Date: Tue, 19 Apr 2016 14:09:31 -0500
|
||||
Subject: [PATCH] Implement PlayerLocaleChangeEvent
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
index 1d302f5..a2681c3 100644
|
||||
index 4bf8344..6fdf276 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
@@ -25,7 +25,7 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
@ -17,7 +17,7 @@ index 1d302f5..a2681c3 100644
|
||||
public PlayerConnection playerConnection;
|
||||
public final MinecraftServer server;
|
||||
public final PlayerInteractManager playerInteractManager;
|
||||
@@ -1069,7 +1069,14 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
||||
@@ -1076,7 +1076,14 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
||||
}
|
||||
|
||||
public void a(PacketPlayInSettings packetplayinsettings) {
|
||||
@ -33,7 +33,7 @@ index 1d302f5..a2681c3 100644
|
||||
this.cg = packetplayinsettings.d();
|
||||
this.getDataWatcher().set(EntityPlayer.bp, Byte.valueOf((byte) packetplayinsettings.e()));
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
index b0e4800..7c63db1 100644
|
||||
index 78a8631..003f700 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
@@ -1654,7 +1654,10 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
@ -49,5 +49,5 @@ index b0e4800..7c63db1 100644
|
||||
|
||||
@Override
|
||||
--
|
||||
2.8.0
|
||||
2.8.1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user