Entity: Use MoveEntityPacket teleport flag for teleporting

fixes entities getting movement interpolation between origin and destination
This commit is contained in:
Dylan K. Taylor 2018-02-24 12:25:25 +00:00
parent abe5d94d5b
commit e5ec8fa603
2 changed files with 7 additions and 6 deletions

View File

@ -1615,7 +1615,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return false;
}
protected function updateMovement(){
protected function updateMovement(bool $teleport = false){
}

View File

@ -1085,13 +1085,13 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return true;
}
protected function updateMovement(){
protected function updateMovement(bool $teleport = false){
$diffPosition = ($this->x - $this->lastX) ** 2 + ($this->y - $this->lastY) ** 2 + ($this->z - $this->lastZ) ** 2;
$diffRotation = ($this->yaw - $this->lastYaw) ** 2 + ($this->pitch - $this->lastPitch) ** 2;
$diffMotion = ($this->motionX - $this->lastMotionX) ** 2 + ($this->motionY - $this->lastMotionY) ** 2 + ($this->motionZ - $this->lastMotionZ) ** 2;
if($diffPosition > 0.0001 or $diffRotation > 1.0){
if($teleport or $diffPosition > 0.0001 or $diffRotation > 1.0){
$this->lastX = $this->x;
$this->lastY = $this->y;
$this->lastZ = $this->z;
@ -1099,7 +1099,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->lastYaw = $this->yaw;
$this->lastPitch = $this->pitch;
$this->broadcastMovement();
$this->broadcastMovement($teleport);
}
if($diffMotion > 0.0025 or ($diffMotion > 0.0001 and $this->getMotion()->lengthSquared() <= 0.0001)){ //0.05 ** 2
@ -1115,7 +1115,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return new Vector3($vector3->x, $vector3->y + $this->baseOffset, $vector3->z);
}
protected function broadcastMovement(){
protected function broadcastMovement(bool $teleport = false){
if($this->chunk !== null){
$pk = new MoveEntityPacket();
$pk->entityRuntimeId = $this->id;
@ -1123,6 +1123,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$pk->yaw = $this->yaw;
$pk->pitch = $this->pitch;
$pk->headYaw = $this->yaw; //TODO
$pk->teleported = $teleport;
$this->level->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $pk);
}
@ -1846,7 +1847,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->resetFallDistance();
$this->onGround = true;
$this->updateMovement();
$this->updateMovement(true);
return true;
}