Last active
January 2, 2020 17:36
-
-
Save TheBlackPlague/612205a90539c1d27e61c66c2332dd68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private static function getVectorFromConnection(int $connection): ?Vector3 | |
{ | |
switch ($connection) { | |
case 2: | |
return new Vector3(0, 0, -1); | |
break; | |
case 3: | |
return new Vector3(0, 0, 1); | |
break; | |
case 4: | |
return new Vector3(-1, 0, 0); | |
break; | |
case 5: | |
return new Vector3(1, 0, 0); | |
break; | |
} | |
return null; | |
} | |
protected function findNextRail(): void | |
{ | |
$railInstanceCheck = $this->currentRail instanceof CustomBaseRail && $this->previousRail instanceof CustomBaseRail; | |
if ($railInstanceCheck === false) { | |
$previousRailInstanceCheck = $this->previousRail instanceof CustomBaseRail; | |
if ($previousRailInstanceCheck === false) { | |
$currentRailConnection = $this->currentRail->getConnectedDirections(); | |
$currentRailConnectionCount = count($currentRailConnection); | |
if ($currentRailConnectionCount === 0) { | |
return; | |
} | |
foreach ($currentRailConnection as $connection) { | |
$connectionVector = self::getVectorFromConnection($connection); | |
$railVector = $this->currentRail->add($connectionVector); | |
if ($this->level === null) { | |
return; | |
} | |
$rail = $this->level->getBlock($railVector); | |
if ($rail instanceof CustomBaseRail) { | |
$this->previousRail = $rail; | |
$this->findNextRail(); | |
return; | |
} | |
} | |
} | |
return; | |
} | |
if ($this->nextRail instanceof CustomBaseRail && $this->nextRailDuplicatedCheck === false) { | |
if ($this->motion->x === 0 && $this->motion->y === 0 && $this->motion->z === 0) { | |
return; | |
} | |
$this->previousRail = $this->currentRail; | |
$this->currentRail = $this->nextRail; | |
$this->nextRailDuplicatedCheck = true; | |
$this->findNextRail(); | |
return; | |
} | |
$currentRailConnection = $this->currentRail->getConnectedDirections(); | |
foreach ($currentRailConnection as $connection) { | |
$connectionVector = self::getVectorFromConnection($connection); | |
$railVector = $this->currentRail->add($connectionVector); | |
$previousConnectionCheck = $this->previousRail->equals($railVector); | |
if ($previousConnectionCheck === true) { | |
continue; | |
} | |
if ($this->level === null) { | |
return; | |
} | |
$rail = $this->level->getBlock($railVector); | |
if ($rail instanceof CustomBaseRail) { | |
$this->nextRail = $rail; | |
$this->nextRailDuplicatedCheck = false; | |
return; | |
} | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment