From 35a3522b4e4045b833d6485bf1ca985976910ca1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 19 Apr 2021 00:30:34 +0100 Subject: [PATCH] Player: fixed chunks getting spammed like crazy during generation because of the shitty way that the chunk resending is handled, it causes all kinds of problems with the async system because of potential reversions of the state during the process. --- src/player/Player.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/player/Player.php b/src/player/Player.php index bffee7087..2350c3863 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -733,6 +733,13 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ if(!$this->isConnected() || !isset($this->usedChunks[$index]) || $world !== $this->getWorld()){ return; } + if(!$this->usedChunks[$index]->equals(UsedChunkStatus::NEEDED())){ + //TODO: make this an error + //we may have added multiple completion handlers, since the Player keeps re-requesting chunks + //it doesn't have yet (a relic from the old system, but also currently relied on for chunk resends). + //in this event, make sure we don't try to send the chunk multiple times. + return; + } unset($this->loadQueue[$index]); $this->usedChunks[$index] = UsedChunkStatus::REQUESTED(); @@ -741,6 +748,13 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $this->logger->debug("Tried to send no-longer-active chunk $X $Z in world " . $world->getFolderName()); return; } + if(!$this->usedChunks[$index]->equals(UsedChunkStatus::REQUESTED())){ + //TODO: make this an error + //this could be triggered due to the shitty way that chunk resends are handled + //right now - not because of the spammy re-requesting, but because the chunk status reverts + //to NEEDED if they want to be resent. + return; + } $this->usedChunks[$index] = UsedChunkStatus::SENT(); if($this->spawnChunkLoadCount === -1){ $this->spawnEntitiesOnChunk($X, $Z);