pathfinder rewrite

This commit is contained in:
GameHerobrine 2024-04-14 04:20:14 +03:00
parent cb0fa06e12
commit 22f3c3f640
16 changed files with 89 additions and 263 deletions

View file

@ -21,7 +21,7 @@ abstract class Living extends Entity implements Pathfindable{
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
$this->target = false;
$this->ai = new EntityAI($this);
$this->pathFinder = new TileNavigator(new MCBlockedProvider(), new MCDiagonalProvider(), new Pythagoras3D());
$this->pathFinder = new TileNavigator();
$this->pathFollower = new PathFollower($this);
parent::__construct($level, $eid, $class, $type, $data);
$this->canBeAttacked = true;
@ -121,21 +121,20 @@ abstract class Living extends Entity implements Pathfindable{
$this->ai->updateTasks();
}
/*if($this->onGround){
if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
$me = new PathTileXYZ($this->x, $this->y, $this->z, $this->level);
if(!$this->hasPath()){
//$target = new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level);
$pl = null;
if(count($this->level->players) > 0){
$pl = array_values($this->level->players)[0];
$target = new PathTileXYZ($pl->entity->x, $pl->entity->y, $pl->entity->z, $this->level);
//$target = new PathTileXYZ($pl->entity->x, $pl->entity->y, $pl->entity->z, $this->level);
}
if(self::$pathfind){
$this->path = $this->pathFinder->navigate($me, $target, 10);
if($pl != null && self::$pathfind){
$this->path = $this->pathFinder->navigate($this->level, (int)$this->x, (int)$this->y, (int)$this->z, (int)$pl->entity->x, (int)$pl->entity->y, (int)$pl->entity->z, 10);
}
if($this->path){
console("Found path to $target from $me of length ".count($this->path));
console("Found path of length ".count($this->path));
foreach($this->path as $node){
$eid = self::$lastPathEID++;
@ -144,9 +143,9 @@ abstract class Living extends Entity implements Pathfindable{
$pk = new AddItemEntityPacket();
$pk->eid = $eid;
$pk->item = BlockAPI::getItem(GOLD_BLOCK, 0, 1);
$pk->x = $node->x + 0.5;
$pk->y = $node->y;
$pk->z = $node->z + 0.5;
$pk->x = ($node >> 16 & 0xff) + 0.5;
$pk->y = $node & 0xff;
$pk->z = ($node >> 8 & 0xff) + 0.5;
$pk->yaw = $pk->pitch = 0;
$pk->roll = 0;
foreach($this->level->players as $player){

View file

@ -18,9 +18,11 @@ class PathFollower{
if($this->entity->currentNode == null){
$this->entity->currentNode = $this->entity->path[$this->entity->currentIndex];
}
$this->entity->ai->mobController->setMovingTarget($this->entity->currentNode->x + 0.5, $this->entity->currentNode->y, $this->entity->currentNode->z + 0.5, 1.0);
if($this->entity->boundingBox->isXYZInsideNS($this->entity->currentNode->x + 0.5, $this->entity->currentNode->y, $this->entity->currentNode->z + 0.5)){
$moveX = ($this->entity->currentNode >> 16 & 0xff) + 0.5;
$moveY = $this->entity->currentNode & 0xff;
$moveZ = ($this->entity->currentNode >> 8 & 0xff) + 0.5;
$this->entity->ai->mobController->setMovingTarget($moveX + 0.5, $moveY, $moveZ + 0.5, 1.0);
if($this->entity->boundingBox->isXYZInsideNS($moveX + 0.5, $moveY, $moveZ + 0.5)){
++$this->entity->currentIndex;
console("next");
$this->entity->currentNode = null;