diff --git a/src/dependencies.php b/src/dependencies.php index 9b9383a0..1388012e 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -97,6 +97,7 @@ 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/entity/Damageable.php"); +require_once(FILE_PATH."/src/entity/Breedable.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"); diff --git a/src/entity/Animal.php b/src/entity/Animal.php index c6fc9641..063ceef9 100644 --- a/src/entity/Animal.php +++ b/src/entity/Animal.php @@ -3,7 +3,7 @@ TODO: move methods */ -class Animal extends Creature implements Ageable{ +abstract class Animal extends Creature implements Ageable, Breedable{ public function isBaby(){ return $this->data["IsBaby"]; } diff --git a/src/entity/Breedable.php b/src/entity/Breedable.php new file mode 100644 index 00000000..b6bd1467 --- /dev/null +++ b/src/entity/Breedable.php @@ -0,0 +1,5 @@ +schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg")); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:4, "generic"); + $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic"); $this->update(); //$this->setName('Chicken'); $this->size = $this->isBaby() ? 0.35 : 0.7; } - + public function isFood($id){ + return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS; + } public function dropAnEgg(){ 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, array($this, "dropAnEgg")); diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index 15782589..08501949 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -9,7 +9,9 @@ class Cow extends Animal{ //$this->setName('Cow'); $this->size = $this->isBaby() ? 0.65 : 1.4; } - + public function isFood($id){ + return $id === WHEAT; + } public function getDrops(){ return $this->isBaby() ? array() : diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index 5d7c5088..19bcc6ee 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -8,7 +8,9 @@ class Pig extends Animal{ //$this->setName('Pig'); $this->size = $this->isBaby() ? 0.60 : 1.1875; } - + public function isFood($id){ + return $id === POTATO || $id === CARROT || $id === BEETROOT; + } public function getDrops(){ return $this->isBaby() ? array() : array( diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index a01b4e15..ae03247b 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -16,6 +16,11 @@ class Sheep extends Animal{ array(WOOL, $this->data["Color"] & 0x0F, 1), ); } + + public function isFood($id){ + return $id === WHEAT; + } + public function getMetadata(){ $d = parent::getMetadata(); if(!isset($this->data["Sheared"])){