public function onUpdate($currentTick)
{
if ($this->closed !== false) {
return false;
}
$this->lastUpdate = $currentTick;
$this->timings->startTiming();
$hasUpdate = true;
//parent::onUpdate($currentTick);
if ($this->isAlive()) {
$expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
$expBlock0 = $this->getLevel()->getBlock($expectedPos->add(0, -1, 0)->round());
$expBlock1 = $this->getLevel()->getBlock($expectedPos->add(0, 0, 0)->round());
if ($expBlock0->getId() == 0) {
$this->motionY -= $this->gravity;
//重力计算
$this->motionX = 0;
$this->motionZ = 0;
} else {
$this->motionY = 0;
}
if ($expBlock1->getId() != 0) {
$this->motionY += 0.1;
}
$this->move($this->motionX, $this->motionY, $this->motionZ);
if ($this->isFreeMoving) {
$this->motionX = 0;
$this->motionZ = 0;
$this->isFreeMoving = false;
}
/*$friction = 1 - $this->drag;
$this->motionX *= $friction;
$this->motionY *= 1 - $this->drag;
$this->motionZ *= $friction;*/
$f = sqrt($this->motionX ** 2 + $this->motionZ ** 2);
$this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
//视角计算
//$this->pitch = (-atan2($f, $this->motionY) * 180 / M_PI);
$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;
}