mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-25 20:33:59 +00:00
Player: make selectChunks() non-dependent on the player's current view distance & location
This commit is contained in:
parent
63d622a3cc
commit
81d11ea4e3
@ -848,13 +848,9 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
/**
|
/**
|
||||||
* @return \Generator<int, int, void, void>
|
* @return \Generator<int, int, void, void>
|
||||||
*/
|
*/
|
||||||
protected function selectChunks() : \Generator{
|
protected function selectChunks(int $radius, int $centerX, int $centerZ) : \Generator{
|
||||||
$radius = $this->server->getAllowedViewDistance($this->viewDistance);
|
|
||||||
$radiusSquared = $radius ** 2;
|
$radiusSquared = $radius ** 2;
|
||||||
|
|
||||||
$centerX = $this->location->getFloorX() >> 4;
|
|
||||||
$centerZ = $this->location->getFloorZ() >> 4;
|
|
||||||
|
|
||||||
for($x = 0; $x < $radius; ++$x){
|
for($x = 0; $x < $radius; ++$x){
|
||||||
for($z = 0; $z <= $x; ++$z){
|
for($z = 0; $z <= $x; ++$z){
|
||||||
if(($x ** 2 + $z ** 2) > $radiusSquared){
|
if(($x ** 2 + $z ** 2) > $radiusSquared){
|
||||||
@ -896,7 +892,11 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
$newOrder = [];
|
$newOrder = [];
|
||||||
$unloadChunks = $this->usedChunks;
|
$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())){
|
if(!isset($this->usedChunks[$hash]) or $this->usedChunks[$hash]->equals(UsedChunkStatus::NEEDED())){
|
||||||
$newOrder[$hash] = true;
|
$newOrder[$hash] = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user