pocketmine\entity\Minecart::checkIfOnRail PHP Method

checkIfOnRail() private method

Check if minecart is currently on a rail and if so center the cart.
private checkIfOnRail ( )
    private function checkIfOnRail()
    {
        for ($y = -1; $y !== 2 and $this->state === Minecart::STATE_INITIAL; $y++) {
            $positionToCheck = $this->temporalVector->setComponents($this->x, $this->y + $y, $this->z);
            $block = $this->level->getBlock($positionToCheck);
            if ($this->isRail($block)) {
                $minecartPosition = $positionToCheck->floor()->add(0.5, 0, 0.5);
                $this->setPosition($minecartPosition);
                // Move minecart to center of rail
                $this->state = Minecart::STATE_ON_RAIL;
            }
        }
        if ($this->state !== Minecart::STATE_ON_RAIL) {
            $this->state = Minecart::STATE_OFF_RAIL;
        }
    }