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;
}