Entity: avoid direct Vector3 mutations in tryChangeMovement()

This commit is contained in:
Dylan K. Taylor 2020-09-25 18:37:29 +01:00
parent 9dda99f844
commit 25566c2f1a

View File

@ -775,24 +775,25 @@ abstract class Entity{
protected function tryChangeMovement() : void{ protected function tryChangeMovement() : void{
$friction = 1 - $this->drag; $friction = 1 - $this->drag;
$mY = $this->motion->y;
if($this->applyDragBeforeGravity()){ if($this->applyDragBeforeGravity()){
$this->motion->y *= $friction; $mY *= $friction;
} }
if($this->gravityEnabled){ if($this->gravityEnabled){
$this->motion->y -= $this->gravity; $mY -= $this->gravity;
} }
if(!$this->applyDragBeforeGravity()){ if(!$this->applyDragBeforeGravity()){
$this->motion->y *= $friction; $mY *= $friction;
} }
if($this->onGround){ if($this->onGround){
$friction *= $this->getWorld()->getBlockAt((int) floor($this->location->x), (int) floor($this->location->y - 1), (int) floor($this->location->z))->getFrictionFactor(); $friction *= $this->getWorld()->getBlockAt((int) floor($this->location->x), (int) floor($this->location->y - 1), (int) floor($this->location->z))->getFrictionFactor();
} }
$this->motion->x *= $friction; $this->motion = new Vector3($this->motion->x * $friction, $mY, $this->motion->z * $friction);
$this->motion->z *= $friction;
} }
protected function checkObstruction(float $x, float $y, float $z) : bool{ protected function checkObstruction(float $x, float $y, float $z) : bool{