tweaks to pathfinder and pathfollower(basically nothing)

This commit is contained in:
GameHerobrine 2024-04-14 03:41:24 +03:00
parent da28b3b0ff
commit cb0fa06e12
5 changed files with 94 additions and 25 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 ManhattanHeuristic3D());
$this->pathFinder = new TileNavigator(new MCBlockedProvider(), new MCDiagonalProvider(), new Pythagoras3D());
$this->pathFollower = new PathFollower($this);
parent::__construct($level, $eid, $class, $type, $data);
$this->canBeAttacked = true;
@ -113,16 +113,50 @@ abstract class Living extends Entity implements Pathfindable{
parent::update($now);
}
public $pathEIDS = [];
private static $lastPathEID = 10000000;
public static $pathfind = true;
public function updateEntityMovement(){
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
$this->ai->updateTasks();
}
//if($this->onGround){
// if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
// $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10);
// }
// $this->pathFollower->followPath();
//}
/*if($this->onGround){
if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
$me = new PathTileXYZ($this->x, $this->y, $this->z, $this->level);
//$target = new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level);
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);
}
if(self::$pathfind){
$this->path = $this->pathFinder->navigate($me, $target, 10);
}
if($this->path){
console("Found path to $target from $me of length ".count($this->path));
foreach($this->path as $node){
$eid = self::$lastPathEID++;
$this->pathEIDS[] = $eid;
$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->yaw = $pk->pitch = 0;
$pk->roll = 0;
foreach($this->level->players as $player){
$player->dataPacket($pk);
}
}
}
}
$this->pathFollower->followPath();
}*/
//not exactly here

View file

@ -19,13 +19,29 @@ class PathFollower{
$this->entity->currentNode = $this->entity->path[$this->entity->currentIndex];
}
$this->entity->ai->mobController->setMovingTarget($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z, 0.25);
console($this->entity->currentNode.":".$this->entity->boundingBox);
if($this->entity->boundingBox->isXYZInsideNS($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z)){
$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)){
++$this->entity->currentIndex;
console("next");
$this->entity->currentNode = null;
}
if($this->entity->currentIndex >= count($this->entity->path)){
console("path finished.");
$this->entity->currentNode = null;
$this->entity->path = null;
$this->entity->currentIndex = 0;
foreach($this->entity->pathEIDS as $eid){
$pk = new RemoveEntityPacket();
$pk->eid = $eid;
foreach($this->entity->level->players as $player){
$player->dataPacket($pk);
}
}
}
}
}