Entity: do not spawn to players who haven't received the target chunk yet, closes #3355

this might cause some delays on chunk resend as documented on master, but entities all get respawned on a resend, so this doesn't matter much. It's better than whatever side effects might come with spawning an entity in a chunk that the player doesn't have yet.
This commit is contained in:
Dylan K. Taylor 2020-05-14 00:46:54 +01:00
parent 2eb62c85f6
commit 59445902b8

View File

@ -1931,7 +1931,12 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
public function spawnTo(Player $player) : void{
if(!isset($this->hasSpawned[$player->getLoaderId()]) and $this->chunk !== null and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){
if(
!isset($this->hasSpawned[$player->getLoaderId()]) and
$this->chunk !== null and
isset($player->usedChunks[$chunkHash = Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())]) and
$player->usedChunks[$chunkHash] === true
){
$this->hasSpawned[$player->getLoaderId()] = $player;
$this->sendSpawnPacket($player);