Inheritance: extends EntityEvent, implements pocketmine\event\Cancellable
Example #1
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->age++;
     $tickDiff = $currentTick - $this->lastUpdate;
     if ($tickDiff <= 0 and !$this->justCreated) {
         return true;
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = $this->entityBaseTick($tickDiff);
     if ($this->isAlive()) {
         if ($this->pickupDelay > 0 and $this->pickupDelay < 32767) {
             //Infinite delay
             $this->pickupDelay -= $tickDiff;
             if ($this->pickupDelay < 0) {
                 $this->pickupDelay = 0;
             }
         }
         $this->motionY -= $this->gravity;
         if ($this->checkObstruction($this->x, $this->y, $this->z)) {
             $hasUpdate = true;
         }
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         $friction = 1 - $this->drag;
         if ($this->onGround and (abs($this->motionX) > 1.0E-5 or abs($this->motionZ) > 1.0E-5)) {
             $friction = $this->getLevel()->getBlock($this->temporalVector->setComponents((int) floor($this->x), (int) floor($this->y - 1), (int) floor($this->z) - 1))->getFrictionFactor() * $friction;
         }
         $this->motionX *= $friction;
         $this->motionY *= 1 - $this->drag;
         $this->motionZ *= $friction;
         if ($this->onGround) {
             $this->motionY *= -0.5;
         }
         if ($currentTick % 5 == 0) {
             $this->updateMovement();
         }
         if ($this->age > 2000) {
             $this->server->getPluginManager()->callEvent($ev = new ItemDespawnEvent($this));
             if ($ev->isCancelled()) {
                 $this->age = 0;
             } else {
                 $this->kill();
                 $hasUpdate = true;
             }
         }
     }
     $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;
 }
Example #2
0
 public function onUpdate($currentTick)
 {
     if ($this->closed !== \false) {
         return \false;
     }
     $tickDiff = \max(1, $currentTick - $this->lastUpdate);
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = $this->entityBaseTick($tickDiff);
     if (!$this->dead) {
         if ($this->pickupDelay > 0 and $this->pickupDelay < 32767) {
             //Infinite delay
             $this->pickupDelay -= $tickDiff;
         }
         $this->motionY -= $this->gravity;
         $this->keepMovement = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z);
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         $friction = 1 - $this->drag;
         if ($this->onGround and ($this->motionX != 0 or $this->motionZ != 0)) {
             $friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->getFrictionFactor() * $friction;
         }
         $this->motionX *= $friction;
         $this->motionY *= 1 - $this->drag;
         $this->motionZ *= $friction;
         $this->updateMovement();
         if ($this->onGround) {
             $this->motionY *= -0.5;
         }
         if ($this->age > 6000) {
             $this->server->getPluginManager()->callEvent($ev = new ItemDespawnEvent($this));
             if ($ev->isCancelled()) {
                 $this->age = 0;
             } else {
                 $this->kill();
                 $hasUpdate = \true;
             }
         }
     }
     $this->timings->stopTiming();
     return $hasUpdate or !$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0;
 }