From 46898097942f00ce2faa1241e9c66b7bc94d4afd Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 9 Jan 2024 09:26:02 +0300 Subject: [PATCH] randomwalking for all mobs --- src/entity/Creature.php | 2 +- src/entity/Monster.php | 2 +- src/entity/ai/tasks/TaskRandomWalk.php | 2 +- src/entity/animal/Chicken.php | 17 +++++++++++++---- src/entity/animal/Cow.php | 2 +- src/entity/animal/Sheep.php | 3 +++ src/entity/monster/Creeper.php | 2 ++ src/entity/monster/Skeleton.php | 3 ++- src/entity/monster/Spider.php | 1 + src/entity/monster/Zombie.php | 2 ++ 10 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/entity/Creature.php b/src/entity/Creature.php index 84fec613..5aacff56 100644 --- a/src/entity/Creature.php +++ b/src/entity/Creature.php @@ -24,7 +24,7 @@ abstract class Creature extends Living{ } public function getSpeedModifer(){ - return $this->speedModifer; + return 0.7; //$this->speedModifer; //should be 0.7? } public function getArmorValue(){ return 2; diff --git a/src/entity/Monster.php b/src/entity/Monster.php index 969de944..c9831eba 100644 --- a/src/entity/Monster.php +++ b/src/entity/Monster.php @@ -2,7 +2,7 @@ class Monster extends Creature{ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); - $this->ai->addTask(new TaskAttackPlayer()); + //$this->ai->addTask(new TaskAttackPlayer()); } public function getAttackDamage(){ diff --git a/src/entity/ai/tasks/TaskRandomWalk.php b/src/entity/ai/tasks/TaskRandomWalk.php index 05aac7f7..685af3c5 100644 --- a/src/entity/ai/tasks/TaskRandomWalk.php +++ b/src/entity/ai/tasks/TaskRandomWalk.php @@ -5,7 +5,7 @@ class TaskRandomWalk extends TaskBase private $x, $z; public $moveSpeed; public function __construct($moveSpeed){ - $this->moveSpeed = 0.25; + $this->moveSpeed = $moveSpeed; } public function onStart(EntityAI $ai) diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index 7d60201a..d775a94c 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -10,19 +10,28 @@ class Chicken extends Animal{ $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic"); $this->setName('Chicken'); $this->setSpeed(0.25); + + $this->ai->addTask(new TaskRandomWalk(0.25)); } public function isFood($id){ return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS; } + public function updateEntityMovement(){ + parent::updateEntityMovement(); + + if($this->onGround && $this->speedY < 0) $this->speedY *= 0.6; + + if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){ + $this->dropAnEgg(); + $this->timeUntilEgg = mt_rand(0,6000) + 6000; + } + } + public function fall(){} //chickens have no fall dmg? public function update($now){ parent::update($now); - if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){ - $this->dropAnEgg(); - $this->timeUntilEgg = mt_rand(0,6000) + 6000; - } } public function dropAnEgg(){ diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index 814251ac..b185db20 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -7,7 +7,7 @@ class Cow extends Animal{ parent::__construct($level, $eid, $class, $type, $data); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); $this->setName("Cow"); - $this->setSpeed(0.2); + $this->ai->addTask(new TaskRandomWalk(0.2)); } public function isFood($id){ diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index f1957bf7..720b88b3 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -12,7 +12,10 @@ class Sheep extends Animal{ $this->data["Sheared"] = isset($this->data["Sheared"]) ? $this->data["Sheared"] : 0; $this->data["Color"] = isset($this->data["Color"]) ? $this->data["Color"] : $this->sheepColor(); $this->setSpeed(0.25); + + $this->ai->addTask(new TaskRandomWalk(0.25)); //in 1.5.2 it is 0.23, but according to ida it should be 1.0 which is 0.25 if converted to 1.5.2? $this->ai->addTask(new TaskEatTileGoal()); + } public function createSaveData(){ diff --git a/src/entity/monster/Creeper.php b/src/entity/monster/Creeper.php index c1c5c38d..68b67f80 100644 --- a/src/entity/monster/Creeper.php +++ b/src/entity/monster/Creeper.php @@ -11,6 +11,8 @@ class Creeper extends Monster{ $this->ignited = 0; $this->setSpeed(0.25); $this->timeUntilExplode = $this->isIgnited() ? self::EXPL_TIME : 0; + + $this->ai->addTask(new TaskRandomWalk(0.25)); } public function getAttackDamage(){ diff --git a/src/entity/monster/Skeleton.php b/src/entity/monster/Skeleton.php index 23a23d13..b9a0344e 100644 --- a/src/entity/monster/Skeleton.php +++ b/src/entity/monster/Skeleton.php @@ -8,7 +8,8 @@ class Skeleton extends Monster{ $this->setName("Skeleton"); $this->ai->removeTask("TaskAttackPlayer"); //$this->ai->addTask(new TaskDestroyServerPerformance()); - $this->setSpeed(0.25); + + $this->ai->addTask(new TaskRandomWalk(0.25)); } public function getAttackDamage(){ diff --git a/src/entity/monster/Spider.php b/src/entity/monster/Spider.php index 2c078b92..6af9c1c5 100644 --- a/src/entity/monster/Spider.php +++ b/src/entity/monster/Spider.php @@ -7,6 +7,7 @@ class Spider extends Monster{ $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic"); $this->setName("Spider"); $this->setSpeed(0.3); + $this->ai->addTask(new TaskRandomWalk(0.25)); //TODO this mob doesnt use newAI -> speed is not correct } public function getDrops(){ diff --git a/src/entity/monster/Zombie.php b/src/entity/monster/Zombie.php index f34e1bbf..1497f048 100644 --- a/src/entity/monster/Zombie.php +++ b/src/entity/monster/Zombie.php @@ -7,6 +7,8 @@ class Zombie extends Monster{ $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic"); $this->setName("Zombie"); $this->setSpeed(0.23); + + $this->ai->addTask(new TaskRandomWalk(0.25)); } public function getArmorValue(){