diff --git a/src/entity/Entity.php b/src/entity/Entity.php index f31ff819..ec0e9af1 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -84,6 +84,8 @@ class Entity extends Position public $stepHeight = 0.5; public $enableAutojump = false; + public $yOffset = 0.0; + public $noClip = false; function __construct(Level $level, $eid, $class, $type = 0, $data = array()) { $this->random = new Random(); @@ -552,7 +554,7 @@ class Entity extends Position $this->boundingBox->offset($dx, $dy, $dz); $fallingFlag = $this->onGround || $savedDY != $dy && $savedDY < 0; - if($this->stepHeight > 0 && $fallingFlag && /*($this->ySize < 0.05) && TODO ySuze*/ ($savedDX != $dx || $savedDZ != $dz)){ + if($this->stepHeight > 0 && $fallingFlag && ($savedDX != $dx || $savedDZ != $dz)){ $cx = $dx; $cy = $dy; $cz = $dz; @@ -600,7 +602,7 @@ class Entity extends Position //TODO step $this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2; - $this->y = $this->boundingBox->minY; //TODO + $this->yOffset - //TODO $this->ySize; + $this->y = $this->boundingBox->minY + $this->yOffset;// - //TODO - used when player is sneaking $this->ySize; $this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2; //$this.isCollidedHorizontally = savedDX != dx || savedDZ != dz; //$this.isCollidedVertically = savedDY != dy; diff --git a/src/entity/Living.php b/src/entity/Living.php index 0f7011cd..1b6ba5b6 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -36,8 +36,11 @@ abstract class Living extends Entity implements Pathfindable{ return $this->aiMoveSpeed; } + public function getVerticalFaceSpeed(){ + return 40; //unused in 0.8 but may be useful in 0.9/0.10 + } + public function setAIMoveSpeed($speed){ - console("set spedd to $speed"); $this->aiMoveSpeed = $speed; $this->moveForward = $speed; } @@ -182,7 +185,6 @@ abstract class Living extends Entity implements Pathfindable{ } //TODO onLadder - console($this->speedY); $this->move($this->speedX, $this->speedY, $this->speedZ); //TODO onLadder + isCollidedHorizonatlly => speedY = 0.2 diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index 86725b9a..fbe744fc 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -26,6 +26,9 @@ class MobController public $moveToX, $moveToY, $moveToZ; public $speed; public $updateMove = false; + + public $lookX, $lookY, $lookZ; + public $deltaLookYaw, $deltaLookPitch; public $isLooking = false; @@ -132,7 +135,17 @@ class MobController $this->entity->pitch = 0; if($this->isLooking){ $this->isLooking = false; - //TODO + + $diffX = $this->lookX - $this->entity->x; + $diffY = $this->lookY - ($this->entity->y + $this->entity->getEyeHeight()); + $diffZ = $this->lookZ - $this->entity->z; + $distance = sqrt($diffX*$diffX + $diffZ*$diffZ); + + $v9 = (atan2($diffZ, $diffX)*180 / M_PI) - 90; + $v10 = -(atan2($diffY, $distance)*180 / M_PI); + + $this->entity->pitch = self::limitAngle($this->entity->pitch, $v10, $this->deltaLookPitch); + $this->entity->headYaw = self::limitAngle($this->entity->headYaw, $v9, $this->deltaLookYaw); }else{ $this->entity->headYaw = self::limitAngle($this->entity->headYaw, $this->entity->renderYawOffset, 10); } @@ -160,8 +173,13 @@ class MobController //$this->entity->headYaw = Utils::wrapAngleTo360($this->entity->headYaw + $w180min); } - public function moveTo($x, $y, $z, $camera = true){ - //TODO fix return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z), $camera); + public function setLookPosition($posX, $posY, $posZ, $lookYaw, $lookPitch){ + $this->lookX = $posX; + $this->lookY = $posY; + $this->lookZ = $posZ; + $this->deltaLookYaw = $lookYaw; + $this->deltaLookPitch = $lookPitch; + $this->isLooking = true; } public function faceEntity($x, $y, $z){ diff --git a/src/entity/ai/tasks/TaskLookAtPlayer.php b/src/entity/ai/tasks/TaskLookAtPlayer.php index aa8ab776..522bcc8b 100644 --- a/src/entity/ai/tasks/TaskLookAtPlayer.php +++ b/src/entity/ai/tasks/TaskLookAtPlayer.php @@ -2,7 +2,11 @@ class TaskLookAtPlayer extends TaskBase{ public $target = false; - private $state, $yaw, $pitch; + public $distance; + public function __construct($distance){ + $this->distance = $distance; + } + public function canBeExecuted(EntityAI $ai){ return !$ai->entity->inPanic && lcg_value() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskMate") && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->isStarted("TaskPanic") && !$ai->entity->hasPath(); } @@ -37,14 +41,13 @@ class TaskLookAtPlayer extends TaskBase{ } public function onStart(EntityAI $ai){ - $this->target = $this->findTarget($ai->entity, 6); //TODO max distance for different mobs + $this->target = $this->findTarget($ai->entity, $this->distance); if(!($this->target instanceof Entity) || !$this->target->isPlayer()){ $this->reset(); $this->onEnd($ai); return; } - $this->yaw = $ai->entity->yaw; - $this->pitch = $ai->entity->pitch; + $this->selfCounter = mt_rand(20, 60); } @@ -54,6 +57,7 @@ class TaskLookAtPlayer extends TaskBase{ $this->onEnd($ai); return; } + $ai->mobController->setLookPosition($this->target->x, $this->target->y + $this->target->getEyeHeight(), $this->target->z, 10, $ai->entity->getVerticalFaceSpeed()); $ai->mobController->lookOn($this->target); $this->selfCounter--; } diff --git a/src/entity/ai/tasks/TaskPanic.php b/src/entity/ai/tasks/TaskPanic.php index 55c426d5..5793708f 100644 --- a/src/entity/ai/tasks/TaskPanic.php +++ b/src/entity/ai/tasks/TaskPanic.php @@ -3,6 +3,12 @@ class TaskPanic extends TaskBase { protected $randX = 2, $randZ = 2; + + public $moveSpeed; + public function __construct($moveSpeed){ + $this->moveSpeed = $moveSpeed; + } + public function onStart(EntityAI $ai) { $this->selfCounter = 60; @@ -16,8 +22,8 @@ class TaskPanic extends TaskBase } public function regenerateRandXZ(){ - $this->randX = (mt_rand(0, 1) ? -1 : 1) * 2; - $this->randZ = (mt_rand(0, 1) ? -1 : 1) * 2; + $this->randX = (mt_rand(0, 1) ? -1 : 1); + $this->randZ = (mt_rand(0, 1) ? -1 : 1); } public function reset(){ @@ -28,7 +34,7 @@ class TaskPanic extends TaskBase { --$this->selfCounter; if($this->selfCounter % 20 === 0) $this->regenerateRandXZ(); - //TODO fix $ai->mobController->moveNonInstant($this->randX, 0, $this->randZ); + $ai->mobController->setMovingOffset($this->randX, 0, $this->randZ, $this->moveSpeed); } public function canBeExecuted(EntityAI $ai) diff --git a/src/entity/ai/tasks/TaskRandomWalk.php b/src/entity/ai/tasks/TaskRandomWalk.php index 685af3c5..28f8a5c2 100644 --- a/src/entity/ai/tasks/TaskRandomWalk.php +++ b/src/entity/ai/tasks/TaskRandomWalk.php @@ -37,11 +37,10 @@ class TaskRandomWalk extends TaskBase public function canBeExecuted(EntityAI $ai) { - return true; - //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; + 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; } diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index d775a94c..4d3dafe5 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -12,6 +12,8 @@ class Chicken extends Animal{ $this->setSpeed(0.25); $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskLookAtPlayer(6)); + $this->ai->addTask(new TaskPanic(0.375)); } 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 b185db20..baff016b 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -8,6 +8,8 @@ class Cow extends Animal{ $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); $this->setName("Cow"); $this->ai->addTask(new TaskRandomWalk(0.2)); + $this->ai->addTask(new TaskLookAtPlayer(6)); + $this->ai->addTask(new TaskPanic(0.375)); } public function isFood($id){ diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index 96a3e468..3083da60 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -11,6 +11,8 @@ class Pig extends Animal implements Rideable{ $this->setSpeed(0.25); $this->ai->addTask(new TaskRandomWalk(0.25)); + $this->ai->addTask(new TaskLookAtPlayer(6)); + $this->ai->addTask(new TaskPanic(0.375)); } /** diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index 720b88b3..ecaba25e 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -14,6 +14,8 @@ class Sheep extends Animal{ $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 TaskLookAtPlayer(6)); + $this->ai->addTask(new TaskPanic(0.375)); $this->ai->addTask(new TaskEatTileGoal()); } diff --git a/src/entity/object/FallingSand.php b/src/entity/object/FallingSand.php index 108a6ee1..42ad573c 100644 --- a/src/entity/object/FallingSand.php +++ b/src/entity/object/FallingSand.php @@ -8,6 +8,7 @@ class FallingSand extends Entity{ $this->setHealth(PHP_INT_MAX, "generic"); $this->height = 0.98; $this->width = 0.98; + $this->yOffset = $this->height / 2; $this->hasGravity = true; $this->gravity = 0.04; } diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index e138dc7a..bc1120c3 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -10,6 +10,7 @@ class ItemEntity extends Entity{ { parent::__construct($level, $eid, $class, $type, $data); $this->setSize(0.25, 0.25); + $this->yOffset = $this->height / 2; if(isset($data["item"]) and ($data["item"] instanceof Item)){ $this->meta = $this->data["item"]->getMetadata(); $this->stack = $this->data["item"]->count; diff --git a/src/entity/object/Minecart.php b/src/entity/object/Minecart.php index c257fcf4..6bd37451 100644 --- a/src/entity/object/Minecart.php +++ b/src/entity/object/Minecart.php @@ -65,6 +65,7 @@ class Minecart extends Vehicle{ $this->setHealth(1, "generic"); //orig: 3 $this->width = 0.98; $this->height = 0.7; + $this->yOffset = $this->height / 2; $this->update(); } diff --git a/src/entity/object/PrimedTNT.php b/src/entity/object/PrimedTNT.php index ca9cb62b..27768a05 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -10,6 +10,8 @@ class PrimedTNT extends Entity{ } $this->hasGravity = true; $this->gravity = 0.04; + $this->setSize(0.98, 0.98); + $this->yOffset = $this->height / 2; $this->setHealth(10000000, "generic"); $this->server->schedule(5, [$this, "updateFuse"], [], true); } diff --git a/src/material/item/generic/SpawnEggItem.php b/src/material/item/generic/SpawnEggItem.php index 3aac8d9c..f41e9a01 100644 --- a/src/material/item/generic/SpawnEggItem.php +++ b/src/material/item/generic/SpawnEggItem.php @@ -13,7 +13,7 @@ class SpawnEggItem extends Item{ "x" => $block->x + 0.5, "y" => $block->y, "z" => $block->z + 0.5, - "IsBaby" => $ageable ? Utils::chance(5) ? 1 : 0 : 0 + "IsBaby" => $ageable ? mt_rand(0, 5) == 0 ? 1 : 0 : 0 ); $e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data); ServerAPI::request()->api->entity->spawnToAll($e);