mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
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:
parent
cb0a972b9f
commit
c8457716c4
@ -3582,15 +3582,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ 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) {
|
||||||
|
@ -330,16 +330,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25029,8 +25029,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
@@ -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
|
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();
|
||||||
-
|
-
|
||||||
|
@ -13,13 +13,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
--- 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
|
||||||
@@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
@@ -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;
|
- 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();
|
||||||
|
|
||||||
@ -48,10 +50,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
|
|
||||||
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();
|
||||||
+ }
|
+ }
|
||||||
|
Loading…
Reference in New Issue
Block a user