Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8f940f2

Browse files
committedApr 18, 2021
Fixed precondition on double chunk send being useless
this is messy, but necessary for now.
1 parent d19c21e commit 8f940f2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed
 

‎src/network/mcpe/NetworkSession.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
use pocketmine\player\GameMode;
103103
use pocketmine\player\Player;
104104
use pocketmine\player\PlayerInfo;
105+
use pocketmine\player\UsedChunkStatus;
105106
use pocketmine\player\XboxLivePlayerInfo;
106107
use pocketmine\Server;
107108
use pocketmine\timings\Timings;
@@ -919,10 +920,17 @@ function(CompressBatchPromise $promise) use ($world, $onCompletion, $chunkX, $ch
919920
return;
920921
}
921922
$currentWorld = $this->player->getLocation()->getWorld();
922-
if($world !== $currentWorld or !$this->player->isUsingChunk($chunkX, $chunkZ)){
923+
if($world !== $currentWorld or ($status = $this->player->getUsedChunkStatus($chunkX, $chunkZ)) === null){
923924
$this->logger->debug("Tried to send no-longer-active chunk $chunkX $chunkZ in world " . $world->getFolderName());
924925
return;
925926
}
927+
if(!$status->equals(UsedChunkStatus::REQUESTED())){
928+
//TODO: make this an error
929+
//this could be triggered due to the shitty way that chunk resends are handled
930+
//right now - not because of the spammy re-requesting, but because the chunk status reverts
931+
//to NEEDED if they want to be resent.
932+
return;
933+
}
926934
$world->timings->syncChunkSend->startTiming();
927935
try{
928936
$this->queueCompressed($promise);

‎src/player/Player.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,6 @@ function() use ($X, $Z, $index, $world) : void{
744744
$this->usedChunks[$index] = UsedChunkStatus::REQUESTED();
745745

746746
$this->getNetworkSession()->startUsingChunk($X, $Z, function() use ($X, $Z, $index) : void{
747-
if(!$this->usedChunks[$index]->equals(UsedChunkStatus::REQUESTED())){
748-
//TODO: make this an error
749-
//this could be triggered due to the shitty way that chunk resends are handled
750-
//right now - not because of the spammy re-requesting, but because the chunk status reverts
751-
//to NEEDED if they want to be resent.
752-
return;
753-
}
754747
$this->usedChunks[$index] = UsedChunkStatus::SENT();
755748
if($this->spawnChunkLoadCount === -1){
756749
$this->spawnEntitiesOnChunk($X, $Z);
@@ -876,6 +869,13 @@ public function getUsedChunks() : array{
876869
return $this->usedChunks;
877870
}
878871

872+
/**
873+
* Returns a usage status of the given chunk, or null if the player is not using the given chunk.
874+
*/
875+
public function getUsedChunkStatus(int $chunkX, int $chunkZ) : ?UsedChunkStatus{
876+
return $this->usedChunks[World::chunkHash($chunkX, $chunkZ)] ?? null;
877+
}
878+
879879
/**
880880
* Returns whether the target chunk has been sent to this player.
881881
*/

0 commit comments

Comments
 (0)
Please sign in to comment.