From f36ab5aa6c7d1f54371145cdca02a9ea84f3f500 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 10 Jan 2026 23:32:19 +0300 Subject: [PATCH] baby sheep color is based on its parents colours --- src/entity/Animal.php | 8 ++++---- src/entity/Breedable.php | 2 +- src/entity/ai/tasks/TaskMate.php | 2 +- src/entity/animal/Sheep.php | 13 +++++++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/entity/Animal.php b/src/entity/Animal.php index 1f2bc748..f4098922 100644 --- a/src/entity/Animal.php +++ b/src/entity/Animal.php @@ -61,9 +61,9 @@ abstract class Animal extends Creature implements Ageable, Breedable{ return $this->getAge() < 0; } - public function breed(){ - if($this->server->dhandle("entity.animal.breed", ["parent" => $this]) !== false){ - $c = $this->spawnChild(); + public function breed($mate){ + if($this->server->dhandle("entity.animal.breed", ["parent" => $this, "parent2" => $mate]) !== false){ + $c = $this->spawnChild($mate); $c->parent = $this; //TODO save eid to avoid memory leaks? $this->server->api->entity->spawnToAll($c); return $c; @@ -108,7 +108,7 @@ abstract class Animal extends Creature implements Ageable, Breedable{ $this->age = $i; } - public function spawnChild() + public function spawnChild($mate) { return $this->server->api->entity->add($this->level, $this->class, $this->type, [ "x" => $this->x + lcg_value() * mt_rand(-1, 1), diff --git a/src/entity/Breedable.php b/src/entity/Breedable.php index 59cc21ec..39c1ae6b 100644 --- a/src/entity/Breedable.php +++ b/src/entity/Breedable.php @@ -3,7 +3,7 @@ interface Breedable{ public function isFood($id); //original name - public function spawnChild(); + public function spawnChild($mate); public function isInLove(); } \ No newline at end of file diff --git a/src/entity/ai/tasks/TaskMate.php b/src/entity/ai/tasks/TaskMate.php index 9aa7c584..71480b0c 100644 --- a/src/entity/ai/tasks/TaskMate.php +++ b/src/entity/ai/tasks/TaskMate.php @@ -43,7 +43,7 @@ class TaskMate extends TaskBase /** * @var Animal $baby */ - $baby = $ai->entity->breed(); + $baby = $ai->entity->breed($entpar2); //this.theAnimal.setGrowingAge(6000); TODO growing age? //this.targetMate.setGrowingAge(6000); diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index 4ce3e6ab..f651bcd7 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -24,6 +24,19 @@ class Sheep extends Animal{ $this->ai->addTask(new TaskFollowParent(1.0)); } + public function spawnChild($mate) + { + $child = parent::spawnChild($mate); + if($child instanceof Sheep){ + if($mate instanceof Sheep){ + $child->setColor(mt_rand(0, 1) == 0 ? $this->getColor() : $mate->getColor()); + }else{ + $child->setColor($this->getColor()); + } + } + return $child; + } + public function createSaveData(){ $data = parent::createSaveData(); $data["Color"] = @$this->data["Color"];