mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
Improved flight detection, added Entity->resetFallDistance(), closes #2632
This commit is contained in:
parent
7c0f5987d3
commit
116ede3679
@ -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);
|
||||
|
@ -45,7 +45,7 @@ class Cobweb extends Flowable{
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->fallDistance = 0;
|
||||
$entity->resetFallDistance();
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
|
@ -52,7 +52,7 @@ class Ladder extends Transparent{
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->fallDistance = 0;
|
||||
$entity->resetFallDistance();
|
||||
$entity->onGround = true;
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Vine extends Transparent{
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->fallDistance = 0;
|
||||
$entity->resetFallDistance();
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox(){
|
||||
|
@ -42,7 +42,7 @@ class Water extends Liquid{
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->fallDistance = 0;
|
||||
$entity->resetFallDistance();
|
||||
if($entity->fireTicks > 0){
|
||||
$entity->extinguish();
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user