mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
rewrite of entity save system
This commit is contained in:
parent
2bae9d8f42
commit
3af7ee98b4
8 changed files with 93 additions and 108 deletions
|
|
@ -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(){
|
||||
|
|
|
|||
|
|
@ -18,6 +18,13 @@ class Sheep extends Animal{
|
|||
}
|
||||
}
|
||||
|
||||
public function createSaveData(){
|
||||
$data = parent::createSaveData();
|
||||
$data["Color"] = @$this->data["Color"];
|
||||
$data["Sheared"] = @$this->data["Sheared"];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function eatGrass(){
|
||||
$downBlock = $this->level->getBlock(new Vector3($this->x, $this->y-1, $this->z));
|
||||
if($downBlock->getID() !== GRASS){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue