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; return false;
} }
public function resetFallDistance(){
parent::resetFallDistance();
$this->inAirTicks = 0;
}
/** /**
* @return bool * @return bool
*/ */
@ -1229,21 +1234,25 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->entityBaseTick(1); $this->entityBaseTick(1);
if($this->onGround or $this->fallDistance === 0){ if($this->onGround){
$this->inAirTicks = 0; $this->inAirTicks = 0;
}else{ }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)); $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()){ 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));
return false;
}else{ }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){ foreach($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity){
if(($currentTick - $entity->lastUpdate) > 1){ if(($currentTick - $entity->lastUpdate) > 1){
@ -2687,7 +2696,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
} }
$this->airTicks = 300; $this->airTicks = 300;
$this->fallDistance = 0; $this->resetFallDistance();
$this->orderChunks(); $this->orderChunks();
$this->nextChunkOrderRun = 0; $this->nextChunkOrderRun = 0;
$this->forceMovement = new Vector3($this->x, $this->y, $this->z); $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){ public function onEntityCollide(Entity $entity){
$entity->fallDistance = 0; $entity->resetFallDistance();
} }
public function getDrops(Item $item){ public function getDrops(Item $item){

View File

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

View File

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

View File

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

View File

@ -709,6 +709,10 @@ abstract class Entity extends Location implements Metadatable{
return true; return true;
} }
public function resetFallDistance(){
$this->fallDistance = 0;
}
protected function updateFallState($distanceThisTick, $onGround){ protected function updateFallState($distanceThisTick, $onGround){
if($onGround === true){ if($onGround === true){
if($this->fallDistance > 0){ if($this->fallDistance > 0){
@ -717,7 +721,7 @@ abstract class Entity extends Location implements Metadatable{
} }
$this->fall($this->fallDistance); $this->fall($this->fallDistance);
$this->fallDistance = 0; $this->resetFallDistance();
} }
}elseif($distanceThisTick < 0){ }elseif($distanceThisTick < 0){
$this->fallDistance -= $distanceThisTick; $this->fallDistance -= $distanceThisTick;
@ -1200,7 +1204,7 @@ abstract class Entity extends Location implements Metadatable{
$this->setMotion(new Vector3(0, 0, 0)); $this->setMotion(new Vector3(0, 0, 0));
if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false){ 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->onGround = true;
$this->lastX = $this->x; $this->lastX = $this->x;