diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 993c1760a..52fc1ce94 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -317,6 +317,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ return false; } + public function resetFallDistance(){ + parent::resetFallDistance(); + $this->inAirTicks = 0; + } + /** * @return bool */ @@ -1229,20 +1234,24 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->entityBaseTick(1); - if($this->onGround or $this->fallDistance === 0){ + if($this->onGround){ $this->inAirTicks = 0; }else{ - if($this->inAirTicks > 20 and $this->isSurvival() and !$this->isSleeping()){ + if($this->inAirTicks > 10 and $this->isSurvival() and !$this->isSleeping()){ $expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - 2)); - $diff = ($this->speed->y - $expectedVelocity) ** 2; + $diff = sqrt(abs($this->speed->y - $expectedVelocity)); if($diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){ - $this->kick("Flying is not enabled on this server"); + if($this->inAirTicks < 100){ + $this->setMotion(new Vector3(0, 5, 0)); + }else{ + $this->kick("Flying is not enabled on this server"); + return false; + } } - return false; - }else{ - ++$this->inAirTicks; } + + ++$this->inAirTicks; } foreach($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity){ @@ -2687,7 +2696,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $this->airTicks = 300; - $this->fallDistance = 0; + $this->resetFallDistance(); $this->orderChunks(); $this->nextChunkOrderRun = 0; $this->forceMovement = new Vector3($this->x, $this->y, $this->z); diff --git a/src/pocketmine/block/Cobweb.php b/src/pocketmine/block/Cobweb.php index 5bc1220f6..7d0995a57 100644 --- a/src/pocketmine/block/Cobweb.php +++ b/src/pocketmine/block/Cobweb.php @@ -45,7 +45,7 @@ class Cobweb extends Flowable{ } public function onEntityCollide(Entity $entity){ - $entity->fallDistance = 0; + $entity->resetFallDistance(); } public function getDrops(Item $item){ diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index b0c389784..02df5f485 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -52,7 +52,7 @@ class Ladder extends Transparent{ } public function onEntityCollide(Entity $entity){ - $entity->fallDistance = 0; + $entity->resetFallDistance(); $entity->onGround = true; } diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index 40d2a092b..b9272b7a0 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -53,7 +53,7 @@ class Vine extends Transparent{ } public function onEntityCollide(Entity $entity){ - $entity->fallDistance = 0; + $entity->resetFallDistance(); } protected function recalculateBoundingBox(){ diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index 8cd69e5dd..de8d3db0a 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -42,7 +42,7 @@ class Water extends Liquid{ } public function onEntityCollide(Entity $entity){ - $entity->fallDistance = 0; + $entity->resetFallDistance(); if($entity->fireTicks > 0){ $entity->extinguish(); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 3b291dcf8..df8327cec 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -709,6 +709,10 @@ abstract class Entity extends Location implements Metadatable{ return true; } + public function resetFallDistance(){ + $this->fallDistance = 0; + } + protected function updateFallState($distanceThisTick, $onGround){ if($onGround === true){ if($this->fallDistance > 0){ @@ -717,7 +721,7 @@ abstract class Entity extends Location implements Metadatable{ } $this->fall($this->fallDistance); - $this->fallDistance = 0; + $this->resetFallDistance(); } }elseif($distanceThisTick < 0){ $this->fallDistance -= $distanceThisTick; @@ -1200,7 +1204,7 @@ abstract class Entity extends Location implements Metadatable{ $this->setMotion(new Vector3(0, 0, 0)); if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false){ - $this->fallDistance = 0; + $this->resetFallDistance(); $this->onGround = true; $this->lastX = $this->x;