Use Player view distance for PlayerNaturallySpawnCreaturesEvent

The spigot view distance may not be correct, as the player may
have a specific view distance configured.
This commit is contained in:
Spottedleaf 2024-11-28 14:22:32 -08:00
parent 78fd8f931b
commit 0cc7bd4857
12 changed files with 64 additions and 63 deletions

View file

@ -3311,7 +3311,7 @@ index 0000000000000000000000000000000000000000..4123edddc556c47f3f8d83523c125fd2
+} +}
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..49fe9eed5d5d08abd6e9778fe0d0545f35552435 index 0000000000000000000000000000000000000000..f7cd0aa43d0b9249d0a317fab41fefa0d951bca0
--- /dev/null --- /dev/null
+++ b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java
@@ -0,0 +1,288 @@ @@ -0,0 +1,288 @@
@ -3582,15 +3582,15 @@ index 0000000000000000000000000000000000000000..49fe9eed5d5d08abd6e9778fe0d0545f
+ } + }
+ +
+ public static int getSendViewDistance(final ServerPlayer player) { + public static int getSendViewDistance(final ServerPlayer player) {
+ return getLoadViewDistance(player); + return getLoadViewDistance(player) - 1;
+ } + }
+ +
+ public static int getLoadViewDistance(final ServerPlayer player) { + public static int getLoadViewDistance(final ServerPlayer player) {
+ final ServerLevel level = player.serverLevel(); + final ServerLevel level = player.serverLevel();
+ if (level == null) { + if (level == null) {
+ return org.bukkit.Bukkit.getViewDistance(); + return org.bukkit.Bukkit.getViewDistance() + 1;
+ } + }
+ return level.chunkSource.chunkMap.getPlayerViewDistance(player); + return level.chunkSource.chunkMap.serverViewDistance + 1;
+ } + }
+ +
+ public static int getTickViewDistance(final ServerPlayer player) { + public static int getTickViewDistance(final ServerPlayer player) {
@ -4695,7 +4695,7 @@ index 46cab7a8c7b87ab01b26074b04f5a02b3907cfc4..49019b4a9bc4e634d54a9b0acaf9229a
+ // Paper end + // Paper end
} }
diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
index 0ea9eba1367858dfa5284524a8dd2f79daf6fc69..18b64c00fa73e233bf41f519db54a1d43c2a8b1f 100644 index 87da4ff63294735bfcbfa8442fb8ae7196b0f197..2eb155d3df2e34c050fd28c5a64015e6e1232851 100644
--- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java --- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
+++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java +++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
@@ -215,7 +215,7 @@ public class GlobalConfiguration extends ConfigurationPart { @@ -215,7 +215,7 @@ public class GlobalConfiguration extends ConfigurationPart {

View file

@ -9,21 +9,23 @@ from triggering monster spawns on a server.
Also a highly more effecient way to blanket block spawns in a world Also a highly more effecient way to blanket block spawns in a world
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 261943f1f188643793a72bd239dfc5fe604e3b99..985ba48a5ac027d3c3dcd9b710b53748508966fb 100644 index 261943f1f188643793a72bd239dfc5fe604e3b99..ebe6c631d772cf41038701aafbe4e0bbb024f7f5 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1098,7 +1098,9 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1094,11 +1094,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
chunkRange = (chunkRange > this.level.spigotConfig.viewDistance) ? (byte) this.level.spigotConfig.viewDistance : chunkRange; }
chunkRange = (chunkRange > 8) ? 8 : chunkRange;
private boolean anyPlayerCloseEnoughForSpawningInternal(ChunkPos chunkcoordintpair, boolean reducedRange) {
- int chunkRange = this.level.spigotConfig.mobSpawnRange;
- chunkRange = (chunkRange > this.level.spigotConfig.viewDistance) ? (byte) this.level.spigotConfig.viewDistance : chunkRange;
- chunkRange = (chunkRange > 8) ? 8 : chunkRange;
-
- double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; - double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D;
+ final int finalChunkRange = chunkRange; // Paper for lambda below + double blockRange; // Paper - use from event
+ //double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; // Paper - use from event
+ double blockRange = 16384.0D; // Paper
// Spigot end // Spigot end
Iterator iterator = this.playerMap.getAllPlayers().iterator(); Iterator iterator = this.playerMap.getAllPlayers().iterator();
@@ -1110,6 +1112,15 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1110,6 +1106,15 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
} }
entityplayer = (ServerPlayer) iterator.next(); entityplayer = (ServerPlayer) iterator.next();
@ -40,18 +42,17 @@ index 261943f1f188643793a72bd239dfc5fe604e3b99..985ba48a5ac027d3c3dcd9b710b53748
return true; return true;
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 2e2976efcf99de269f67dec2c87cb910ff280562..5749698b0c9647295e0be6f7d532d39c18432539 100644 index 2e2976efcf99de269f67dec2c87cb910ff280562..f4fa64ab18573cb9a22a9bfb79a351c388d1aaa5 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -501,6 +501,15 @@ public class ServerChunkCache extends ChunkSource { @@ -501,6 +501,14 @@ public class ServerChunkCache extends ChunkSource {
List list1; List list1;
if (flag && (this.spawnEnemies || this.spawnFriendlies)) { if (flag && (this.spawnEnemies || this.spawnFriendlies)) {
+ // Paper start - PlayerNaturallySpawnCreaturesEvent + // Paper start - PlayerNaturallySpawnCreaturesEvent
+ int chunkRange = level.spigotConfig.mobSpawnRange;
+ chunkRange = (chunkRange > level.spigotConfig.viewDistance) ? (byte) level.spigotConfig.viewDistance : chunkRange;
+ chunkRange = Math.min(chunkRange, 8);
+ for (ServerPlayer entityPlayer : this.level.players()) { + for (ServerPlayer entityPlayer : this.level.players()) {
+ int chunkRange = Math.min(level.spigotConfig.mobSpawnRange, entityPlayer.getBukkitEntity().getViewDistance());
+ chunkRange = Math.min(chunkRange, 8);
+ entityPlayer.playerNaturallySpawnedEvent = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityPlayer.getBukkitEntity(), (byte) chunkRange); + entityPlayer.playerNaturallySpawnedEvent = new com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent(entityPlayer.getBukkitEntity(), (byte) chunkRange);
+ entityPlayer.playerNaturallySpawnedEvent.callEvent(); + entityPlayer.playerNaturallySpawnedEvent.callEvent();
+ } + }
@ -60,7 +61,7 @@ index 2e2976efcf99de269f67dec2c87cb910ff280562..5749698b0c9647295e0be6f7d532d39c
list1 = NaturalSpawner.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1, this.level); // CraftBukkit list1 = NaturalSpawner.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1, this.level); // CraftBukkit
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index b99bd43bf5185bed21fad7dac31baf1a30bdd1fe..98aeafcc51e23a7534c8d57e4db0eb58abb3f30b 100644 index 0432304139fada99dff884ebf8d08dbf9afc45c7..8fd3802d8e293e35478666bd4e921d58e1ce5b41 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java --- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java +++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -314,6 +314,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player { @@ -314,6 +314,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {

View file

@ -8,10 +8,10 @@ Sets tracking range of watermobs to animals instead of misc and simplifies code
Also ignores Enderdragon, defaulting it to Mojang's setting Also ignores Enderdragon, defaulting it to Mojang's setting
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 985ba48a5ac027d3c3dcd9b710b53748508966fb..5f85d7f7ec57fc1b0375e62a8e8e3e8783f34193 100644 index ebe6c631d772cf41038701aafbe4e0bbb024f7f5..bf9e2851bdc77339bde1fd15c1bad66b8f9e3193 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1598,6 +1598,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1592,6 +1592,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
while (iterator.hasNext()) { while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next(); Entity entity = (Entity) iterator.next();
int j = entity.getType().clientTrackingRange() * 16; int j = entity.getType().clientTrackingRange() * 16;

View file

@ -7,10 +7,10 @@ Suspected case would be around the technique used in .stopRiding
Stack will identify any causer of this and warn instead of crashing. Stack will identify any causer of this and warn instead of crashing.
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 5f85d7f7ec57fc1b0375e62a8e8e3e8783f34193..396310a51480cf0d1ea4c0959d3f8e4ed77b99e3 100644 index bf9e2851bdc77339bde1fd15c1bad66b8f9e3193..48e848e407e4e78e05c35a5cb2393bccc6de3a4f 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1298,6 +1298,13 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1292,6 +1292,13 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
public void addEntity(Entity entity) { public void addEntity(Entity entity) {
org.spigotmc.AsyncCatcher.catchOp("entity track"); // Spigot org.spigotmc.AsyncCatcher.catchOp("entity track"); // Spigot

View file

@ -31,10 +31,10 @@ delays anymore.
public net.minecraft.server.level.ChunkMap addEntity(Lnet/minecraft/world/entity/Entity;)V public net.minecraft.server.level.ChunkMap addEntity(Lnet/minecraft/world/entity/Entity;)V
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 396310a51480cf0d1ea4c0959d3f8e4ed77b99e3..0f8fc275af95750871aa6917aa12053f75c112f7 100644 index 48e848e407e4e78e05c35a5cb2393bccc6de3a4f..2a216485522a63298e239074ef5bdfa1101fa9d6 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1305,6 +1305,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1299,6 +1299,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
return; return;
} }
// Paper end - ignore and warn about illegal addEntity calls instead of crashing server // Paper end - ignore and warn about illegal addEntity calls instead of crashing server
@ -43,7 +43,7 @@ index 396310a51480cf0d1ea4c0959d3f8e4ed77b99e3..0f8fc275af95750871aa6917aa12053f
EntityType<?> entitytypes = entity.getType(); EntityType<?> entitytypes = entity.getType();
int i = entitytypes.clientTrackingRange() * 16; int i = entitytypes.clientTrackingRange() * 16;
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 9911e231ad021286f2da90057b06874f7b4e3b4d..807068fc6065f71961d34cb4f18b6eb39ae49637 100644 index eebf44c7124c4f48b6d48562a00633b1e8ff9b00..8c80a852ed00c2bf79bb68da9d535af425893deb 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java --- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java +++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -317,6 +317,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player { @@ -317,6 +317,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
@ -55,7 +55,7 @@ index 9911e231ad021286f2da90057b06874f7b4e3b4d..807068fc6065f71961d34cb4f18b6eb3
// CraftBukkit end // CraftBukkit end
public boolean isRealPlayer; // Paper public boolean isRealPlayer; // Paper
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index ad4f5a4e00b9b517841acd0b4ff5088e45451bf4..4ff14dc6996634b0fcd365f76055023601ad2be0 100644 index e137278f9dc02eefaaf7071a3219436a94cfcfac..ac5725230b04bc1a333863e251fe86580f909ea9 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java --- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -299,6 +299,13 @@ public abstract class PlayerList { @@ -299,6 +299,13 @@ public abstract class PlayerList {

View file

@ -7,10 +7,10 @@ Reference2BooleanOpenHashMap is going to have
better lookups than HashMap. better lookups than HashMap.
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 0f8fc275af95750871aa6917aa12053f75c112f7..51a6735b35e73175680e61c2d67d4adbedf305c9 100644 index 2a216485522a63298e239074ef5bdfa1101fa9d6..fde03e0e5cd42339e5bfbeb60670139af5f56e1c 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1514,7 +1514,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1508,7 +1508,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
final Entity entity; final Entity entity;
private final int range; private final int range;
SectionPos lastSectionPos; SectionPos lastSectionPos;

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Player Entity Tracking Events
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 51a6735b35e73175680e61c2d67d4adbedf305c9..8b5d11aceb77135c917c3581f4db792ef4b647ec 100644 index fde03e0e5cd42339e5bfbeb60670139af5f56e1c..bf88c5de30e6cde87099dab546e5d1bd817134a2 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1586,7 +1586,11 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1580,7 +1580,11 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
// CraftBukkit end // CraftBukkit end
if (flag) { if (flag) {
if (this.seenBy.add(player.connection)) { if (this.seenBy.add(player.connection)) {

View file

@ -6,10 +6,10 @@ Subject: [PATCH] Configurable entity tracking range by Y coordinate
Options to configure entity tracking by Y coordinate, also for each entity category. Options to configure entity tracking by Y coordinate, also for each entity category.
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 8b5d11aceb77135c917c3581f4db792ef4b647ec..5b993cb8a99c6a0257b9d3d93162f9b2fff552b0 100644 index bf88c5de30e6cde87099dab546e5d1bd817134a2..51c52aeb3724c919443b7f5aa574d64983b57c49 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1577,7 +1577,17 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1571,7 +1571,17 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
double d0 = (double) Math.min(this.getEffectiveRange(), i * 16); double d0 = (double) Math.min(this.getEffectiveRange(), i * 16);
double d1 = vec3d.x * vec3d.x + vec3d.z * vec3d.z; double d1 = vec3d.x * vec3d.x + vec3d.z * vec3d.z;
double d2 = d0 * d0; double d2 = d0 * d0;

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Don't check if we can see non-visible entities
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 5b993cb8a99c6a0257b9d3d93162f9b2fff552b0..7483f9f2639c58a4f43e264211791f4377e1db64 100644 index 51c52aeb3724c919443b7f5aa574d64983b57c49..a76b53c6f0640f2d3c73ee48d584ce747e010776 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1590,7 +1590,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1584,7 +1584,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
// Paper end - Configurable entity tracking range by Y // Paper end - Configurable entity tracking range by Y
// CraftBukkit start - respect vanish API // CraftBukkit start - respect vanish API

View file

@ -18,10 +18,10 @@ index a043ac10834562d357ef0b5aded2e916e2a0d056..74276c368016fcc4dbf9579b2ecbadc9
@VisibleForTesting @VisibleForTesting
static long encode(double value) { static long encode(double value) {
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 7483f9f2639c58a4f43e264211791f4377e1db64..7317c353edab8b11d9d94e257f968ac49284f47a 100644 index a76b53c6f0640f2d3c73ee48d584ce747e010776..16e55cc94c8f6e204e4b7ab6ad8d32a6c443357f 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1572,10 +1572,14 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1566,10 +1566,14 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
public void updatePlayer(ServerPlayer player) { public void updatePlayer(ServerPlayer player) {
org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot
if (player != this.entity) { if (player != this.entity) {

View file

@ -18,7 +18,7 @@ Currently includes:
See https://github.com/Tuinity/Moonrise See https://github.com/Tuinity/Moonrise
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java
index 49fe9eed5d5d08abd6e9778fe0d0545f35552435..fc029c8fb22a7c8eeb23bfc171812f6da91c60fa 100644 index f7cd0aa43d0b9249d0a317fab41fefa0d951bca0..fc029c8fb22a7c8eeb23bfc171812f6da91c60fa 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java --- a/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java
@@ -2,11 +2,17 @@ package ca.spottedleaf.moonrise.common.util; @@ -2,11 +2,17 @@ package ca.spottedleaf.moonrise.common.util;
@ -330,16 +330,16 @@ index 49fe9eed5d5d08abd6e9778fe0d0545f35552435..fc029c8fb22a7c8eeb23bfc171812f6d
} }
public static int getSendViewDistance(final ServerPlayer player) { public static int getSendViewDistance(final ServerPlayer player) {
- return getLoadViewDistance(player); - return getLoadViewDistance(player) - 1;
+ return RegionizedPlayerChunkLoader.getAPISendViewDistance(player); + return RegionizedPlayerChunkLoader.getAPISendViewDistance(player);
} }
public static int getLoadViewDistance(final ServerPlayer player) { public static int getLoadViewDistance(final ServerPlayer player) {
- final ServerLevel level = player.serverLevel(); - final ServerLevel level = player.serverLevel();
- if (level == null) { - if (level == null) {
- return org.bukkit.Bukkit.getViewDistance(); - return org.bukkit.Bukkit.getViewDistance() + 1;
- } - }
- return level.chunkSource.chunkMap.getPlayerViewDistance(player); - return level.chunkSource.chunkMap.serverViewDistance + 1;
+ return RegionizedPlayerChunkLoader.getLoadViewDistance(player); + return RegionizedPlayerChunkLoader.getLoadViewDistance(player);
} }
@ -24172,7 +24172,7 @@ index d9ad32acdf46a43a649334a3b736aeb7b3af21d1..fae17a075d7efaf24d916877dd5968eb
public static final int RADIUS_AROUND_FULL_CHUNK = FULL_CHUNK_STEP.accumulatedDependencies().getRadius(); public static final int RADIUS_AROUND_FULL_CHUNK = FULL_CHUNK_STEP.accumulatedDependencies().getRadius();
public static final int MAX_LEVEL = 33 + RADIUS_AROUND_FULL_CHUNK; public static final int MAX_LEVEL = 33 + RADIUS_AROUND_FULL_CHUNK;
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88af3ac389 100644 index 16e55cc94c8f6e204e4b7ab6ad8d32a6c443357f..80bbf77454ff34505196998bcfeaa3e40a4f639c 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -108,7 +108,7 @@ import org.slf4j.Logger; @@ -108,7 +108,7 @@ import org.slf4j.Logger;
@ -25028,9 +25028,9 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
// Spigot end // Spigot end
} }
@@ -1102,16 +688,20 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1096,16 +682,20 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
//double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; // Paper - use from event private boolean anyPlayerCloseEnoughForSpawningInternal(ChunkPos chunkcoordintpair, boolean reducedRange) {
double blockRange = 16384.0D; // Paper double blockRange; // Paper - use from event
// Spigot end // Spigot end
- Iterator iterator = this.playerMap.getAllPlayers().iterator(); - Iterator iterator = this.playerMap.getAllPlayers().iterator();
- -
@ -25057,7 +25057,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
// Paper start - PlayerNaturallySpawnCreaturesEvent // Paper start - PlayerNaturallySpawnCreaturesEvent
com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event; com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event;
blockRange = 16384.0D; blockRange = 16384.0D;
@@ -1121,33 +711,47 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1115,33 +705,47 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
blockRange = (double) ((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4)); blockRange = (double) ((event.getSpawnRadius() << 4) * (event.getSpawnRadius() << 4));
} }
// Paper end - PlayerNaturallySpawnCreaturesEvent // Paper end - PlayerNaturallySpawnCreaturesEvent
@ -25120,7 +25120,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
if (entityplayer.isSpectator()) { if (entityplayer.isSpectator()) {
return false; return false;
} else { } else {
@@ -1170,19 +774,21 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1164,19 +768,21 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
this.updatePlayerPos(player); this.updatePlayerPos(player);
if (!flag1) { if (!flag1) {
this.distanceManager.addPlayer(SectionPos.of((EntityAccess) player), player); this.distanceManager.addPlayer(SectionPos.of((EntityAccess) player), player);
@ -25144,7 +25144,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
} }
} }
@@ -1194,17 +800,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1188,17 +794,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
} }
public void move(ServerPlayer player) { public void move(ServerPlayer player) {
@ -25163,7 +25163,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
SectionPos sectionposition = player.getLastSectionPos(); SectionPos sectionposition = player.getLastSectionPos();
SectionPos sectionposition1 = SectionPos.of((EntityAccess) player); SectionPos sectionposition1 = SectionPos.of((EntityAccess) player);
@@ -1214,6 +810,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1208,6 +804,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
if (flag2 || flag != flag1) { if (flag2 || flag != flag1) {
this.updatePlayerPos(player); this.updatePlayerPos(player);
@ -25171,7 +25171,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
if (!flag) { if (!flag) {
this.distanceManager.removePlayer(sectionposition, player); this.distanceManager.removePlayer(sectionposition, player);
} }
@@ -1230,70 +827,30 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1224,70 +821,30 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
this.playerMap.unIgnorePlayer(player); this.playerMap.unIgnorePlayer(player);
} }
@ -25253,7 +25253,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
} }
public void addEntity(Entity entity) { public void addEntity(Entity entity) {
@@ -1320,6 +877,12 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1314,6 +871,12 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
ChunkMap.TrackedEntity playerchunkmap_entitytracker = new ChunkMap.TrackedEntity(entity, i, j, entitytypes.trackDeltas()); ChunkMap.TrackedEntity playerchunkmap_entitytracker = new ChunkMap.TrackedEntity(entity, i, j, entitytypes.trackDeltas());
this.entityMap.put(entity.getId(), playerchunkmap_entitytracker); this.entityMap.put(entity.getId(), playerchunkmap_entitytracker);
@ -25266,7 +25266,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
playerchunkmap_entitytracker.updatePlayers(this.level.players()); playerchunkmap_entitytracker.updatePlayers(this.level.players());
if (entity instanceof ServerPlayer) { if (entity instanceof ServerPlayer) {
ServerPlayer entityplayer = (ServerPlayer) entity; ServerPlayer entityplayer = (ServerPlayer) entity;
@@ -1360,16 +923,38 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1354,16 +917,38 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
playerchunkmap_entitytracker1.broadcastRemoved(); playerchunkmap_entitytracker1.broadcastRemoved();
} }
@ -25310,7 +25310,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
List<ServerPlayer> list = Lists.newArrayList(); List<ServerPlayer> list = Lists.newArrayList();
List<ServerPlayer> list1 = this.level.players(); List<ServerPlayer> list1 = this.level.players();
@@ -1472,27 +1057,25 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1466,27 +1051,25 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
} }
public void waitForLightBeforeSending(ChunkPos centerPos, int radius) { public void waitForLightBeforeSending(ChunkPos centerPos, int radius) {
@ -25348,7 +25348,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
} }
@Nullable @Nullable
@@ -1508,7 +1091,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1502,7 +1085,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
} }
} }
@ -25357,7 +25357,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
public final ServerEntity serverEntity; public final ServerEntity serverEntity;
final Entity entity; final Entity entity;
@@ -1516,6 +1099,89 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1510,6 +1093,89 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
SectionPos lastSectionPos; SectionPos lastSectionPos;
public final Set<ServerPlayerConnection> seenBy = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); // Paper - Perf: optimise map impl public final Set<ServerPlayerConnection> seenBy = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(); // Paper - Perf: optimise map impl
@ -25447,7 +25447,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88
public TrackedEntity(final Entity entity, final int i, final int j, final boolean flag) { public TrackedEntity(final Entity entity, final int i, final int j, final boolean flag) {
this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, j, flag, this::broadcast, this.seenBy); // CraftBukkit this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, j, flag, this::broadcast, this.seenBy); // CraftBukkit
this.entity = entity; this.entity = entity;
@@ -1618,20 +1284,24 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1612,20 +1278,24 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
} }
private int getEffectiveRange() { private int getEffectiveRange() {
@ -26299,7 +26299,7 @@ index 65206fdfa5b94eaca139e433b4865c16b16641f3..bf4463bcb5dc439ac5a3fa08dd60845a
} }
} }
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..56a109dc832c231bf8470f46e1ff37565e9fdd7a 100644 index 6a2af3cd3aebe525a5ff41a801929547d59b8fec..b3ce572547535001959d9bcc6cb567da552c6539 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java --- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java +++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -52,7 +52,7 @@ import net.minecraft.world.level.storage.DimensionDataStorage; @@ -52,7 +52,7 @@ import net.minecraft.world.level.storage.DimensionDataStorage;
@ -26730,7 +26730,7 @@ index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..56a109dc832c231bf8470f46e1ff3756
} }
private void tickChunks(ProfilerFiller profiler, long timeDelta, List<LevelChunk> chunks) { private void tickChunks(ProfilerFiller profiler, long timeDelta, List<LevelChunk> chunks) {
@@ -509,7 +585,7 @@ public class ServerChunkCache extends ChunkSource { @@ -508,7 +584,7 @@ public class ServerChunkCache extends ChunkSource {
NaturalSpawner.spawnForChunk(this.level, chunk, spawnercreature_d, list1); NaturalSpawner.spawnForChunk(this.level, chunk, spawnercreature_d, list1);
} }
@ -26739,7 +26739,7 @@ index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..56a109dc832c231bf8470f46e1ff3756
this.level.tickChunk(chunk, k); this.level.tickChunk(chunk, k);
} }
} }
@@ -522,11 +598,13 @@ public class ServerChunkCache extends ChunkSource { @@ -521,11 +597,13 @@ public class ServerChunkCache extends ChunkSource {
} }
private void getFullChunk(long pos, Consumer<LevelChunk> chunkConsumer) { private void getFullChunk(long pos, Consumer<LevelChunk> chunkConsumer) {
@ -26757,7 +26757,7 @@ index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..56a109dc832c231bf8470f46e1ff3756
} }
@@ -620,6 +698,12 @@ public class ServerChunkCache extends ChunkSource { @@ -619,6 +697,12 @@ public class ServerChunkCache extends ChunkSource {
this.chunkMap.setServerViewDistance(watchDistance); this.chunkMap.setServerViewDistance(watchDistance);
} }
@ -26770,7 +26770,7 @@ index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..56a109dc832c231bf8470f46e1ff3756
public void setSimulationDistance(int simulationDistance) { public void setSimulationDistance(int simulationDistance) {
this.distanceManager.updateSimulationDistance(simulationDistance); this.distanceManager.updateSimulationDistance(simulationDistance);
} }
@@ -711,21 +795,19 @@ public class ServerChunkCache extends ChunkSource { @@ -710,21 +794,19 @@ public class ServerChunkCache extends ChunkSource {
@Override @Override
// CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task // CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task
public boolean pollTask() { public boolean pollTask() {

View file

@ -50,10 +50,10 @@ index f6e1deb2f849d8b01b15cfa69e2f6cd5f2b1512b..f66e40326c510aa3267542b1a24ed75d
entityTrackerEntry.getLastSentYRot(), entityTrackerEntry.getLastSentYRot(),
entity.getType(), entity.getType(),
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index cb3850939955ae068d4776c835522e0b8f228984..f1999729cd1c00071c5e1835ee49ea5fcafa7b05 100644 index 80bbf77454ff34505196998bcfeaa3e40a4f639c..674fbb35d372a67c21453a8c63c3628c563ccef7 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java --- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1271,6 +1271,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider @@ -1265,6 +1265,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
this.serverEntity.addPairing(player); this.serverEntity.addPairing(player);
} }
// Paper end - entity tracking events // Paper end - entity tracking events