mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 18:59:00 +00:00
Fixed outdated movement problem, fixed #1171
This commit is contained in:
parent
1493cde07f
commit
1a5e3b2ad0
@ -298,6 +298,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
/** @var Vector3 */
|
||||
protected $newPosition;
|
||||
|
||||
/** @var bool */
|
||||
protected $isTeleporting = false;
|
||||
|
||||
protected $viewDistance = -1;
|
||||
protected $chunksPerTick;
|
||||
protected $spawnThreshold;
|
||||
@ -1491,7 +1494,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
$revert = false;
|
||||
|
||||
if(($distanceSquared / ($tickDiff ** 2)) > 100 and !$this->allowMovementCheats){
|
||||
if(($distanceSquared / ($tickDiff ** 2)) > 100){
|
||||
$this->server->getLogger()->warning($this->getName() . " moved too fast, reverting movement");
|
||||
$this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $this->newPosition);
|
||||
$revert = true;
|
||||
@ -2126,10 +2129,18 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
public function handleMovePlayer(MovePlayerPacket $packet) : bool{
|
||||
$newPos = new Vector3($packet->x, $packet->y - $this->baseOffset, $packet->z);
|
||||
|
||||
if((!$this->isAlive() or $this->spawned !== true) and $newPos->distanceSquared($this) > 0.01){
|
||||
if($this->isTeleporting and $newPos->distanceSquared($this) > 1){ //Tolerate up to 1 block to avoid problems with client-sided physics when spawning in blocks
|
||||
$this->server->getLogger()->debug("Ignoring outdated pre-teleport movement from " . $this->getName() . ", received " . $newPos . ", expected " . $this->asVector3());
|
||||
//Still getting movements from before teleport, ignore them
|
||||
}elseif((!$this->isAlive() or $this->spawned !== true) and $newPos->distanceSquared($this) > 0.01){
|
||||
$this->sendPosition($this, null, null, MovePlayerPacket::MODE_RESET);
|
||||
$this->server->getLogger()->debug("Reverted movement of " . $this->getName() . " due to not alive or not spawned, received " . $newPos . ", locked at " . $this->asVector3());
|
||||
}else{
|
||||
// Once we get a movement within a reasonable distance, treat it as a teleport ACK and remove position lock
|
||||
if($this->isTeleporting){
|
||||
$this->isTeleporting = false;
|
||||
}
|
||||
|
||||
$packet->yaw %= 360;
|
||||
$packet->pitch %= 360;
|
||||
|
||||
@ -2712,6 +2723,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}else{
|
||||
$this->setPosition($realSpawn); //The client will move to the position of its own accord once chunks are sent
|
||||
$this->nextChunkOrderRun = 0;
|
||||
$this->isTeleporting = true;
|
||||
}
|
||||
|
||||
$this->resetLastMovements();
|
||||
@ -4035,6 +4047,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->newPosition = null;
|
||||
$this->stopSleep();
|
||||
|
||||
$this->isTeleporting = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user