Player: make selectChunks() non-dependent on the player's current view distance & location

This commit is contained in:
Dylan K. Taylor 2020-05-24 18:59:43 +01:00
parent 63d622a3cc
commit 81d11ea4e3

View File

@ -848,13 +848,9 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
/**
* @return \Generator<int, int, void, void>
*/
protected function selectChunks() : \Generator{
$radius = $this->server->getAllowedViewDistance($this->viewDistance);
protected function selectChunks(int $radius, int $centerX, int $centerZ) : \Generator{
$radiusSquared = $radius ** 2;
$centerX = $this->location->getFloorX() >> 4;
$centerZ = $this->location->getFloorZ() >> 4;
for($x = 0; $x < $radius; ++$x){
for($z = 0; $z <= $x; ++$z){
if(($x ** 2 + $z ** 2) > $radiusSquared){
@ -896,7 +892,11 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$newOrder = [];
$unloadChunks = $this->usedChunks;
foreach($this->selectChunks() as $hash){
foreach($this->selectChunks(
$this->server->getAllowedViewDistance($this->viewDistance),
$this->location->getFloorX() >> 4,
$this->location->getFloorZ() >> 4
) as $hash){
if(!isset($this->usedChunks[$hash]) or $this->usedChunks[$hash]->equals(UsedChunkStatus::NEEDED())){
$newOrder[$hash] = true;
}