mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
jump test for pathfinder
This commit is contained in:
parent
d0ec32dc02
commit
dd4264998d
5 changed files with 28 additions and 15 deletions
|
|
@ -58,10 +58,10 @@ class TileNavigator implements ITileNavigator
|
|||
}
|
||||
|
||||
$visited[(string)$neighbor] = $neighbor;
|
||||
if ($this->blockedProvider->isBlocked($neighbor))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//if ($this->blockedProvider->isBlocked($neighbor)) shouldnt be neccessary now
|
||||
//{
|
||||
// continue;
|
||||
//}
|
||||
$distbetweenCost = $this->distanceAlgorithm->calculate($current, $neighbor);
|
||||
$tentativeG = $gScore[(string) $current] + $distbetweenCost;
|
||||
$tentativeF = $distbetweenCost + $this->heuristicAlgorithm->calculate($neighbor, $to);
|
||||
|
|
|
|||
|
|
@ -2,14 +2,28 @@
|
|||
|
||||
class MCDiagonalProvider implements INeighborProvider
|
||||
{
|
||||
private static $neighbors = array([ 0, 0, -1 ], [ 1, 0, 0 ], [ 0, 0, 1 ], [ -1, 0, 0 ], [ -1, 0, -1 ], [ 1, 0, -1 ], [ 1, 0, 1 ], [ -1, 0, 1 ]);
|
||||
private static $neighbors = array([ 0, 0, -1 ], [ 1, 0, 0 ], [ 0, 0, 1 ], [ -1, 0, 0 ]);
|
||||
private static $jumpOffset = [0, 1, 0];
|
||||
private static $moveDownOffset = [0, -1, 0];
|
||||
public function getNeighbors(PathTile $tile)
|
||||
{
|
||||
|
||||
if($tile instanceof PathTileXYZ){
|
||||
return array_map(function($offset) use($tile){
|
||||
return $tile->addOffset($offset);
|
||||
}, MCDiagonalProvider::$neighbors);
|
||||
$pnts = [];
|
||||
foreach(MCDiagonalProvider::$neighbors as $offset){
|
||||
$pnt = $tile->addOffset($offset);
|
||||
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y, $pnt->z)->isSolid){
|
||||
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y - 1, $pnt->z)->isSolid){
|
||||
--$pnt->y;
|
||||
}
|
||||
$pnts[] = $pnt;
|
||||
}else{
|
||||
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y + 1, $pnt->z)->isSolid){
|
||||
$pnts[] = $pnt->addOffset(self::$jumpOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $pnts;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue