Use MODE_RESET for forceMovement, fixes most teleportation issues

This commit is contained in:
Dylan K. Taylor 2017-01-09 15:30:26 +00:00
parent 6e87a48100
commit 4bf8f00b0f

View File

@ -1451,7 +1451,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->lastYaw = $from->yaw; $this->lastYaw = $from->yaw;
$this->lastPitch = $from->pitch; $this->lastPitch = $from->pitch;
$this->sendPosition($from, $from->yaw, $from->pitch, 1); $this->sendPosition($from, $from->yaw, $from->pitch, MovePlayerPacket::MODE_RESET);
$this->forceMovement = new Vector3($from->x, $from->y, $from->z); $this->forceMovement = new Vector3($from->x, $from->y, $from->z);
}else{ }else{
$this->forceMovement = null; $this->forceMovement = null;
@ -1891,10 +1891,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
break; break;
case ProtocolInfo::MOVE_PLAYER_PACKET: case ProtocolInfo::MOVE_PLAYER_PACKET:
if($this->teleportPosition !== null){
break;
}
$newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z); $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z);
if($newPos->distanceSquared($this) < 0.01 and ($packet->yaw % 360) === $this->yaw and ($packet->pitch % 360) === $this->pitch){ //player hasn't moved, just client spamming packets if($newPos->distanceSquared($this) < 0.01 and ($packet->yaw % 360) === $this->yaw and ($packet->pitch % 360) === $this->pitch){ //player hasn't moved, just client spamming packets
@ -1908,7 +1904,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
if($this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)){ if($this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)){
$this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch); $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch, MovePlayerPacket::MODE_RESET);
}else{ }else{
$packet->yaw %= 360; $packet->yaw %= 360;
$packet->pitch %= 360; $packet->pitch %= 360;
@ -3360,7 +3356,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
} }
public function sendPosition(Vector3 $pos, $yaw = null, $pitch = null, $mode = 0, array $targets = null){ public function sendPosition(Vector3 $pos, $yaw = null, $pitch = null, $mode = MovePlayerPacket::MODE_NORMAL, array $targets = null){
$yaw = $yaw === null ? $this->yaw : $yaw; $yaw = $yaw === null ? $this->yaw : $yaw;
$pitch = $pitch === null ? $this->pitch : $pitch; $pitch = $pitch === null ? $this->pitch : $pitch;
@ -3430,7 +3426,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
} }
$this->sendPosition($this, null, null, 1); $this->sendPosition($this, null, null, MovePlayerPacket::MODE_RESET);
$this->spawnToAll(); $this->spawnToAll();
$this->forceMovement = $this->teleportPosition; $this->forceMovement = $this->teleportPosition;
$this->teleportPosition = null; $this->teleportPosition = null;
@ -3499,7 +3495,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
$this->forceMovement = new Vector3($this->x, $this->y, $this->z); $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
$this->sendPosition($this, $this->yaw, $this->pitch, 1); $this->sendPosition($this, $this->yaw, $this->pitch, MovePlayerPacket::MODE_RESET);
$this->resetFallDistance(); $this->resetFallDistance();
$this->orderChunks(); $this->orderChunks();