mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
pathfinder optimizations
This commit is contained in:
parent
cba1879947
commit
60c8603c8b
13 changed files with 58 additions and 145 deletions
|
|
@ -423,7 +423,11 @@ class Utils{
|
|||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public static function php8_nulcoal(&$arr, $else){
|
||||
return isset($arr) ? $arr : $else;
|
||||
}
|
||||
|
||||
public static function readTriad($str){
|
||||
return @unpack("N", "\x00" . $str)[1];
|
||||
}
|
||||
|
|
@ -556,8 +560,15 @@ class Utils{
|
|||
/**
|
||||
* manhattan distance, less accurate, but still useful sometimes
|
||||
*/
|
||||
public static function manh_distance(Vector3 $pos1, Vector3 $pos2){
|
||||
return abs($pos2->x - $pos1->x) + abs($pos2->y - $pos1->y) + abs($pos2->z - $pos1->z);
|
||||
public static function manh_distance($pos1, $pos2){
|
||||
if($pos1 instanceof Vector3){
|
||||
$pos1 = $pos1->toArray();
|
||||
}
|
||||
if($pos2 instanceof Vector3){
|
||||
$pos2 = $pos2->toArray();
|
||||
}
|
||||
|
||||
return abs($pos2["x"] - $pos1["x"]) + abs($pos2["y"] - $pos1["y"]) + abs($pos2["z"] - $pos1["z"]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue