Inheritance: extends PlayerEvent, implements pocketmine\event\Cancellable
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $tickDiff = $currentTick - $this->lastUpdate;
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = $this->entityBaseTick($tickDiff);
     $this->age++;
     if ($this->age > 1200) {
         $this->kill();
         $this->close();
         $hasUpdate = true;
     }
     $minDistance = PHP_INT_MAX;
     $expectedPos = null;
     foreach ($this->getLevel()->getEntities() as $e) {
         if ($e instanceof Player) {
             if ($e->distance($this) <= $minDistance) {
                 $expectedPos = $e;
                 $minDistance = $e->distance($this);
             }
         }
     }
     if ($minDistance < PHP_INT_MAX) {
         $moveSpeed = 0.7;
         $motX = ($expectedPos->getX() - $this->x) / 8;
         $motY = ($expectedPos->getY() + $expectedPos->getEyeHeight() - $this->y) / 8;
         $motZ = ($expectedPos->getZ() - $this->z) / 8;
         $motSqrt = sqrt($motX * $motX + $motY * $motY + $motZ * $motZ);
         $motC = 1 - $motSqrt;
         if ($motC > 0) {
             $motC *= $motC;
             $this->motionX = $motX / $motSqrt * $motC * $moveSpeed;
             $this->motionY = $motY / $motSqrt * $motC * $moveSpeed;
             $this->motionZ = $motZ / $motSqrt * $motC * $moveSpeed;
         }
         $this->motionY -= $this->gravity;
         if ($minDistance <= 1.3) {
             if ($this->getLevel()->getServer()->expEnabled) {
                 if ($this->getExperience() > 0) {
                     $this->kill();
                     $this->close();
                     $this->getLevel()->getServer()->getPluginManager()->callEvent($ev = new PlayerPickupExpOrbEvent($expectedPos, $this->getExperience()));
                     if (!$ev->isCancelled()) {
                         $expectedPos->addExperience($this->getExperience());
                     }
                 }
             }
         }
     }
     $this->move($this->motionX, $this->motionY, $this->motionZ);
     $this->updateMovement();
     $this->timings->stopTiming();
     return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
 }
Beispiel #2
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $tickDiff = $currentTick - $this->lastUpdate;
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = $this->entityBaseTick($tickDiff);
     $this->age++;
     if ($this->age > 1200) {
         $this->kill();
         $this->close();
         $hasUpdate = true;
     }
     $minDistance = PHP_INT_MAX;
     $target = null;
     foreach ($this->getViewers() as $p) {
         if (!$p->isSpectator() and $p->isAlive()) {
             if (($dist = $p->distance($this)) < $minDistance and $dist < $this->range) {
                 $target = $p;
                 $minDistance = $dist;
             }
         }
     }
     if ($target !== null) {
         $moveSpeed = 0.7;
         $motX = ($target->getX() - $this->x) / 8;
         $motY = ($target->getY() + $target->getEyeHeight() - $this->y) / 8;
         $motZ = ($target->getZ() - $this->z) / 8;
         $motSqrt = sqrt($motX * $motX + $motY * $motY + $motZ * $motZ);
         $motC = 1 - $motSqrt;
         if ($motC > 0) {
             $motC *= $motC;
             $this->motionX = $motX / $motSqrt * $motC * $moveSpeed;
             $this->motionY = $motY / $motSqrt * $motC * $moveSpeed;
             $this->motionZ = $motZ / $motSqrt * $motC * $moveSpeed;
         }
         $this->motionY -= $this->gravity;
         if ($this->checkObstruction($this->x, $this->y, $this->z)) {
             $hasUpdate = true;
         }
         if ($this->isInsideOfSolid()) {
             $this->setPosition($target);
         }
         if ($minDistance <= 1.3) {
             if ($this->getLevel()->getServer()->expEnabled and $target->canPickupXp()) {
                 $this->getLevel()->getServer()->getPluginManager()->callEvent($ev = new PlayerPickupExpOrbEvent($target, $this->getExperience()));
                 if (!$ev->isCancelled()) {
                     $this->kill();
                     $this->close();
                     if ($this->getExperience() > 0) {
                         $this->level->addSound(new ExpPickupSound($target, mt_rand(0, 1000)));
                         $target->addXp($this->getExperience());
                         $target->resetXpCooldown();
                     }
                 }
             }
         }
     }
     $this->move($this->motionX, $this->motionY, $this->motionZ);
     $this->updateMovement();
     $this->timings->stopTiming();
     return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
 }