diff --git a/src/entity/Living.php b/src/entity/Living.php index 1b6ba5b6..3124197d 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -115,9 +115,14 @@ abstract class Living extends Entity implements Pathfindable{ public function updateEntityMovement(){ if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) { - $this->ai->updateTasks(); + //$this->ai->updateTasks(); } - + //if($this->onGround){ + // if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){ + // $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10); + // } + // $this->pathFollower->followPath(); + //} $this->ai->mobController->movementTick(); $this->ai->mobController->rotateTick(); diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index fbe744fc..342fb168 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -49,7 +49,13 @@ class MobController public function isRotationCompleted(){ return $this->finalHeadYaw === $this->entity->headYaw; } - + public function setMovingTarget($x, $y, $z, $speed){ + $this->moveToX = $x; + $this->moveToY = $y; + $this->moveToZ = $z; + $this->speed = $speed; + $this->updateMove = true; + } public function setMovingOffset($x, $y, $z, $speed){ $this->moveToX = $this->entity->x + ($x); $this->moveToY = $this->entity->y + ($y); diff --git a/src/entity/ai/path/PathFollower.php b/src/entity/ai/path/PathFollower.php index 24545186..fa462b7e 100644 --- a/src/entity/ai/path/PathFollower.php +++ b/src/entity/ai/path/PathFollower.php @@ -13,13 +13,18 @@ class PathFollower{ public function followPath(){ if(!isset($this->entity) || !($this->entity instanceof Living)) return; + if(!$this->entity->hasPath()) return; - if($this->entity->path != null && (is_array($this->entity->path) && count($this->entity->path) <= 0 || $this->entity->currentIndex >= count($this->entity->path))){ - $this->entity->path = null; - $this->entity->currentIndex = 0; - $this->entity->currentNode = false; - }elseif($this->entity->path != null && ($this->entity->currentNode == false || $this->entity->boundingBox->isXYZInside($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z) || $this->entity->ai->mobController->moveTo($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z) === false)){ - $this->entity->currentNode = $this->entity->path[$this->entity->currentIndex++]; + if($this->entity->currentNode == null){ + $this->entity->currentNode = $this->entity->path[$this->entity->currentIndex]; + } + + $this->entity->ai->mobController->setMovingTarget($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z, 0.25); + console($this->entity->currentNode.":".$this->entity->boundingBox); + if($this->entity->boundingBox->isXYZInsideNS($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z)){ + ++$this->entity->currentIndex; + console("next"); + $this->entity->currentNode = null; } } diff --git a/src/entity/ai/tasks/TaskLookAround.php b/src/entity/ai/tasks/TaskLookAround.php index 78d342bd..bb25edc5 100644 --- a/src/entity/ai/tasks/TaskLookAround.php +++ b/src/entity/ai/tasks/TaskLookAround.php @@ -2,31 +2,29 @@ class TaskLookAround extends TaskBase { - private $rotation; + public $lookOffsetX, $lookOffsetZ; + public function onStart(EntityAI $ai) { - $this->selfCounter = 1; - $this->rotation = mt_rand(-120, 120); + $this->selfCounter = 20 + lcg_value(); + $v = (M_PI * 2) * lcg_value(); + $this->lookOffsetX = cos($v); + $this->lookOffsetZ = sin($v); } public function onEnd(EntityAI $ai) { - $ai->entity->idleTime = mt_rand(20, 40); + //$ai->entity->idleTime = mt_rand(20, 40); } public function canBeExecuted(EntityAI $ai) { return !$ai->entity->inPanic && !$ai->entity->isMoving() && lcg_value() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath(); /*Vanilla value*/ } - + public function onUpdate(EntityAI $ai) { - if($this->rotation === 0){ - $this->selfCounter = 0; - } - $v = min(Utils::getSign($this->rotation) * 10, $this->rotation); - $ai->entity->headYaw += $v; - $this->rotation -= $v; - + --$this->selfCounter; + $ai->mobController->setLookPosition($ai->entity->x + $this->lookOffsetX, $ai->entity->y + $ai->entity->getEyeHeight(), $ai->entity->z + $this->lookOffsetZ, 10, $ai->entity->getVerticalFaceSpeed()); } } diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index 4d3dafe5..d1049460 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -14,6 +14,7 @@ class Chicken extends Animal{ $this->ai->addTask(new TaskRandomWalk(0.25)); $this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskPanic(0.375)); + $this->ai->addTask(new TaskLookAround()); } public function isFood($id){ return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS; diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index baff016b..ed592207 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -10,6 +10,9 @@ class Cow extends Animal{ $this->ai->addTask(new TaskRandomWalk(0.2)); $this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskPanic(0.375)); + $this->ai->addTask(new TaskLookAround()); + + //$this->ai->addTask(new TaskSwimming()); } public function isFood($id){ diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index 3083da60..a69bdfd3 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -13,7 +13,7 @@ class Pig extends Animal implements Rideable{ $this->ai->addTask(new TaskRandomWalk(0.25)); $this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskPanic(0.375)); - + $this->ai->addTask(new TaskLookAround()); } /** * @return boolean diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index ecaba25e..2b002cf4 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -17,7 +17,7 @@ class Sheep extends Animal{ $this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskPanic(0.375)); $this->ai->addTask(new TaskEatTileGoal()); - + $this->ai->addTask(new TaskLookAround()); } public function createSaveData(){ diff --git a/src/entity/monster/Creeper.php b/src/entity/monster/Creeper.php index 68b67f80..93011ba9 100644 --- a/src/entity/monster/Creeper.php +++ b/src/entity/monster/Creeper.php @@ -13,6 +13,7 @@ class Creeper extends Monster{ $this->timeUntilExplode = $this->isIgnited() ? self::EXPL_TIME : 0; $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskLookAround()); } public function getAttackDamage(){ diff --git a/src/entity/monster/PigZombie.php b/src/entity/monster/PigZombie.php index bfc5371c..1e8878c9 100644 --- a/src/entity/monster/PigZombie.php +++ b/src/entity/monster/PigZombie.php @@ -7,6 +7,9 @@ class PigZombie extends Monster{ $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic"); $this->setName("Pigman"); $this->setSpeed(0.25); + + $this->ai->addTask(new TaskLookAround()); + $this->ai->addTask(new TaskRandomWalk(0.25)); } public function getAttackDamage(){ return 5; diff --git a/src/entity/monster/Skeleton.php b/src/entity/monster/Skeleton.php index b9a0344e..46471322 100644 --- a/src/entity/monster/Skeleton.php +++ b/src/entity/monster/Skeleton.php @@ -10,6 +10,7 @@ class Skeleton extends Monster{ //$this->ai->addTask(new TaskDestroyServerPerformance()); $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskLookAround()); } public function getAttackDamage(){ diff --git a/src/entity/monster/Spider.php b/src/entity/monster/Spider.php index 6af9c1c5..69dab308 100644 --- a/src/entity/monster/Spider.php +++ b/src/entity/monster/Spider.php @@ -8,6 +8,7 @@ class Spider extends Monster{ $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 TaskLookAround()); //TODO this mob doesnt use newAI } public function getDrops(){ diff --git a/src/entity/monster/Zombie.php b/src/entity/monster/Zombie.php index 1497f048..0364f6f5 100644 --- a/src/entity/monster/Zombie.php +++ b/src/entity/monster/Zombie.php @@ -9,6 +9,7 @@ class Zombie extends Monster{ $this->setSpeed(0.23); $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskLookAround()); } public function getArmorValue(){ diff --git a/src/math/AxisAlignedBB.php b/src/math/AxisAlignedBB.php index 93026a4f..7eba2e67 100644 --- a/src/math/AxisAlignedBB.php +++ b/src/math/AxisAlignedBB.php @@ -188,7 +188,16 @@ class AxisAlignedBB{ public function intersectsWith(AxisAlignedBB $bb){ return $bb->maxX > $this->minX and $bb->minX < $this->maxX && $bb->maxZ > $this->minZ and $bb->minZ < $this->maxZ && $bb->maxY > $this->minY and $bb->minY < $this->maxY; } - + public function isXYZInsideNS($x, $y, $z){ + if($x < $this->minX or $x > $this->maxX){ + return false; + } + if($y < $this->minY or $y > $this->maxY){ + return false; + } + + return $z > $this->minZ and $z < $this->maxZ; + } public function isXYZInside($x, $y, $z){ if($x <= $this->minX or $x >= $this->maxX){ return false;