From 6f54da56ba3819ca360006b98838e4598d7936cd Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 17 Jan 2023 20:29:19 +0300 Subject: [PATCH] mobs should swim now --- src/entity/Creature.php | 3 +-- src/entity/Entity.php | 7 +++--- src/entity/ai/tasks/TaskSwimming.php | 34 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/entity/ai/tasks/TaskSwimming.php diff --git a/src/entity/Creature.php b/src/entity/Creature.php index 822229ce..6e5d1b98 100644 --- a/src/entity/Creature.php +++ b/src/entity/Creature.php @@ -16,8 +16,7 @@ abstract class Creature extends Living{ $this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskRandomWalk()); $this->ai->addTask(new TaskLookAtPlayer()); - - + $this->ai->addTask(new TaskSwimming()); } public function createSaveData(){ diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 2ae0ee6a..e5bfa456 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -72,7 +72,7 @@ class Entity extends Position public $inAction = false; public $hasKnockback; - public $onGround; + public $onGround, $inWater; function __construct(Level $level, $eid, $class, $type = 0, $data = array()) { @@ -558,7 +558,7 @@ class Entity extends Position if(Utils::in_range($this->speedY, -0.007, 0.007)){ $this->speedY = 0; } - + $this->inWater = false; if($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT)){ $aABB = $this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ); $x0 = floor($aABB->minX); @@ -594,6 +594,7 @@ class Entity extends Position $this->air -= 1; $waterDone = true; $this->updateMetadata(); + $this->inWater = true; $hasUpdate = true; } break; @@ -646,7 +647,7 @@ class Entity extends Position } - + if($this->speedX != 0){ $this->x += $this->speedX; $this->speedX -= $this->speedX * $drag; diff --git a/src/entity/ai/tasks/TaskSwimming.php b/src/entity/ai/tasks/TaskSwimming.php new file mode 100644 index 00000000..2bf1b910 --- /dev/null +++ b/src/entity/ai/tasks/TaskSwimming.php @@ -0,0 +1,34 @@ +selfCounter = 1; + } + + public function onEnd(EntityAI $ai) + { + + } + + public function onUpdate(EntityAI $ai) + { + if(!$ai->entity->inWater){ + $this->reset(); + } + + if(Utils::randomFloat() < 0.8){ #1.5.2 method + $ai->entity->speedY = 0.42; + } + + + } + + public function canBeExecuted(EntityAI $ai) + { + return $ai->entity->inWater; + } + +} +