Improved flight detection, added Entity->resetFallDistance(), closes #2632

This commit is contained in:
Shoghi Cervantes 2015-02-15 17:40:17 +01:00
parent 7c0f5987d3
commit 116ede3679
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
6 changed files with 27 additions and 14 deletions

View File

@ -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,21 +1234,25 @@ 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");
}
return false;
if($this->inAirTicks < 100){
$this->setMotion(new Vector3(0, 5, 0));
}else{
++$this->inAirTicks;
$this->kick("Flying is not enabled on this server");
return false;
}
}
}
++$this->inAirTicks;
}
foreach($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity){
if(($currentTick - $entity->lastUpdate) > 1){
@ -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);

View File

@ -45,7 +45,7 @@ class Cobweb extends Flowable{
}
public function onEntityCollide(Entity $entity){
$entity->fallDistance = 0;
$entity->resetFallDistance();
}
public function getDrops(Item $item){

View File

@ -52,7 +52,7 @@ class Ladder extends Transparent{
}
public function onEntityCollide(Entity $entity){
$entity->fallDistance = 0;
$entity->resetFallDistance();
$entity->onGround = true;
}

View File

@ -53,7 +53,7 @@ class Vine extends Transparent{
}
public function onEntityCollide(Entity $entity){
$entity->fallDistance = 0;
$entity->resetFallDistance();
}
protected function recalculateBoundingBox(){

View File

@ -42,7 +42,7 @@ class Water extends Liquid{
}
public function onEntityCollide(Entity $entity){
$entity->fallDistance = 0;
$entity->resetFallDistance();
if($entity->fireTicks > 0){
$entity->extinguish();
}

View File

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