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;
}