mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
minecart entity tweaks
This commit is contained in:
parent
39bfa7115d
commit
b362f262f4
7 changed files with 23 additions and 19 deletions
|
|
@ -26,8 +26,8 @@ class TileNavigator implements ITileNavigator
|
|||
|
||||
public function navigate(PathTile $from, PathTile $to, $maxDist)
|
||||
{
|
||||
$open = new SplPriorityQueue();
|
||||
$open->insert($from, 0);
|
||||
$open = [0 => $from];
|
||||
//$open->insert(, 0);
|
||||
$path = [];
|
||||
$gScore = [];
|
||||
$gScore[(string) $from] = 0;
|
||||
|
|
@ -37,16 +37,16 @@ class TileNavigator implements ITileNavigator
|
|||
}
|
||||
$visited = [];
|
||||
$maxDist*=$maxDist; //no square root
|
||||
while(!$open->isEmpty())
|
||||
while(count($open) > 0)
|
||||
{
|
||||
$current = $open->top();
|
||||
$open->next();
|
||||
$current = array_pop($open);
|
||||
if ($current == $to){
|
||||
return $this->reconstructPath($path, $current);
|
||||
}
|
||||
foreach($this->neighborProvider->getNeighbors($current) as $neighbor)
|
||||
{
|
||||
if(!Utils::in_range(($from->x - $neighbor->x)*($from->x - $neighbor->x) + ($from->y - $neighbor->y)*($from->y - $neighbor->y) + ($from->z - $neighbor->z)*($from->z - $neighbor->z), -$maxDist, $maxDist)){ //Utils::distance_noroot($neighbor->asArray(), $from->asArray())
|
||||
$dist = ($from->x - $neighbor->x)*($from->x - $neighbor->x) + ($from->y - $neighbor->y)*($from->y - $neighbor->y) + ($from->z - $neighbor->z)*($from->z - $neighbor->z);
|
||||
if($dist < -$maxDist || $dist > $maxDist){ //Utils::distance_noroot($neighbor->asArray(), $from->asArray())
|
||||
continue;
|
||||
}
|
||||
if(isset($visited[(string)$neighbor])){
|
||||
|
|
@ -58,7 +58,7 @@ class TileNavigator implements ITileNavigator
|
|||
$tentativeG = $gScore[(string) $current] + $distbetweenCost;
|
||||
if (!isset($has[(string)$neighbor]))
|
||||
{
|
||||
$open->insert($neighbor, -$tentativeG);
|
||||
$open[-$tentativeG] = $neighbor;
|
||||
$has[(string)$neighbor] = true;
|
||||
}
|
||||
elseif ($tentativeG >= $gScore[(string) $neighbor])
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@
|
|||
|
||||
class MCDiagonalProvider implements INeighborProvider
|
||||
{
|
||||
private static $neighbors = array([ 0, 0, -1 ], [ 1, 0, 0 ], [ 0, 0, 1 ], [ -1, 0, 0 ]);
|
||||
private static $neighbors = array(
|
||||
[ -1, 0, -1 ], [-1, 0, 0], [-1, 0, 1],
|
||||
[0, 0, -1], [0, 0, 1],
|
||||
[1, 0, -1], [1, 0, 0], [1, 0, -1]
|
||||
);
|
||||
private static $jumpOffset = [0, 1, 0];
|
||||
private static $moveDownOffset = [0, -1, 0];
|
||||
public function getNeighbors(PathTile $tile)
|
||||
|
|
@ -12,12 +16,12 @@ class MCDiagonalProvider implements INeighborProvider
|
|||
foreach(MCDiagonalProvider::$neighbors as $offset){
|
||||
$pnt = $tile->addOffset($offset);
|
||||
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y, $pnt->z))){
|
||||
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y - 1, $pnt->z, false))){
|
||||
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y - 1, $pnt->z))){
|
||||
--$pnt->y;
|
||||
}
|
||||
$pnts[] = $pnt;
|
||||
}else{
|
||||
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y + 1, $pnt->z, false))){
|
||||
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y + 1, $pnt->z))){
|
||||
++$pnt->y;
|
||||
$pnts[] = $pnt;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue