jump test for pathfinder

This commit is contained in:
GameHerobrine 2023-01-08 02:07:45 +03:00
parent d0ec32dc02
commit dd4264998d
5 changed files with 28 additions and 15 deletions

View file

@ -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);

View file

@ -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 [];
}