From dee744e7091c980dfb851e9075e3021f7df484cb Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 1 Feb 2024 07:19:59 +0300 Subject: [PATCH] simple autojump, more vanilla speed --- src/entity/Entity.php | 8 +++----- src/entity/Living.php | 12 +++++++++++- src/entity/ai/MobController.php | 15 +++++++++++---- src/entity/ai/tasks/TaskAttackPlayer.php | 6 +++--- src/entity/ai/tasks/TaskPanic.php | 8 ++++---- src/entity/ai/tasks/TaskRandomWalk.php | 8 ++++---- src/entity/animal/Chicken.php | 4 ++-- src/entity/animal/Cow.php | 5 +++-- src/entity/animal/Pig.php | 4 ++-- src/entity/animal/Sheep.php | 4 ++-- src/entity/monster/Creeper.php | 2 +- src/entity/monster/PigZombie.php | 2 +- src/entity/monster/Skeleton.php | 3 ++- src/entity/monster/Spider.php | 2 +- src/entity/monster/Zombie.php | 4 ++-- 15 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 03d536b1..23e16b43 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -666,9 +666,7 @@ class Entity extends Position $dy = $cy; $dz = $cz; $this->boundingBox->setBB($aabb1); - }//else{ TODO autojump - // $stepSuccess = true; - //} + } } @@ -762,7 +760,7 @@ class Entity extends Position $this->updateLast(); $this->updatePosition(); //TODO shouldnt be called in Entity $this->updateEntityMovement(); - + $update = false; if($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){ $this->server->api->handle("entity.move", $this); $update = true; @@ -1214,7 +1212,7 @@ class Entity extends Position $this->speedMeasure = array(0, 0, 0, 0, 0, 0, 0); } - public function getSpeed() + public function getSpeed() //TODO rename to getBaseSpeed { return $this->speed; } diff --git a/src/entity/Living.php b/src/entity/Living.php index 4bbcb5cd..c1f09d43 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -129,7 +129,7 @@ abstract class Living extends Entity implements Pathfindable{ if($this->jumping){ if(!$this->inWater){ //TODO also lava if($this->onGround && $this->jumpTicks <= 0){ - //TODO jump $this->jump(); + $this->jump(); $this->jumpTicks = 10; } }else{ @@ -165,6 +165,12 @@ abstract class Living extends Entity implements Pathfindable{ } + public function jump(){ + $this->speedY = 0.42; + + //TODO also set AirBorne? + } + public function counterUpdate(){ parent::counterUpdate(); if($this->jumpTicks > 0) --$this->jumpTicks; @@ -245,6 +251,10 @@ abstract class Living extends Entity implements Pathfindable{ $this->speedY *= 0.98; $this->speedX *= $friction; $this->speedZ *= $friction; + + if($this->isCollidedHorizontally && $this->enableAutojump){ + $this->ai->mobController->setJumping(true); //non vanilla + } } //TODO limbYaw - is it even needed? diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index 591993b7..519db655 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -23,7 +23,7 @@ class MobController protected $jumping; public $moveToX, $moveToY, $moveToZ; - public $speed; + public $speedMultiplier; public $updateMove = false; public $lookX, $lookY, $lookZ; @@ -52,14 +52,14 @@ class MobController $this->moveToX = $x; $this->moveToY = $y; $this->moveToZ = $z; - $this->speed = $speed; + $this->speedMultiplier = $speed; $this->updateMove = true; } public function setMovingOffset($x, $y, $z, $speed){ $this->moveToX = $this->entity->x + ($x); $this->moveToY = $this->entity->y + ($y); $this->moveToZ = $this->entity->z + ($z); - $this->speed = $speed; + $this->speedMultiplier = $speed; $this->updateMove = true; } @@ -103,7 +103,14 @@ class MobController if($v8 >= 2.500000277905201E-7){ //TODO convert notation $v10 = (atan2($diffZ, $diffX) * 180 / M_PI) - 90; $this->entity->yaw = self::limitAngle($this->entity->yaw, $v10, 30); - $this->entity->setAIMoveSpeed($this->speed * $this->entity->getSpeedModifer()); + $this->entity->setAIMoveSpeed($this->speedMultiplier * $this->entity->getSpeed() * $this->entity->getSpeedModifer()); + //TODO 0.8.1 doesnt seem to make 2 multiplications here + /* + * v15 = this->controlledEntity; + speedMultiplier = this->speedMultiplier; + v17 = v15->vtable->_virt_getBaseSpeed(v15); + Mob::setSpeed(v15, speedMultiplier * v17); + */ if($diffY > 0 && $diffX*$diffX + $diffZ*$diffZ < 1) $this->setJumping(true); } } diff --git a/src/entity/ai/tasks/TaskAttackPlayer.php b/src/entity/ai/tasks/TaskAttackPlayer.php index 31f357ed..cc8a4bc6 100644 --- a/src/entity/ai/tasks/TaskAttackPlayer.php +++ b/src/entity/ai/tasks/TaskAttackPlayer.php @@ -2,13 +2,13 @@ class TaskAttackPlayer extends TaskBase { - public $moveSpeed; + public $speedMultiplier; public $rangeSquared; public $attackCounter; public function __construct($speed, $range){ - $this->moveSpeed = $speed; + $this->speedMultiplier = $speed; $this->rangeSquared = $range*$range; } @@ -25,7 +25,7 @@ class TaskAttackPlayer extends TaskBase $this->reset(); return false; } - $ai->mobController->setMovingTarget($ai->entity->target->x, $ai->entity->target->y, $ai->entity->target->z, $this->moveSpeed); + $ai->mobController->setMovingTarget($ai->entity->target->x, $ai->entity->target->y, $ai->entity->target->z, $this->speedMultiplier); $ai->mobController->setLookPosition($ai->entity->target->x, $ai->entity->target->y + 0.12, $ai->entity->target->z, 10, $ai->entity->getVerticalFaceSpeed()); --$this->attackCounter; diff --git a/src/entity/ai/tasks/TaskPanic.php b/src/entity/ai/tasks/TaskPanic.php index 5793708f..a010802d 100644 --- a/src/entity/ai/tasks/TaskPanic.php +++ b/src/entity/ai/tasks/TaskPanic.php @@ -4,9 +4,9 @@ class TaskPanic extends TaskBase { protected $randX = 2, $randZ = 2; - public $moveSpeed; - public function __construct($moveSpeed){ - $this->moveSpeed = $moveSpeed; + public $speedMultiplier; + public function __construct($speedMultiplier){ + $this->speedMultiplier = $speedMultiplier; } public function onStart(EntityAI $ai) @@ -34,7 +34,7 @@ class TaskPanic extends TaskBase { --$this->selfCounter; if($this->selfCounter % 20 === 0) $this->regenerateRandXZ(); - $ai->mobController->setMovingOffset($this->randX, 0, $this->randZ, $this->moveSpeed); + $ai->mobController->setMovingOffset($this->randX, 0, $this->randZ, $this->speedMultiplier); } public function canBeExecuted(EntityAI $ai) diff --git a/src/entity/ai/tasks/TaskRandomWalk.php b/src/entity/ai/tasks/TaskRandomWalk.php index 28f8a5c2..cb9d38ee 100644 --- a/src/entity/ai/tasks/TaskRandomWalk.php +++ b/src/entity/ai/tasks/TaskRandomWalk.php @@ -3,9 +3,9 @@ class TaskRandomWalk extends TaskBase { private $x, $z; - public $moveSpeed; - public function __construct($moveSpeed){ - $this->moveSpeed = $moveSpeed; + public $speedMultiplier; + public function __construct($speedMultiplier){ + $this->speedMultiplier = $speedMultiplier; } public function onStart(EntityAI $ai) @@ -31,7 +31,7 @@ class TaskRandomWalk extends TaskBase return false; //TODO Better way: block movement } --$this->selfCounter; - $ai->mobController->setMovingOffset($this->x, 0, $this->z, $this->moveSpeed); + $ai->mobController->setMovingOffset($this->x, 0, $this->z, $this->speedMultiplier); //TODO fix $ai->mobController->moveNonInstant($this->x, 0, $this->z); } diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index 5e0c2c4b..5fd27a3a 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -11,9 +11,9 @@ class Chicken extends Animal{ $this->setName('Chicken'); $this->setSpeed(0.25); - $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAtPlayer(6)); - $this->ai->addTask(new TaskPanic(0.375)); + $this->ai->addTask(new TaskPanic(1.5)); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); } diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index 02bd7f69..fdcd4779 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -7,9 +7,10 @@ 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->ai->addTask(new TaskRandomWalk(0.2)); + $this->setSpeed(0.2); + $this->ai->addTask(new TaskRandomWalk(0.8)); $this->ai->addTask(new TaskLookAtPlayer(6)); - $this->ai->addTask(new TaskPanic(0.375)); + $this->ai->addTask(new TaskPanic(1.5)); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); } diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index 0c152f82..f307c523 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -10,9 +10,9 @@ class Pig extends Animal implements Rideable{ $this->setName("Pig"); $this->setSpeed(0.25); - $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAtPlayer(6)); - $this->ai->addTask(new TaskPanic(0.375)); + $this->ai->addTask(new TaskPanic(1.5)); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); } diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index 79e66056..3108d954 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -13,9 +13,9 @@ class Sheep extends Animal{ $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 TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAtPlayer(6)); - $this->ai->addTask(new TaskPanic(0.375)); + $this->ai->addTask(new TaskPanic(1.5)); $this->ai->addTask(new TaskEatTileGoal()); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); diff --git a/src/entity/monster/Creeper.php b/src/entity/monster/Creeper.php index 750d80e8..6d0ca6ad 100644 --- a/src/entity/monster/Creeper.php +++ b/src/entity/monster/Creeper.php @@ -12,7 +12,7 @@ class Creeper extends Monster{ $this->setSpeed(0.25); $this->timeUntilExplode = $this->isIgnited() ? self::EXPL_TIME : 0; - $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); } diff --git a/src/entity/monster/PigZombie.php b/src/entity/monster/PigZombie.php index 6be561e8..e4cc616e 100644 --- a/src/entity/monster/PigZombie.php +++ b/src/entity/monster/PigZombie.php @@ -9,7 +9,7 @@ class PigZombie extends Monster{ $this->setSpeed(0.25); $this->ai->addTask(new TaskLookAround()); - $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskSwimming()); } public function getAttackDamage(){ diff --git a/src/entity/monster/Skeleton.php b/src/entity/monster/Skeleton.php index 749f0d06..0d79e269 100644 --- a/src/entity/monster/Skeleton.php +++ b/src/entity/monster/Skeleton.php @@ -7,9 +7,10 @@ class Skeleton extends Monster{ $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); $this->setName("Skeleton"); $this->ai->removeTask("TaskAttackPlayer"); + $this->setSpeed(0.25); //$this->ai->addTask(new TaskDestroyServerPerformance()); - $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); } diff --git a/src/entity/monster/Spider.php b/src/entity/monster/Spider.php index d9adf87e..9087321f 100644 --- a/src/entity/monster/Spider.php +++ b/src/entity/monster/Spider.php @@ -7,7 +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 + $this->ai->addTask(new TaskRandomWalk(1.0)); //TODO this mob doesnt use newAI -> speed is not correct $this->ai->addTask(new TaskLookAround()); //TODO this mob doesnt use newAI $this->ai->addTask(new TaskSwimming()); } diff --git a/src/entity/monster/Zombie.php b/src/entity/monster/Zombie.php index 16153e9a..55e3d51e 100644 --- a/src/entity/monster/Zombie.php +++ b/src/entity/monster/Zombie.php @@ -8,10 +8,10 @@ class Zombie extends Monster{ $this->setName("Zombie"); $this->setSpeed(0.23); - $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskSwimming()); - $this->ai->addTask(new TaskAttackPlayer(0.25, 16)); + $this->ai->addTask(new TaskAttackPlayer(1.0, 16)); //TODO fix range? } public function getArmorValue(){