Test Pathfinder

This commit is contained in:
GameHerobrine 2022-08-28 18:42:52 +03:00
parent 110b93837a
commit 70a36f8e6b
4 changed files with 57 additions and 4 deletions

View file

@ -67,6 +67,7 @@ class PocketMinecraftServer{
if(!defined("NO_THREADS")){
$this->asyncThread = new AsyncMultipleQueue();
}
console("[INFO] Loading extra.properties...");
$this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [
"version" => "5",

View file

@ -76,9 +76,16 @@ $sha1sum = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
require_once(FILE_PATH . "/src/math/Vector3.php");
require_once(FILE_PATH . "/src/world/Position.php");
require_once(FILE_PATH . "/src/pmf/PMF.php");
require_once(FILE_PATH . "/src/entity/Entity.php");
require_once(FILE_PATH . "/src/utils/pathfinder/PathNode.php");
require_once(FILE_PATH . "/src/utils/pathfinder/Path.php");
require_once(FILE_PATH . "/src/utils/pathfinder/PathFinder.php");
require_once(FILE_PATH . "/src/entity/Damageable.php");
require_once(FILE_PATH . "/src/entity/Breedable.php");
require_once(FILE_PATH . "/src/entity/Damageable.php");
require_once(FILE_PATH . "/src/entity/Pathfindable.php");
require_once(FILE_PATH . "/src/entity/Entity.php");
require_once(FILE_PATH . "/src/entity/Living.php");
require_once(FILE_PATH . "/src/entity/Creature.php");
require_once(FILE_PATH . "/src/entity/Ageable.php");

View file

@ -1,3 +1,6 @@
<?php
abstract class Living extends Entity implements Damageable{
abstract class Living extends Entity implements Damageable, Pathfindable{
public function getPathfinder(){ //Placeholder
return $this->pathFinder;
}
}

View file

@ -1,10 +1,14 @@
<?php
class Pig extends Animal{
const TYPE = MOB_PIG;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
public $pathFinder, $path, $server;
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic");
$this->pathFinder = new Pathfinder($this);
$this->update();
$this->server = ServerAPI::request();
//$this->server->schedule(60, array($this, "testMovement"));
//$this->setName('Pig');
$this->size = $this->isBaby() ? 0.60 : 1.1875;
}
@ -17,5 +21,43 @@ class Pig extends Animal{
array(($this->fire > 0 ? COOKED_PORKCHOP:RAW_PORKCHOP), 0, mt_rand(0,2)),
);
}
public function testMovement(){ //test movement, move 1 block each 10 seconds, looks terrible ingame
$this->pathFinder->updateEntityPos(ceil($this->x), ceil($this->y), ceil($this->z));
$this->path = $this->pathFinder->buildTo(new Vector3(ceil($this->x) + mt_rand(0,4), ceil($this->y), ceil($this->z) + mt_rand(0,4)));
$this->followPath();
}
public function followPath(){
$point = null;
if($this->path instanceof Path){
$point = $this->path->increaseIndexAndGetPoint();
}else{
$this->server->schedule(40, array($this, "testMovement"), false);
return;
}
if($point != null){
console($point);
$xDiff = $point->x - $this->x;
$zDiff = $point->z - $this->z;
console($this);
$this->move(new Vector3($xDiff, 0, $zDiff), $this->yaw, $this->pitch);
$this->updateMovement();
$this->handleUpdate($this);
$this->server->schedule(10, array($this, "followPath"), false);
}else{
$this->server->schedule(40, array($this, "testMovement"), false);
}
}
public function handleUpdate($entity){
$players = $this->server->api->player->getAll($entity->level);
$pk = new MoveEntityPacket_PosRot;
$pk->eid = $entity->eid;
$pk->x = $entity->x;
$pk->y = $entity->y;
$pk->z = $entity->z;
$pk->yaw = $entity->yaw;
$pk->pitch = $entity->pitch;
$this->server->api->player->broadcastPacket($players, $pk);
}
}