mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
Entity collisions, bounding boxes for entites and blocks
This commit is contained in:
parent
9154c0fc3d
commit
1448fd21b9
19 changed files with 265 additions and 118 deletions
|
|
@ -7,9 +7,9 @@ class Chicken extends Animal{
|
|||
$server = ServerAPI::request();
|
||||
$server->schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg"));
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
|
||||
$this->update();
|
||||
$this->setName('Chicken');
|
||||
$this->size = $this->isBaby() ? 0.35 : 0.7;
|
||||
$this->setSize($this->isBaby() ? 0.2 : 0.4, $this->isBaby() ? 0.35 : 0.7);
|
||||
$this->update();
|
||||
}
|
||||
public function isFood($id){
|
||||
return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ class Cow extends Animal{
|
|||
const TYPE = MOB_COW;
|
||||
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->update();
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
|
||||
$this->setSize($this->isBaby() ? 0.45 : 0.9 , $this->isBaby() ? 0.7 : 1.4);
|
||||
$this->setName('Cow');
|
||||
$this->size = $this->isBaby() ? 0.65 : 1.4;
|
||||
$this->update();
|
||||
}
|
||||
public function isFood($id){
|
||||
return $id === WHEAT;
|
||||
|
|
|
|||
|
|
@ -5,12 +5,10 @@ class Pig extends Animal{
|
|||
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->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.45 : 0.9);
|
||||
$this->setName('Pig');
|
||||
$this->size = $this->isBaby() ? 0.60 : 1.1875;
|
||||
$this->update();
|
||||
}
|
||||
public function isFood($id){
|
||||
return $id === POTATO || $id === CARROT || $id === BEETROOT;
|
||||
|
|
@ -21,43 +19,4 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ class Sheep extends Animal{
|
|||
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"] : 8, "generic");
|
||||
$this->update();
|
||||
$this->setName('Sheep');
|
||||
$this->size = $this->isBaby() ? 0.65 : 1.3;
|
||||
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.675 : 1.3);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue