public function onUpdate($currentTick)
{
if (!$this->loggedIn) {
return false;
}
$tickDiff = $currentTick - $this->lastUpdate;
if ($tickDiff <= 0) {
return true;
}
$this->messageCounter = 2;
$this->lastUpdate = $currentTick;
$this->sendAttributes();
if (!$this->isAlive() and $this->spawned) {
++$this->deadTicks;
if ($this->deadTicks >= 10) {
$this->despawnFromAll();
}
return true;
}
$this->timings->startTiming();
if ($this->spawned) {
if ($this->server->netherEnabled) {
if (($this->isCreative() or $this->isSurvival() and $this->server->getTick() - $this->portalTime >= 80) and $this->portalTime > 0) {
if ($this->server->netherLevel instanceof Level) {
if ($this->getLevel() != $this->server->netherLevel) {
$this->fromPos = $this->getPosition();
$this->fromPos->x = (int) $this->fromPos->x + 0.5;
$this->fromPos->z = (int) $this->fromPos->z + 0.5;
$this->teleport($this->shouldResPos = $this->server->netherLevel->getSafeSpawn());
} elseif ($this->fromPos instanceof Position) {
if (!$this->getLevel()->isChunkLoaded($this->fromPos->x, $this->fromPos->z)) {
$this->getLevel()->loadChunk($this->fromPos->x, $this->fromPos->z);
}
$add = [1, 0, -1, 0, 0, 1, 0, -1];
$tempos = null;
for ($j = 2; $j < 5; $j++) {
for ($i = 0; $i < 4; $i++) {
if ($this->fromPos->getLevel()->getBlock($this->temporalVector->fromObjectAdd($this->fromPos, $add[$i] * $j, 0, $add[$i + 4] * $j))->getId() === Block::AIR) {
if ($this->fromPos->getLevel()->getBlock($this->temporalVector->fromObjectAdd($this->fromPos, $add[$i] * $j, 1, $add[$i + 4] * $j))->getId() === Block::AIR) {
$tempos = $this->fromPos->add($add[$i] * $j, 0, $add[$i + 4] * $j);
//$this->getLevel()->getServer()->getLogger()->debug($tempos);
break;
}
}
}
if ($tempos != null) {
break;
}
}
if ($tempos == null) {
$tempos = $this->fromPos->add(mt_rand(-2, 2), 0, mt_rand(-2, 2));
}
$this->teleport($this->shouldResPos = $tempos);
$add = null;
$tempos = null;
$this->fromPos = null;
} else {
$this->teleport($this->shouldResPos = $this->server->getDefaultLevel()->getSafeSpawn());
}
$this->portalTime = 0;
}
}
}
if (!$this->isSleeping()) {
$this->processMovement($tickDiff);
}
if (!$this->isSpectator()) {
$this->entityBaseTick($tickDiff);
}
if ($this->isOnFire() or $this->lastUpdate % 10 == 0) {
if ($this->isCreative() and !$this->isInsideOfFire()) {
$this->extinguish();
} elseif ($this->getLevel()->getWeather()->isRainy()) {
if ($this->getLevel()->canBlockSeeSky($this)) {
$this->extinguish();
}
}
}
if ($this->server->antiFly) {
if (!$this->isSpectator() and $this->speed !== null) {
if ($this->onGround) {
if ($this->inAirTicks !== 0) {
$this->startAirTicks = 5;
}
$this->inAirTicks = 0;
} else {
if (!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and $this->getDataProperty(self::DATA_NO_AI) !== 1) {
//expectedVelocity here is not calculated correctly
//This causes players to fall too fast when bouncing on slime when antiFly is enabled
$expectedVelocity = -$this->gravity / $this->drag - -$this->gravity / $this->drag * exp(-$this->drag * ($this->inAirTicks - $this->startAirTicks));
$diff = ($this->speed->y - $expectedVelocity) ** 2;
if (!$this->hasEffect(Effect::JUMP) and $diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()) {
$this->setMotion($this->temporalVector->setComponents(0, $expectedVelocity, 0));
/*if($this->inAirTicks < 1000){
}elseif($this->kick("Flying is not enabled on this server")){
$this->timings->stopTiming();
return false;
}*/
}
}
++$this->inAirTicks;
}
}
}
if ($this->getTransactionQueue() !== null) {
$this->getTransactionQueue()->execute();
}
}
$this->checkTeleportPosition();
$this->timings->stopTiming();
return true;
}