mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-26 00:56:39 +01:00
17f71ac87b
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 70d24eb8 SPIGOT-6587: Update documentation/error of drop chance API CraftBukkit Changes: 470050ad SPIGOT-6587: Update documentation/error of drop chance API 1c39efa3 Fix Inventory#getViewers on the player inventory not returning the player first time their inventory is opened d161627d Fix PrepareItemCraftEvent#isRepair aa1fae73 SPIGOT-6586: EntityChangeBlockEvent for falling block does not cancel properly 8a04072e SPIGOT-6583: Throwing eggs doesn't make sounds Spigot Changes: f773da84 Remove redundant patch cd367234 Rebuild patches
63 lines
3.5 KiB
Diff
63 lines
3.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Sat, 23 May 2020 17:03:41 -0400
|
|
Subject: [PATCH] Optimize sending packets to nearby locations (sounds/effects)
|
|
|
|
Instead of using the entire world or player list, use the distance
|
|
maps to only iterate players who are even seeing the chunk the packet
|
|
is originating from.
|
|
|
|
This will drastically cut down on packet sending cost for worlds with
|
|
lots of players in them.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 95f229dcb1b003215c602847a351b313fb0980ba..67c5d0a53f50896daa6bba3ac2816cfc15b0af75 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -1135,16 +1135,40 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
public void broadcast(@Nullable net.minecraft.world.entity.player.Player player, double x, double y, double z, double distance, ResourceKey<Level> worldKey, Packet<?> packet) {
|
|
- for (int i = 0; i < this.players.size(); ++i) {
|
|
- ServerPlayer entityplayer = (ServerPlayer) this.players.get(i);
|
|
+ ServerLevel world = null;
|
|
+ if (player != null && player.level instanceof ServerLevel) {
|
|
+ world = (ServerLevel) player.level;
|
|
+ }
|
|
|
|
- // CraftBukkit start - Test if player receiving packet can see the source of the packet
|
|
- if (player != null && player instanceof ServerPlayer && !entityplayer.getBukkitEntity().canSee(((ServerPlayer) player).getBukkitEntity())) {
|
|
- continue;
|
|
+ // Paper start
|
|
+ if (world == null) {
|
|
+ world = server.getLevel(worldKey);
|
|
+ }
|
|
+ net.minecraft.server.level.ChunkMap chunkMap = world != null ? world.getChunkSource().chunkMap : null;
|
|
+ Object[] backingSet;
|
|
+ if (chunkMap == null) {
|
|
+ // Really shouldn't happen...
|
|
+ backingSet = world != null ? world.players.toArray() : players.toArray();
|
|
+ } else {
|
|
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> nearbyPlayers = chunkMap.playerViewDistanceBroadcastMap.getObjectsInRange(MCUtil.fastFloor(x) >> 4, MCUtil.fastFloor(z) >> 4);
|
|
+ if (nearbyPlayers == null) {
|
|
+ return;
|
|
}
|
|
+ backingSet = nearbyPlayers.getBackingSet();
|
|
+ }
|
|
+
|
|
+ for (Object object : backingSet) {
|
|
+ if (!(object instanceof ServerPlayer)) continue;
|
|
+ ServerPlayer entityplayer = (ServerPlayer) object;
|
|
+ // Paper end
|
|
+
|
|
+ // CraftBukkit start - Test if player receiving packet can see the source of the packet
|
|
+ //if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) { // Paper
|
|
+ //continue; // Paper
|
|
+ //} // Paper
|
|
// CraftBukkit end
|
|
|
|
- if (entityplayer != player && entityplayer.level.dimension() == worldKey) {
|
|
+ if (entityplayer != player && entityplayer.level.dimension() == worldKey && (!(player instanceof ServerPlayer) || entityplayer.getBukkitEntity().canSee(((ServerPlayer) player).getBukkitEntity()))) { // Paper
|
|
double d4 = x - entityplayer.getX();
|
|
double d5 = y - entityplayer.getY();
|
|
double d6 = z - entityplayer.getZ();
|