mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 04:29:43 +00:00
baby sheep color is based on its parents colours
This commit is contained in:
parent
d990c7c6b3
commit
f36ab5aa6c
4 changed files with 19 additions and 6 deletions
|
|
@ -61,9 +61,9 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
||||||
return $this->getAge() < 0;
|
return $this->getAge() < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function breed(){
|
public function breed($mate){
|
||||||
if($this->server->dhandle("entity.animal.breed", ["parent" => $this]) !== false){
|
if($this->server->dhandle("entity.animal.breed", ["parent" => $this, "parent2" => $mate]) !== false){
|
||||||
$c = $this->spawnChild();
|
$c = $this->spawnChild($mate);
|
||||||
$c->parent = $this; //TODO save eid to avoid memory leaks?
|
$c->parent = $this; //TODO save eid to avoid memory leaks?
|
||||||
$this->server->api->entity->spawnToAll($c);
|
$this->server->api->entity->spawnToAll($c);
|
||||||
return $c;
|
return $c;
|
||||||
|
|
@ -108,7 +108,7 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
||||||
$this->age = $i;
|
$this->age = $i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function spawnChild()
|
public function spawnChild($mate)
|
||||||
{
|
{
|
||||||
return $this->server->api->entity->add($this->level, $this->class, $this->type, [
|
return $this->server->api->entity->add($this->level, $this->class, $this->type, [
|
||||||
"x" => $this->x + lcg_value() * mt_rand(-1, 1),
|
"x" => $this->x + lcg_value() * mt_rand(-1, 1),
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
interface Breedable{
|
interface Breedable{
|
||||||
public function isFood($id); //original name
|
public function isFood($id); //original name
|
||||||
|
|
||||||
public function spawnChild();
|
public function spawnChild($mate);
|
||||||
|
|
||||||
public function isInLove();
|
public function isInLove();
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +43,7 @@ class TaskMate extends TaskBase
|
||||||
/**
|
/**
|
||||||
* @var Animal $baby
|
* @var Animal $baby
|
||||||
*/
|
*/
|
||||||
$baby = $ai->entity->breed();
|
$baby = $ai->entity->breed($entpar2);
|
||||||
//this.theAnimal.setGrowingAge(6000); TODO growing age?
|
//this.theAnimal.setGrowingAge(6000); TODO growing age?
|
||||||
//this.targetMate.setGrowingAge(6000);
|
//this.targetMate.setGrowingAge(6000);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,19 @@ class Sheep extends Animal{
|
||||||
$this->ai->addTask(new TaskFollowParent(1.0));
|
$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(){
|
public function createSaveData(){
|
||||||
$data = parent::createSaveData();
|
$data = parent::createSaveData();
|
||||||
$data["Color"] = @$this->data["Color"];
|
$data["Color"] = @$this->data["Color"];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue