Entity: avoid direct mutation of Vector3 in checkObstruction(), use withComponents() instead

this ugly code can be simplified quite a lot further, but that's a job for later.
This commit is contained in:
Dylan K. Taylor 2020-09-25 18:38:41 +01:00
parent 25566c2f1a
commit 1d8e7abdd4

View File

@ -853,37 +853,37 @@ abstract class Entity{
$force = lcg_value() * 0.2 + 0.1;
if($direction === Facing::WEST){
$this->motion->x = -$force;
$this->motion = $this->motion->withComponents(-$force, null, null);
return true;
}
if($direction === Facing::EAST){
$this->motion->x = $force;
$this->motion = $this->motion->withComponents($force, null, null);
return true;
}
if($direction === Facing::DOWN){
$this->motion->y = -$force;
$this->motion = $this->motion->withComponents(null, -$force, null);
return true;
}
if($direction === Facing::UP){
$this->motion->y = $force;
$this->motion = $this->motion->withComponents(null, $force, null);
return true;
}
if($direction === Facing::NORTH){
$this->motion->z = -$force;
$this->motion = $this->motion->withComponents(null, null, -$force);
return true;
}
if($direction === Facing::SOUTH){
$this->motion->z = $force;
$this->motion = $this->motion->withComponents(null, null, $force);
return true;
}