示例#1
0
 /**
  * @param Vector3 $pos
  * @param int     $delay
  */
 public function scheduleUpdate(Vector3 $pos, $delay)
 {
     if (isset($this->updateQueueIndex[$index = PHP_INT_SIZE === 8 ? ($pos->x & 0xfffffff) << 35 | ($pos->y & 0x7f) << 28 | $pos->z & 0xfffffff : $pos->x . ":" . $pos->y . ":" . $pos->z]) and $this->updateQueueIndex[$index] <= $delay) {
         return;
     }
     $this->updateQueueIndex[$index] = $delay;
     $this->updateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick());
 }
示例#2
0
 /**
  * @param Vector3 $pos
  * @param int     $delay
  */
 public function scheduleUpdate(Vector3 $pos, $delay)
 {
     $this->updateQueue->insert($pos, (int) $delay);
 }
示例#3
0
 /**
  * @param Vector3 $pos
  * @param int     $delay
  */
 public function scheduleUpdate(Vector3 $pos, $delay)
 {
     if (isset($this->updateQueueIndex[$index = Level::blockHash($pos->x, $pos->y, $pos->z)]) and $this->updateQueueIndex[$index] <= $delay) {
         return;
     }
     $this->updateQueueIndex[$index] = $delay;
     $this->updateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick());
 }
示例#4
0
 /**
  *
  * WARNING: Do not use this, it's only for internal use.
  * Changes to this function won't be recorded on the version.
  *
  * @return bool
  */
 public function orderChunks()
 {
     if ($this->connected === false) {
         return false;
     }
     $radiusSquared = $this->viewDistance / M_PI;
     $radius = ceil(sqrt($radiusSquared));
     $newOrder = [];
     $lastChunk = $this->usedChunks;
     $centerX = $this->x >> 4;
     $centerZ = $this->z >> 4;
     $generateQueue = new ReversePriorityQueue();
     for ($X = -$radius; $X <= $radius; ++$X) {
         for ($Z = -$radius; $Z <= $radius; ++$Z) {
             $distance = $X * $X + $Z * $Z;
             if ($distance > $radiusSquared) {
                 continue;
             }
             $chunkX = $X + $centerX;
             $chunkZ = $Z + $centerZ;
             $index = Level::chunkHash($chunkX, $chunkZ);
             if (!isset($this->usedChunks[$index])) {
                 if ($this->level->isChunkPopulated($chunkX, $chunkZ)) {
                     $newOrder[$index] = $distance;
                 } else {
                     $generateQueue->insert([$chunkX, $chunkZ], $distance);
                 }
             }
             unset($lastChunk[$index]);
         }
     }
     asort($newOrder);
     if (count($newOrder) > $this->viewDistance) {
         $count = 0;
         $this->loadQueue = [];
         foreach ($newOrder as $k => $distance) {
             $this->loadQueue[$k] = $distance;
             if (++$count > $this->viewDistance) {
                 break;
             }
         }
     } else {
         $this->loadQueue = $newOrder;
     }
     $i = 0;
     while (count($this->loadQueue) < 3 and $generateQueue->count() > 0 and $i < 16) {
         $d = $generateQueue->extract();
         $this->getLevel()->generateChunk($d[0], $d[1]);
         ++$i;
     }
     foreach ($lastChunk as $index => $Yndex) {
         $X = null;
         $Z = null;
         Level::getXZ($index, $X, $Z);
         foreach ($this->getLevel()->getChunkEntities($X, $Z) as $entity) {
             if ($entity !== $this) {
                 $entity->despawnFrom($this);
             }
         }
         unset($this->usedChunks[$index]);
     }
 }