pocketmine\entity\Minecart::forwardOnRail PHP Méthode

forwardOnRail() private méthode

Attempt to move forward on rail given the direction the cart is already moving, or if not moving based on the direction the player is looking.
private forwardOnRail ( Player $player ) : boolean
$player pocketmine\Player Player riding the minecart.
Résultat boolean True if minecart moved, false otherwise.
    private function forwardOnRail(Player $player)
    {
        if ($this->direction === -1) {
            $candidateDirection = $player->getDirection();
        } else {
            $candidateDirection = $this->direction;
        }
        $rail = $this->getCurrentRail();
        if ($rail !== null) {
            $railType = $rail->getDamage();
            $nextDirection = $this->getDirectionToMove($railType, $candidateDirection);
            if ($nextDirection !== -1) {
                $this->direction = $nextDirection;
                $moved = $this->checkForVertical($railType, $nextDirection);
                if (!$moved) {
                    return $this->moveIfRail();
                } else {
                    return true;
                }
            } else {
                $this->direction = -1;
                // Was not able to determine direction to move, so wait for player to look in valid direction
            }
        } else {
            // Not able to find rail
            $this->state = Minecart::STATE_INITIAL;
        }
        return false;
    }