Level: fixed setChunk() bug introduced by eebd90ec4245abbcdddfc11fe3f4dc36a008f19e

Anyone who is using getChunkPlayers() should probably check that their code is actually doing what they think it's doing.
This commit is contained in:
Dylan K. Taylor 2019-01-31 18:28:42 +00:00
parent ddbb5363ef
commit 5fe1d2e396

View File

@ -616,7 +616,10 @@ class Level implements ChunkManager, Metadatable{
}
/**
* Gets the players being used in a specific chunk
* @deprecated WARNING: This function has a misleading name. Contrary to what the name might imply, this function
* DOES NOT return players who are IN a chunk, rather, it returns players who can SEE the chunk.
*
* Returns a list of players who have the target chunk within their view distance.
*
* @param int $chunkX
* @param int $chunkZ
@ -2490,8 +2493,10 @@ class Level implements ChunkManager, Metadatable{
$oldChunk = $this->getChunk($chunkX, $chunkZ, false);
if($oldChunk !== null and $oldChunk !== $chunk){
if($deleteEntitiesAndTiles){
$players = $this->getChunkPlayers($chunkX, $chunkZ);
foreach($players as $player){
foreach($oldChunk->getEntities() as $player){
if(!($player instanceof Player)){
continue;
}
$chunk->addEntity($player);
$oldChunk->removeEntity($player);
$player->chunk = $chunk;