pathfinder was changed to https://github.com/ppetermann/pathfinder (+small edits to make it work with nc)

This commit is contained in:
GameHerobrine 2022-10-20 15:48:32 +03:00
parent ae8c541452
commit 187704d96e
9 changed files with 130 additions and 44 deletions

View file

@ -1,13 +1,14 @@
<?php
class Pig extends Animal{
const TYPE = MOB_PIG;
public $pathFinder, $pathFound, $path, $server;
public $pathFinder, $pathFound, $path, $server, $pathNavigator;
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
$this->pathFinder = new AStar($this); //make it before everything else as entity class constructor sends update
$this->pathFound = false;
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic");
$this->server = ServerAPI::request();
$this->pathNavigator = new PathNavigator($this);
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.45 : 0.9);
$this->setName('Pig');
$this->update();
@ -23,17 +24,19 @@ class Pig extends Animal{
}
public function update(){
if($this->pathFound && $this->path !== false and count($this->path) > 0){
/*if($this->pathFound && $this->path !== false && count($this->path) > 0){
$this->pathFound = !$this->pathNavigator->followPath($this->path);
}else{
//$start = new MinecraftNode(round($this->x), round($this->y), round($this->z));
//$stop = $start->add(5,0,5);
//$this->path = $this->pathFinder->findPath($start, $stop); //allows diagonals, path should be ~5 blocks
$start = new MinecraftNode(ceil($this->x), ceil($this->y), ceil($this->z));
$stop = $start->add(mt_rand(-10, 10), 0, mt_rand(-10, 10));
$this->path = $this->pathFinder->findPath($start, $stop); //allows diagonals, path should be ~5 blocks
//var_dump($this->path);
$this->pathFound = true;
}
if($this->path !== false && count($this->path) > 0){
$this->pathFound = true;
}else{
$this->moveTime = 30;
}
}*/ //uncomment to enable test moving
parent::update();
}