mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
Added new predictive flight protection
This commit is contained in:
parent
24c6cca664
commit
63f1a50be4
@ -147,6 +147,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
protected $moveToSend = [];
|
protected $moveToSend = [];
|
||||||
protected $motionToSend = [];
|
protected $motionToSend = [];
|
||||||
|
|
||||||
|
/** @var Vector3 */
|
||||||
|
public $speed = null;
|
||||||
|
|
||||||
public $blocked = false;
|
public $blocked = false;
|
||||||
public $achievements = [];
|
public $achievements = [];
|
||||||
public $lastCorrect;
|
public $lastCorrect;
|
||||||
@ -1164,6 +1167,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->speed = $to->subtract($from);
|
||||||
|
}elseif($distanceSquared == 0){
|
||||||
|
$this->speed = new Vector3(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($revert){
|
if($revert){
|
||||||
@ -1186,13 +1193,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$pk->teleport = true;
|
$pk->teleport = true;
|
||||||
$this->directDataPacket($pk);
|
$this->directDataPacket($pk);
|
||||||
$this->forceMovement = new Vector3($from->x, $from->y, $from->z);
|
$this->forceMovement = new Vector3($from->x, $from->y, $from->z);
|
||||||
$this->newPosition = null;
|
|
||||||
}else{
|
}else{
|
||||||
$this->forceMovement = null;
|
$this->forceMovement = null;
|
||||||
if($distanceSquared != 0 and $this->nextChunkOrderRun > 20){
|
if($distanceSquared != 0 and $this->nextChunkOrderRun > 20){
|
||||||
$this->nextChunkOrderRun = 20;
|
$this->nextChunkOrderRun = 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->newPosition = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateMovement(){
|
public function updateMovement(){
|
||||||
@ -1224,8 +1232,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
if($this->onGround){
|
if($this->onGround){
|
||||||
$this->inAirTicks = 0;
|
$this->inAirTicks = 0;
|
||||||
}else{
|
}else{
|
||||||
if($this->inAirTicks > 100 and $this->isSurvival() and !$this->isSleeping() and $this->spawned and !$this->server->getAllowFlight()){
|
if($this->inAirTicks > 20 and $this->isSurvival() and !$this->isSleeping() and $this->spawned and !$this->server->getAllowFlight()){
|
||||||
|
$expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - 2));
|
||||||
|
$diff = ($this->speed->y - $expectedVelocity) ** 2;
|
||||||
|
|
||||||
|
if($diff > 0.6 and $expectedVelocity < $this->speed->y){
|
||||||
$this->kick("Flying is not enabled on this server");
|
$this->kick("Flying is not enabled on this server");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
++$this->inAirTicks;
|
++$this->inAirTicks;
|
||||||
|
@ -1039,7 +1039,7 @@ class Block extends Position implements Metadatable{
|
|||||||
*/
|
*/
|
||||||
public function collidesWithBB(AxisAlignedBB $bb, &$list = []){
|
public function collidesWithBB(AxisAlignedBB $bb, &$list = []){
|
||||||
$bb2 = $this->getBoundingBox();
|
$bb2 = $this->getBoundingBox();
|
||||||
if($bb2 !== null and $bb2->intersectsWith($bb)){
|
if($bb2 !== null and $bb->intersectsWith($bb2)){
|
||||||
$list[] = $bb2;
|
$list[] = $bb2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1055,11 +1055,10 @@ class Block extends Position implements Metadatable{
|
|||||||
* @return AxisAlignedBB
|
* @return AxisAlignedBB
|
||||||
*/
|
*/
|
||||||
public function getBoundingBox(){
|
public function getBoundingBox(){
|
||||||
if($this->boundingBox !== null){
|
if($this->boundingBox === null){
|
||||||
return $this->boundingBox;
|
$this->boundingBox = $this->recalculateBoundingBox();
|
||||||
}else{
|
|
||||||
return ($this->boundingBox = $this->recalculateBoundingBox());
|
|
||||||
}
|
}
|
||||||
|
return $this->boundingBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1004,7 +1004,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
if(!$this->onGround or $movY != 0){
|
if(!$this->onGround or $movY != 0){
|
||||||
$bb = clone $this->boundingBox;
|
$bb = clone $this->boundingBox;
|
||||||
$bb->minY -= 1;
|
$bb->minY -= 1;
|
||||||
if(count($this->level->getCollisionBlocks($bb->expand(0.01, 0.01, 0.01))) > 0){
|
if(count($this->level->getCollisionBlocks($bb)) > 0){
|
||||||
$this->onGround = true;
|
$this->onGround = true;
|
||||||
}else{
|
}else{
|
||||||
$this->onGround = false;
|
$this->onGround = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user