mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
pathfinder rewrite
This commit is contained in:
parent
cb0fa06e12
commit
22f3c3f640
16 changed files with 89 additions and 263 deletions
|
|
@ -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){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue