changed pathfinder(hopefully one last time)

This commit is contained in:
GameHerobrine 2022-12-26 02:16:24 +03:00
parent 8c12e0de26
commit e11c40f645
28 changed files with 401 additions and 416 deletions

View file

@ -0,0 +1,17 @@
<?php
class DiagonalNeighborProvider implements INeighborProvider
{
private static $neighbors = array([ 0, -1 ], [ 1, 0 ], [ 0, 1 ], [ -1, 0 ], [ -1, -1 ], [ 1, -1 ], [ 1, 1 ], [ -1, 1 ]);
public function getNeighbors(PathTile $tile)
{
$result = [];
foreach(self::$neighbors as $offset){
$t = clone $tile;
$result[] = $t->addOffset($offset);
}
return $result;
}
}

View file

@ -0,0 +1,10 @@
<?php
class EmptyBlockedProvider implements IBlockedProvider
{
public function isBlocked(PathTile $tile)
{
return false;
}
}

View file

@ -0,0 +1,12 @@
<?php
interface IBlockedProvider
{
/**
* @param Tile $tile
*
* @return boolean
*/
public function isBlocked(PathTile $tile);
}

View file

@ -0,0 +1,7 @@
<?php
interface INeighborProvider
{
public function getNeighbors(PathTile $tile);
}

View file

@ -0,0 +1,16 @@
<?php
class MCBlockedProvider implements IBlockedProvider
{
public function isBlocked(PathTile $tile)
{
if($tile instanceof PathTileXYZ){
$b = $tile->level->getBlockWithoutVector($tile->x, $tile->y, $tile->z);
return $b instanceof Block && $b->isSolid;
}
return false;
}
}

View file

@ -0,0 +1,22 @@
<?php
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 ]);
public function getNeighbors(PathTile $tile)
{
if($tile instanceof PathTileXYZ){
$result = [];
foreach(self::$neighbors as $offset){
$t = clone $tile;
$result[] = $t->addOffset($offset);
}
return $result;
}
return [];
}
}