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; $diff = $this->distanceSquared($newPos) / $tickDiff ** 2;
if($this->isSurvival() and !$revert and $diff > 0.0625){ 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); $ev->setCancelled($this->allowMovementCheats);
$this->server->getPluginManager()->callEvent($ev); $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); $from = clone $this->lastLocation;
$to = $this->getLocation(); $to = $this->asLocation();
$delta = (($this->lastX - $to->x) ** 2) + (($this->lastY - $to->y) ** 2) + (($this->lastZ - $to->z) ** 2); $delta = $to->distanceSquared($from);
$deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch); $deltaAngle = abs($this->lastLocation->yaw - $to->yaw) + abs($this->lastLocation->pitch - $to->pitch);
if(!$revert and ($delta > 0.0001 or $deltaAngle > 1.0)){ if(!$revert and ($delta > 0.0001 or $deltaAngle > 1.0)){
$this->lastX = $to->x; $this->lastLocation = clone $to; //avoid PlayerMoveEvent modifying this
$this->lastY = $to->y;
$this->lastZ = $to->z;
$this->lastYaw = $to->yaw;
$this->lastPitch = $to->pitch;
$ev = new PlayerMoveEvent($this, $from, $to); $ev = new PlayerMoveEvent($this, $from, $to);
@ -1563,13 +1558,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
if($revert){ if($revert){
$this->lastLocation = $from;
$this->lastX = $from->x;
$this->lastY = $from->y;
$this->lastZ = $from->z;
$this->lastYaw = $from->yaw;
$this->lastPitch = $from->pitch;
$this->setPosition($from); $this->setPosition($from);
$this->sendPosition($from, $from->yaw, $from->pitch, MovePlayerPacket::MODE_RESET); $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[] */ /** @var Block[] */
protected $blocksAround = []; protected $blocksAround = [];
/** @var float|null */ /** @var Location */
public $lastX = null; protected $lastLocation;
/** @var float|null */
public $lastY = null;
/** @var float|null */
public $lastZ = null;
/** @var Vector3 */ /** @var Vector3 */
protected $motion; protected $motion;
/** @var Vector3 */ /** @var Vector3 */
@ -393,12 +388,6 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** @var Vector3 */ /** @var Vector3 */
public $temporalVector; public $temporalVector;
/** @var float */
public $lastYaw;
/** @var float */
public $lastPitch;
/** @var AxisAlignedBB */ /** @var AxisAlignedBB */
public $boundingBox; public $boundingBox;
/** @var bool */ /** @var bool */
@ -1110,18 +1099,13 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
} }
protected function updateMovement(bool $teleport = false) : void{ protected function updateMovement(bool $teleport = false) : void{
$diffPosition = ($this->x - $this->lastX) ** 2 + ($this->y - $this->lastY) ** 2 + ($this->z - $this->lastZ) ** 2; $diffPosition = $this->distanceSquared($this->lastLocation);
$diffRotation = ($this->yaw - $this->lastYaw) ** 2 + ($this->pitch - $this->lastPitch) ** 2; $diffRotation = ($this->yaw - $this->lastLocation->yaw) ** 2 + ($this->pitch - $this->lastLocation->pitch) ** 2;
$diffMotion = $this->motion->subtract($this->lastMotion)->lengthSquared(); $diffMotion = $this->motion->subtract($this->lastMotion)->lengthSquared();
if($teleport or $diffPosition > 0.0001 or $diffRotation > 1.0){ if($teleport or $diffPosition > 0.0001 or $diffRotation > 1.0){
$this->lastX = $this->x; $this->lastLocation = $this->asLocation();
$this->lastY = $this->y;
$this->lastZ = $this->z;
$this->lastYaw = $this->yaw;
$this->lastPitch = $this->pitch;
$this->broadcastMovement($teleport); $this->broadcastMovement($teleport);
} }
@ -1819,8 +1803,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
} }
protected function resetLastMovements() : void{ protected function resetLastMovements() : void{
list($this->lastX, $this->lastY, $this->lastZ) = [$this->x, $this->y, $this->z]; $this->lastLocation = $this->asLocation();
list($this->lastYaw, $this->lastPitch) = [$this->yaw, $this->pitch];
$this->lastMotion = clone $this->motion; $this->lastMotion = clone $this->motion;
} }