Entity: use match in checkObstruction()

This commit is contained in:
Dylan K. Taylor 2021-08-17 20:44:33 +01:00
parent b3298d7c77
commit 83805a3406
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -868,43 +868,21 @@ abstract class Entity{
$direction = Facing::SOUTH;
}
if($direction === -1){
return false;
}
$force = lcg_value() * 0.2 + 0.1;
if($direction === Facing::WEST){
$this->motion = $this->motion->withComponents(-$force, null, null);
return true;
}
if($direction === Facing::EAST){
$this->motion = $this->motion->withComponents($force, null, null);
return true;
}
if($direction === Facing::DOWN){
$this->motion = $this->motion->withComponents(null, -$force, null);
return true;
}
if($direction === Facing::UP){
$this->motion = $this->motion->withComponents(null, $force, null);
return true;
}
if($direction === Facing::NORTH){
$this->motion = $this->motion->withComponents(null, null, -$force);
return true;
}
if($direction === Facing::SOUTH){
$this->motion = $this->motion->withComponents(null, null, $force);
return true;
}
$this->motion = match($direction){
Facing::WEST => $this->motion->withComponents(-$force, null, null),
Facing::EAST => $this->motion->withComponents($force, null, null),
Facing::DOWN => $this->motion->withComponents(null, -$force, null),
Facing::UP => $this->motion->withComponents(null, $force, null),
Facing::NORTH => $this->motion->withComponents(null, null, -$force),
Facing::SOUTH => $this->motion->withComponents(null, null, $force),
};
return true;
}
return false;