pocketmine\entity\Minecart::checkForTurn PHP Метод

checkForTurn() приватный Метод

Need to alter direction on curves halfway through the turn and reset the minecart to be in the middle of the rail again so as not to collide with nearby blocks.
private checkForTurn ( Direction $currentDirection, Direction $newDirection ) : Direction
$currentDirection Direction Direction minecart currently moving
$newDirection Direction Direction minecart should turn once has hit the halfway point.
Результат Direction Either the current direction or the new direction depending on haw far across the rail the minecart is.
    private function checkForTurn($currentDirection, $newDirection)
    {
        switch ($currentDirection) {
            case Entity::NORTH:
                $diff = $this->x - $this->getFloorX();
                if ($diff !== 0 and $diff <= 0.5) {
                    $dx = $this->getFloorX() + 0.5 - $this->x;
                    $this->move($dx, 0, 0);
                    return $newDirection;
                }
                break;
            case Entity::SOUTH:
                $diff = $this->x - $this->getFloorX();
                if ($diff !== 0 and $diff >= 0.5) {
                    $dx = $this->getFloorX() + 0.5 - $this->x;
                    $this->move($dx, 0, 0);
                    return $newDirection;
                }
                break;
            case Entity::EAST:
                $diff = $this->z - $this->getFloorZ();
                if ($diff !== 0 and $diff <= 0.5) {
                    $dz = $this->getFloorZ() + 0.5 - $this->z;
                    $this->move(0, 0, $dz);
                    return $newDirection;
                }
                break;
            case Entity::WEST:
                $diff = $this->z - $this->getFloorZ();
                if ($diff !== 0 and $diff >= 0.5) {
                    $dz = $dz = $this->getFloorZ() + 0.5 - $this->z;
                    $this->move(0, 0, $dz);
                    return $newDirection;
                }
                break;
        }
        return $currentDirection;
    }