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 cb0a972b9f
commit c8457716c4
3 changed files with 17 additions and 16 deletions

View File

@ -3582,15 +3582,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ 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) {

View File

@ -330,16 +330,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
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);
}
@ -25029,8 +25029,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
@@ -0,0 +0,0 @@ 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
private boolean anyPlayerCloseEnoughForSpawningInternal(ChunkPos chunkcoordintpair, boolean reducedRange) {
double blockRange; // Paper - use from event
// Spigot end
- Iterator iterator = this.playerMap.getAllPlayers().iterator();
-

View File

@ -13,13 +13,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -0,0 +0,0 @@ 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;
+ 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();
@ -48,10 +50,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
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();
+ }