From 0cc7bd485760dd0abd387f64d193ffef7aa019ee Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Thu, 28 Nov 2024 14:22:32 -0800 Subject: [PATCH] Use Player view distance for PlayerNaturallySpawnCreaturesEvent The spigot view distance may not be correct, as the player may have a specific view distance configured. --- patches/server/0009-MC-Utils.patch | 10 ++-- ...4-PlayerNaturallySpawnCreaturesEvent.patch | 29 +++++------ .../0306-Tracking-Range-Improvements.patch | 4 +- ...-PlayerChunkMap-adds-crashing-server.patch | 4 +- ...nEvent-when-Player-is-actually-ready.patch | 8 ++-- ...primise-map-impl-for-tracked-players.patch | 4 +- .../0766-Player-Entity-Tracking-Events.patch | 4 +- ...ntity-tracking-range-by-Y-coordinate.patch | 4 +- ...k-if-we-can-see-non-visible-entities.patch | 4 +- ...llocation-of-Vec3D-by-entity-tracker.patch | 4 +- .../1038-Moonrise-optimisation-patches.patch | 48 +++++++++---------- ...er-desync-when-new-players-are-added.patch | 4 +- 12 files changed, 64 insertions(+), 63 deletions(-) diff --git a/patches/server/0009-MC-Utils.patch b/patches/server/0009-MC-Utils.patch index efbef79a1b..2bea8ec9a7 100644 --- a/patches/server/0009-MC-Utils.patch +++ b/patches/server/0009-MC-Utils.patch @@ -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 new file mode 100644 -index 0000000000000000000000000000000000000000..49fe9eed5d5d08abd6e9778fe0d0545f35552435 +index 0000000000000000000000000000000000000000..f7cd0aa43d0b9249d0a317fab41fefa0d951bca0 --- /dev/null +++ b/src/main/java/ca/spottedleaf/moonrise/common/util/ChunkSystem.java @@ -0,0 +1,288 @@ @@ -3582,15 +3582,15 @@ index 0000000000000000000000000000000000000000..49fe9eed5d5d08abd6e9778fe0d0545f + } + + public static int getSendViewDistance(final ServerPlayer player) { -+ return getLoadViewDistance(player); ++ return getLoadViewDistance(player) - 1; + } + + public static int getLoadViewDistance(final ServerPlayer player) { + final ServerLevel level = player.serverLevel(); + 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) { @@ -4695,7 +4695,7 @@ index 46cab7a8c7b87ab01b26074b04f5a02b3907cfc4..49019b4a9bc4e634d54a9b0acaf9229a + // Paper end } 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 +++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java @@ -215,7 +215,7 @@ public class GlobalConfiguration extends ConfigurationPart { diff --git a/patches/server/0164-PlayerNaturallySpawnCreaturesEvent.patch b/patches/server/0164-PlayerNaturallySpawnCreaturesEvent.patch index 182a62cf0d..cb145ad224 100644 --- a/patches/server/0164-PlayerNaturallySpawnCreaturesEvent.patch +++ b/patches/server/0164-PlayerNaturallySpawnCreaturesEvent.patch @@ -9,21 +9,23 @@ from triggering monster spawns on a server. 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 -index 261943f1f188643793a72bd239dfc5fe604e3b99..985ba48a5ac027d3c3dcd9b710b53748508966fb 100644 +index 261943f1f188643793a72bd239dfc5fe604e3b99..ebe6c631d772cf41038701aafbe4e0bbb024f7f5 100644 --- a/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 - chunkRange = (chunkRange > this.level.spigotConfig.viewDistance) ? (byte) this.level.spigotConfig.viewDistance : chunkRange; - chunkRange = (chunkRange > 8) ? 8 : chunkRange; +@@ -1094,11 +1094,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider + } + 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; -+ final int finalChunkRange = chunkRange; // Paper for lambda below -+ //double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; // Paper - use from event -+ double blockRange = 16384.0D; // Paper ++ double blockRange; // Paper - use from event // Spigot end 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(); @@ -40,18 +42,17 @@ index 261943f1f188643793a72bd239dfc5fe604e3b99..985ba48a5ac027d3c3dcd9b710b53748 return true; 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 +++ 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; if (flag && (this.spawnEnemies || this.spawnFriendlies)) { + // 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()) { ++ 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.callEvent(); + } @@ -60,7 +61,7 @@ index 2e2976efcf99de269f67dec2c87cb910ff280562..5749698b0c9647295e0be6f7d532d39c 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 -index b99bd43bf5185bed21fad7dac31baf1a30bdd1fe..98aeafcc51e23a7534c8d57e4db0eb58abb3f30b 100644 +index 0432304139fada99dff884ebf8d08dbf9afc45c7..8fd3802d8e293e35478666bd4e921d58e1ce5b41 100644 --- a/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 { diff --git a/patches/server/0306-Tracking-Range-Improvements.patch b/patches/server/0306-Tracking-Range-Improvements.patch index c22d82fbf9..3377d904f2 100644 --- a/patches/server/0306-Tracking-Range-Improvements.patch +++ b/patches/server/0306-Tracking-Range-Improvements.patch @@ -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 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 +++ 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()) { Entity entity = (Entity) iterator.next(); int j = entity.getType().clientTrackingRange() * 16; diff --git a/patches/server/0328-Prevent-Double-PlayerChunkMap-adds-crashing-server.patch b/patches/server/0328-Prevent-Double-PlayerChunkMap-adds-crashing-server.patch index e37145e970..f9e919de80 100644 --- a/patches/server/0328-Prevent-Double-PlayerChunkMap-adds-crashing-server.patch +++ b/patches/server/0328-Prevent-Double-PlayerChunkMap-adds-crashing-server.patch @@ -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. 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 +++ 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) { org.spigotmc.AsyncCatcher.catchOp("entity track"); // Spigot diff --git a/patches/server/0339-Fire-PlayerJoinEvent-when-Player-is-actually-ready.patch b/patches/server/0339-Fire-PlayerJoinEvent-when-Player-is-actually-ready.patch index 463ceefd14..1196295511 100644 --- a/patches/server/0339-Fire-PlayerJoinEvent-when-Player-is-actually-ready.patch +++ b/patches/server/0339-Fire-PlayerJoinEvent-when-Player-is-actually-ready.patch @@ -31,10 +31,10 @@ delays anymore. 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 -index 396310a51480cf0d1ea4c0959d3f8e4ed77b99e3..0f8fc275af95750871aa6917aa12053f75c112f7 100644 +index 48e848e407e4e78e05c35a5cb2393bccc6de3a4f..2a216485522a63298e239074ef5bdfa1101fa9d6 100644 --- a/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; } // Paper end - ignore and warn about illegal addEntity calls instead of crashing server @@ -43,7 +43,7 @@ index 396310a51480cf0d1ea4c0959d3f8e4ed77b99e3..0f8fc275af95750871aa6917aa12053f EntityType entitytypes = entity.getType(); 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 -index 9911e231ad021286f2da90057b06874f7b4e3b4d..807068fc6065f71961d34cb4f18b6eb39ae49637 100644 +index eebf44c7124c4f48b6d48562a00633b1e8ff9b00..8c80a852ed00c2bf79bb68da9d535af425893deb 100644 --- a/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 { @@ -55,7 +55,7 @@ index 9911e231ad021286f2da90057b06874f7b4e3b4d..807068fc6065f71961d34cb4f18b6eb3 // CraftBukkit end 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 -index ad4f5a4e00b9b517841acd0b4ff5088e45451bf4..4ff14dc6996634b0fcd365f76055023601ad2be0 100644 +index e137278f9dc02eefaaf7071a3219436a94cfcfac..ac5725230b04bc1a333863e251fe86580f909ea9 100644 --- a/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 { diff --git a/patches/server/0600-Oprimise-map-impl-for-tracked-players.patch b/patches/server/0600-Oprimise-map-impl-for-tracked-players.patch index 286a4f8c94..ba86306e1b 100644 --- a/patches/server/0600-Oprimise-map-impl-for-tracked-players.patch +++ b/patches/server/0600-Oprimise-map-impl-for-tracked-players.patch @@ -7,10 +7,10 @@ Reference2BooleanOpenHashMap is going to have 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 -index 0f8fc275af95750871aa6917aa12053f75c112f7..51a6735b35e73175680e61c2d67d4adbedf305c9 100644 +index 2a216485522a63298e239074ef5bdfa1101fa9d6..fde03e0e5cd42339e5bfbeb60670139af5f56e1c 100644 --- a/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; private final int range; SectionPos lastSectionPos; diff --git a/patches/server/0766-Player-Entity-Tracking-Events.patch b/patches/server/0766-Player-Entity-Tracking-Events.patch index 49ee909e24..8a601a81f2 100644 --- a/patches/server/0766-Player-Entity-Tracking-Events.patch +++ b/patches/server/0766-Player-Entity-Tracking-Events.patch @@ -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 -index 51a6735b35e73175680e61c2d67d4adbedf305c9..8b5d11aceb77135c917c3581f4db792ef4b647ec 100644 +index fde03e0e5cd42339e5bfbeb60670139af5f56e1c..bf88c5de30e6cde87099dab546e5d1bd817134a2 100644 --- a/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 if (flag) { if (this.seenBy.add(player.connection)) { diff --git a/patches/server/0852-Configurable-entity-tracking-range-by-Y-coordinate.patch b/patches/server/0852-Configurable-entity-tracking-range-by-Y-coordinate.patch index feb7011cca..89e48222c8 100644 --- a/patches/server/0852-Configurable-entity-tracking-range-by-Y-coordinate.patch +++ b/patches/server/0852-Configurable-entity-tracking-range-by-Y-coordinate.patch @@ -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. 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 +++ 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 d1 = vec3d.x * vec3d.x + vec3d.z * vec3d.z; double d2 = d0 * d0; diff --git a/patches/server/0884-Don-t-check-if-we-can-see-non-visible-entities.patch b/patches/server/0884-Don-t-check-if-we-can-see-non-visible-entities.patch index 5a591c2450..0160bd3b03 100644 --- a/patches/server/0884-Don-t-check-if-we-can-see-non-visible-entities.patch +++ b/patches/server/0884-Don-t-check-if-we-can-see-non-visible-entities.patch @@ -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 -index 5b993cb8a99c6a0257b9d3d93162f9b2fff552b0..7483f9f2639c58a4f43e264211791f4377e1db64 100644 +index 51c52aeb3724c919443b7f5aa574d64983b57c49..a76b53c6f0640f2d3c73ee48d584ce747e010776 100644 --- a/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 // CraftBukkit start - respect vanish API diff --git a/patches/server/0913-Reduce-allocation-of-Vec3D-by-entity-tracker.patch b/patches/server/0913-Reduce-allocation-of-Vec3D-by-entity-tracker.patch index c1b9e8e12b..e5b83e9d8d 100644 --- a/patches/server/0913-Reduce-allocation-of-Vec3D-by-entity-tracker.patch +++ b/patches/server/0913-Reduce-allocation-of-Vec3D-by-entity-tracker.patch @@ -18,10 +18,10 @@ index a043ac10834562d357ef0b5aded2e916e2a0d056..74276c368016fcc4dbf9579b2ecbadc9 @VisibleForTesting 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 -index 7483f9f2639c58a4f43e264211791f4377e1db64..7317c353edab8b11d9d94e257f968ac49284f47a 100644 +index a76b53c6f0640f2d3c73ee48d584ce747e010776..16e55cc94c8f6e204e4b7ab6ad8d32a6c443357f 100644 --- a/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) { org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot if (player != this.entity) { diff --git a/patches/server/1038-Moonrise-optimisation-patches.patch b/patches/server/1038-Moonrise-optimisation-patches.patch index da2851b944..993b277e65 100644 --- a/patches/server/1038-Moonrise-optimisation-patches.patch +++ b/patches/server/1038-Moonrise-optimisation-patches.patch @@ -18,7 +18,7 @@ Currently includes: 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 -index 49fe9eed5d5d08abd6e9778fe0d0545f35552435..fc029c8fb22a7c8eeb23bfc171812f6da91c60fa 100644 +index f7cd0aa43d0b9249d0a317fab41fefa0d951bca0..fc029c8fb22a7c8eeb23bfc171812f6da91c60fa 100644 --- a/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; @@ -330,16 +330,16 @@ index 49fe9eed5d5d08abd6e9778fe0d0545f35552435..fc029c8fb22a7c8eeb23bfc171812f6d } public static int getSendViewDistance(final ServerPlayer player) { -- return getLoadViewDistance(player); +- return getLoadViewDistance(player) - 1; + return RegionizedPlayerChunkLoader.getAPISendViewDistance(player); } public static int getLoadViewDistance(final ServerPlayer player) { - final ServerLevel level = player.serverLevel(); - 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); } @@ -24172,7 +24172,7 @@ index d9ad32acdf46a43a649334a3b736aeb7b3af21d1..fae17a075d7efaf24d916877dd5968eb public static final int RADIUS_AROUND_FULL_CHUNK = FULL_CHUNK_STEP.accumulatedDependencies().getRadius(); 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 -index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88af3ac389 100644 +index 16e55cc94c8f6e204e4b7ab6ad8d32a6c443357f..80bbf77454ff34505196998bcfeaa3e40a4f639c 100644 --- a/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; @@ -25028,9 +25028,9 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88 // Spigot end } -@@ -1102,16 +688,20 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider - //double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D; // Paper - use from event - double blockRange = 16384.0D; // Paper +@@ -1096,16 +682,20 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider + private boolean anyPlayerCloseEnoughForSpawningInternal(ChunkPos chunkcoordintpair, boolean reducedRange) { + double blockRange; // Paper - use from event // Spigot end - Iterator iterator = this.playerMap.getAllPlayers().iterator(); - @@ -25057,7 +25057,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88 // Paper start - PlayerNaturallySpawnCreaturesEvent com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent event; 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)); } // Paper end - PlayerNaturallySpawnCreaturesEvent @@ -25120,7 +25120,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88 if (entityplayer.isSpectator()) { return false; } 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); if (!flag1) { 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) { @@ -25163,7 +25163,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88 SectionPos sectionposition = player.getLastSectionPos(); 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) { this.updatePlayerPos(player); @@ -25171,7 +25171,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88 if (!flag) { 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); } @@ -25253,7 +25253,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88 } 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()); this.entityMap.put(entity.getId(), playerchunkmap_entitytracker); @@ -25266,7 +25266,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88 playerchunkmap_entitytracker.updatePlayers(this.level.players()); if (entity instanceof ServerPlayer) { 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(); } @@ -25310,7 +25310,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88 List list = Lists.newArrayList(); List 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) { @@ -25348,7 +25348,7 @@ index 7317c353edab8b11d9d94e257f968ac49284f47a..c185f634b962c40047696ec0df50eb88 } @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; 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; public final Set 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) { this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, j, flag, this::broadcast, this.seenBy); // CraftBukkit 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() { @@ -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 -index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..56a109dc832c231bf8470f46e1ff37565e9fdd7a 100644 +index 6a2af3cd3aebe525a5ff41a801929547d59b8fec..b3ce572547535001959d9bcc6cb567da552c6539 100644 --- a/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; @@ -26730,7 +26730,7 @@ index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..56a109dc832c231bf8470f46e1ff3756 } private void tickChunks(ProfilerFiller profiler, long timeDelta, List 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); } @@ -26739,7 +26739,7 @@ index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..56a109dc832c231bf8470f46e1ff3756 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 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); } @@ -26770,7 +26770,7 @@ index 0a895055ec7f61d3cb52d303bbe3f89486a322e7..56a109dc832c231bf8470f46e1ff3756 public void setSimulationDistance(int simulationDistance) { this.distanceManager.updateSimulationDistance(simulationDistance); } -@@ -711,21 +795,19 @@ public class ServerChunkCache extends ChunkSource { +@@ -710,21 +794,19 @@ public class ServerChunkCache extends ChunkSource { @Override // CraftBukkit start - process pending Chunk loadCallback() and unloadCallback() after each run task public boolean pollTask() { diff --git a/patches/server/1050-Fix-entity-tracker-desync-when-new-players-are-added.patch b/patches/server/1050-Fix-entity-tracker-desync-when-new-players-are-added.patch index d8a7d54cb0..9737c35436 100644 --- a/patches/server/1050-Fix-entity-tracker-desync-when-new-players-are-added.patch +++ b/patches/server/1050-Fix-entity-tracker-desync-when-new-players-are-added.patch @@ -50,10 +50,10 @@ index f6e1deb2f849d8b01b15cfa69e2f6cd5f2b1512b..f66e40326c510aa3267542b1a24ed75d entityTrackerEntry.getLastSentYRot(), entity.getType(), 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 +++ 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); } // Paper end - entity tracking events