Entity: remove lastX lastY lastZ lastYaw lastPitch, replace with lastLocation object field

This commit is contained in:
Dylan K. Taylor 2018-08-18 13:38:19 +01:00
parent f8e3b0b16b
commit a306421737
2 changed files with 13 additions and 41 deletions

View File

@ -1506,7 +1506,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$diff = $this->distanceSquared($newPos) / $tickDiff ** 2;
if($this->isSurvival() and !$revert and $diff > 0.0625){
$ev = new PlayerIllegalMoveEvent($this, $newPos, new Vector3($this->lastX, $this->lastY, $this->lastZ));
$ev = new PlayerIllegalMoveEvent($this, $newPos, $this->lastLocation->asVector3());
$ev->setCancelled($this->allowMovementCheats);
$this->server->getPluginManager()->callEvent($ev);
@ -1523,19 +1523,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
}
$from = new Location($this->lastX, $this->lastY, $this->lastZ, $this->lastYaw, $this->lastPitch, $this->level);
$to = $this->getLocation();
$from = clone $this->lastLocation;
$to = $this->asLocation();
$delta = (($this->lastX - $to->x) ** 2) + (($this->lastY - $to->y) ** 2) + (($this->lastZ - $to->z) ** 2);
$deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch);
$delta = $to->distanceSquared($from);
$deltaAngle = abs($this->lastLocation->yaw - $to->yaw) + abs($this->lastLocation->pitch - $to->pitch);
if(!$revert and ($delta > 0.0001 or $deltaAngle > 1.0)){
$this->lastX = $to->x;
$this->lastY = $to->y;
$this->lastZ = $to->z;
$this->lastYaw = $to->yaw;
$this->lastPitch = $to->pitch;
$this->lastLocation = clone $to; //avoid PlayerMoveEvent modifying this
$ev = new PlayerMoveEvent($this, $from, $to);
@ -1563,13 +1558,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
if($revert){
$this->lastX = $from->x;
$this->lastY = $from->y;
$this->lastZ = $from->z;
$this->lastYaw = $from->yaw;
$this->lastPitch = $from->pitch;
$this->lastLocation = $from;
$this->setPosition($from);
$this->sendPosition($from, $from->yaw, $from->pitch, MovePlayerPacket::MODE_RESET);

View File

@ -376,13 +376,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** @var Block[] */
protected $blocksAround = [];
/** @var float|null */
public $lastX = null;
/** @var float|null */
public $lastY = null;
/** @var float|null */
public $lastZ = null;
/** @var Location */
protected $lastLocation;
/** @var Vector3 */
protected $motion;
/** @var Vector3 */
@ -393,12 +388,6 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** @var Vector3 */
public $temporalVector;
/** @var float */
public $lastYaw;
/** @var float */
public $lastPitch;
/** @var AxisAlignedBB */
public $boundingBox;
/** @var bool */
@ -1110,18 +1099,13 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
protected function updateMovement(bool $teleport = false) : void{
$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;
$diffPosition = $this->distanceSquared($this->lastLocation);
$diffRotation = ($this->yaw - $this->lastLocation->yaw) ** 2 + ($this->pitch - $this->lastLocation->pitch) ** 2;
$diffMotion = $this->motion->subtract($this->lastMotion)->lengthSquared();
if($teleport or $diffPosition > 0.0001 or $diffRotation > 1.0){
$this->lastX = $this->x;
$this->lastY = $this->y;
$this->lastZ = $this->z;
$this->lastYaw = $this->yaw;
$this->lastPitch = $this->pitch;
$this->lastLocation = $this->asLocation();
$this->broadcastMovement($teleport);
}
@ -1819,8 +1803,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
protected function resetLastMovements() : void{
list($this->lastX, $this->lastY, $this->lastZ) = [$this->x, $this->y, $this->z];
list($this->lastYaw, $this->lastPitch) = [$this->yaw, $this->pitch];
$this->lastLocation = $this->asLocation();
$this->lastMotion = clone $this->motion;
}