rewrite of entity save system

This commit is contained in:
GameHerobrine 2022-11-13 01:53:06 +03:00
parent 2bae9d8f42
commit 3af7ee98b4
8 changed files with 93 additions and 108 deletions

View file

@ -2,24 +2,32 @@
class Chicken extends Animal{
const TYPE = MOB_CHICKEN;
public $timeUntilEgg;
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->server->schedule(mt_rand(0,6000) + 6000, [$this, "dropAnEgg"]);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
$this->setName('Chicken');
$this->setSize($this->isBaby() ? 0.2 : 0.4, $this->isBaby() ? 0.35 : 0.7);
$this->setSpeed(0.25);
$this->timeUntilEgg = mt_rand(0,6000) + 6000;
$this->update();
}
public function isFood($id){
return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS;
}
public function update(){
if($this->timeUntilEgg-- <= 0){
$this->dropAnEgg();
$this->timeUntilEgg = mt_rand(0,6000) + 6000;
}
}
public function dropAnEgg(){
if($this->closed){
return;
}
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(EGG, 0, 1));
$this->server->schedule(mt_rand(0,6000) + 6000, [$this, "dropAnEgg"]);
}
public function getDrops(){