From 80e150c80377741485446ce56f19039dcd139451 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 20 Jun 2020 21:41:19 +0100 Subject: [PATCH] Entity: get rid of temporalVector mutation except for checkBlockCollision, these are all cold paths ... this gets us one step closer to immutable Vector3 --- src/entity/Entity.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 0c367a28c..c7288db27 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -115,9 +115,6 @@ abstract class Entity{ /** @var bool */ protected $forceMovementUpdate = false; - /** @var Vector3 */ - public $temporalVector; - /** @var AxisAlignedBB */ public $boundingBox; /** @var bool */ @@ -224,8 +221,6 @@ abstract class Entity{ public function __construct(Location $location, ?CompoundTag $nbt = null){ $this->timings = Timings::getEntityTimings($this); - $this->temporalVector = new Vector3(0, 0, 0); - if($this->eyeHeight === null){ $this->eyeHeight = $this->height / 2 + 0.1; } @@ -918,7 +913,7 @@ abstract class Entity{ $x = -$xz * sin(deg2rad($this->location->yaw)); $z = $xz * cos(deg2rad($this->location->yaw)); - return $this->temporalVector->setComponents($x, $y, $z)->normalize(); + return (new Vector3($x, $y, $z))->normalize(); } public function getDirectionPlane() : Vector2{ @@ -1267,7 +1262,7 @@ abstract class Entity{ } protected function checkBlockCollision() : void{ - $vector = $this->temporalVector->setComponents(0, 0, 0); + $vector = new Vector3(0, 0, 0); foreach($this->getBlocksAround() as $block){ $block->onEntityInside($this); @@ -1423,7 +1418,7 @@ abstract class Entity{ } $pos = $ev->getTo(); - $this->setMotion($this->temporalVector->setComponents(0, 0, 0)); + $this->setMotion(new Vector3(0, 0, 0)); if($this->setPositionAndRotation($pos, $yaw ?? $this->location->yaw, $pitch ?? $this->location->pitch)){ $this->resetFallDistance(); $this->setForceMovementUpdate();