pocketmine\entity\Entity::onUpdate PHP Method

onUpdate() public method

public onUpdate ( $currentTick )
    public function onUpdate($currentTick)
    {
        if ($this->closed) {
            return false;
        }
        if (!$this->isAlive()) {
            ++$this->deadTicks;
            if ($this->deadTicks >= 10) {
                $this->despawnFromAll();
                if (!$this->isPlayer) {
                    $this->close();
                }
            }
            return $this->deadTicks < 10;
        }
        $tickDiff = $currentTick - $this->lastUpdate;
        if ($tickDiff <= 0) {
            return false;
        }
        $this->lastUpdate = $currentTick;
        $this->timings->startTiming();
        $hasUpdate = $this->entityBaseTick($tickDiff);
        $this->updateMovement();
        $this->timings->stopTiming();
        //if($this->isStatic())
        return $hasUpdate;
        //return !($this instanceof Player);
    }

Usage Example

Example #1
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     $collector = null;
     if (!$this->collected) {
         foreach ($this->level->getPlayers() as $p) {
             if ($this->distanceSquared($p) <= 36) {
                 //6 or less
                 $collector = $p;
                 $this->collected = true;
                 break;
             }
         }
     }
     if ($this->age > 1200 || $this->collected) {
         $this->kill();
         $hasUpdate = true;
     }
     if ($collector !== null) {
         $collector->giveExp($this->getAmount());
         $this->kill();
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
All Usage Examples Of pocketmine\entity\Entity::onUpdate