mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
better breeding, baby entities will follow their parent
This commit is contained in:
parent
eff034e897
commit
eab6573b84
10 changed files with 64 additions and 7 deletions
|
|
@ -5,6 +5,9 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
public $parent;
|
||||
public $inLove; //do NOT add it into metadata, it doesnt send it to player
|
||||
public $age;
|
||||
|
||||
public $loveTimeout;
|
||||
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setAge(isset($data["Age"]) ? $data["Age"] : 0);
|
||||
|
|
@ -48,6 +51,11 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
|
||||
public function update($now){
|
||||
parent::update($now);
|
||||
|
||||
if($this->loveTimeout > 0){
|
||||
--$this->loveTimeout;
|
||||
}
|
||||
|
||||
$age = $this->getAge() + 1; //100 - fast. debug, 1 - normal
|
||||
if($age >= 0 && $this->isBaby()){
|
||||
$this->setAge($age);
|
||||
|
|
@ -101,7 +109,7 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->isFood($slot->getID()) && $this->inLove <= 0 && !$this->isBaby()){
|
||||
if($this->isFood($slot->getID()) && $this->inLove <= 0 && !$this->isBaby() && $this->loveTimeout <= 0){
|
||||
if(($e->player->gamemode & 0x01) === SURVIVAL){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1);
|
||||
}
|
||||
|
|
|
|||
44
src/entity/ai/tasks/TaskFollowParent.php
Normal file
44
src/entity/ai/tasks/TaskFollowParent.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
class TaskFollowParent extends TaskBase
|
||||
{
|
||||
public function __construct($speed){
|
||||
$this->speedMultiplier = $speed;
|
||||
}
|
||||
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = 1;
|
||||
}
|
||||
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = 0;
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if(!$ai->entity->isBaby() || !($ai->entity->parent instanceof Entity) && $ai->entity->parent->dead){
|
||||
$this->reset();
|
||||
$ai->entity->parent = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
$dist = $ai->entity->distanceSquared($ai->entity->parent);
|
||||
|
||||
if($dist > 256 || $dist < 9){ //3-16 blocks
|
||||
$this->reset();
|
||||
return false;
|
||||
}
|
||||
$parent = $ai->entity->parent;
|
||||
|
||||
$ai->mobController->setLookPosition($parent->x, $parent->y + $parent->getEyeHeight(), $parent->z, 30, $ai->entity->getVerticalFaceSpeed());
|
||||
$ai->mobController->setMovingTarget($parent->x, $parent->y, $parent->z, $this->speedMultiplier);
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
return $ai->entity->isBaby() && !$ai->entity->parent->dead; //TODO find a new parent if the current one is dead
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -46,6 +46,9 @@ class TaskMate extends TaskBase
|
|||
//this.theAnimal.setGrowingAge(6000); TODO growing age?
|
||||
//this.targetMate.setGrowingAge(6000);
|
||||
|
||||
$ai->entity->loveTimeout = 6000;
|
||||
$entpar2->loveTimeout = 6000;
|
||||
|
||||
$ai->entity->resetInLove();
|
||||
$entpar2->resetInLove();
|
||||
$baby->setAge(-24000);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class TaskRandomWalk extends TaskBase
|
|||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if(($ai->entity instanceof Creeper && $ai->entity->isIgnited()) || $ai->isStarted("TaskTempt")) {
|
||||
if(($ai->entity instanceof Creeper && $ai->entity->isIgnited()) || $ai->isStarted("TaskTempt") || $ai->isStarted("TaskFollowParent") ) {
|
||||
$this->reset();
|
||||
return false; //TODO Better way: block movement
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ class TaskRandomWalk extends TaskBase
|
|||
if(($ai->entity instanceof Creeper && $ai->entity->isIgnited()) || $ai->entity->hasPath() || $ai->isStarted("TaskTempt") ||$ai->isStarted("TaskAttackPlayer")) {
|
||||
return false;
|
||||
} // i really need mutexBits
|
||||
return !$ai->entity->inPanic && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskEatTileGoal") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
|
||||
return !$ai->entity->inPanic && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskEatTileGoal") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskFollowParent") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class TaskTempt extends TaskBase
|
|||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if(!$this->isTargetValid($ai)){
|
||||
if(!$this->isTargetValid($ai) || $ai->entity->inPanic || $ai->isStarted("TaskMate")){
|
||||
$this->reset();
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class Chicken extends Animal{
|
|||
$this->ai->addTask(new TaskSwimming());
|
||||
$this->ai->addTask(new TaskTempt(1.0));
|
||||
$this->ai->addTask(new TaskMate(1.0));
|
||||
|
||||
$this->ai->addTask(new TaskFollowParent(1.0));
|
||||
}
|
||||
public function isFood($id){
|
||||
return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class Cow extends Animal{
|
|||
$this->ai->addTask(new TaskSwimming());
|
||||
$this->ai->addTask(new TaskTempt(1.0));
|
||||
$this->ai->addTask(new TaskMate(1.0));
|
||||
$this->ai->addTask(new TaskFollowParent(1.1));
|
||||
}
|
||||
|
||||
public function isFood($id){
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class Pig extends Animal implements Rideable{
|
|||
$this->ai->addTask(new TaskSwimming());
|
||||
$this->ai->addTask(new TaskTempt(1.0));
|
||||
$this->ai->addTask(new TaskMate(1.0));
|
||||
|
||||
$this->ai->addTask(new TaskFollowParent(1.1));
|
||||
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class Sheep extends Animal{
|
|||
$this->ai->addTask(new TaskSwimming());
|
||||
$this->ai->addTask(new TaskTempt(1.0));
|
||||
$this->ai->addTask(new TaskMate(1.0));
|
||||
$this->ai->addTask(new TaskFollowParent(1.0));
|
||||
}
|
||||
|
||||
public function createSaveData(){
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ class Vector3{
|
|||
}
|
||||
|
||||
public function distanceSquared($x = 0, $y = 0, $z = 0){
|
||||
if(($x instanceof Vector3) === true){
|
||||
if($x instanceof Vector3){
|
||||
return $this->distanceSquared($x->x, $x->y, $x->z);
|
||||
}else{
|
||||
return ($this->x - $x)*($this->x - $x) + ($this->y - $y)*($this->y - $y) + ($this->z - $z)*($this->z - $z);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue