diff --git a/src/Player.php b/src/Player.php index 7582c9e2..42631b0a 100755 --- a/src/Player.php +++ b/src/Player.php @@ -771,9 +771,10 @@ class Player{ $this->dataPacket($pk); break; case "entity.animate": - if($data["eid"] === $this->eid or $data["entity"]->level !== $this->level){ + if($data["eid"] === $this->eid or $data["entity"]->level->getName() === $this->level->getName()){ break; } + console("dis"); $pk = new AnimatePacket; $pk->eid = $data["eid"]; $pk->action = $data["action"]; //1 swing arm, diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index c7c180af..e21cda8e 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -30,7 +30,6 @@ class PocketMinecraftServer{ @cli_set_process_title("NostalgiaCore ".MAJOR_VERSION); }*/ console("[INFO] Starting Minecraft PE server on " . ($this->serverip === "0.0.0.0" ? "*" : $this->serverip) . ":" . $this->port); - EntityRegistry::registerEntities(); define("BOOTUP_RANDOM", Utils::getRandomBytes(16)); $this->serverID = $this->serverID === false ? Utils::readLong(substr(Utils::getUniqueID(true, $this->serverip . $this->port), 8)) : $this->serverID; diff --git a/src/entity/Creature.php b/src/entity/Creature.php index 50538193..57c69e48 100644 --- a/src/entity/Creature.php +++ b/src/entity/Creature.php @@ -9,7 +9,7 @@ abstract class Creature extends Living{ public $inPanic; public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ - $this->inPanic = true; + $this->inPanic = false; //force for now parent::__construct($level, $eid, $class, $type, $data); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 1, "generic"); //$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type)); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 02055ae0..49732c58 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1249,11 +1249,11 @@ class Entity extends Position $pk = new EntityEventPacket; $pk->eid = $this->eid; $pk->event = 2; - $this->server->api->player->broadcastPacket($this->level->players, $pk); - /*$this->server->api->dhandle("entity.event", array( + //$this->server->api->player->broadcastPacket($this->level->players, $pk); + $this->server->api->dhandle("entity.event", array( "entity" => $this, "event" => 2 - )); // Ouch! sound*/ + )); // Ouch! sound } if($this->player instanceof Player){ $pk = new SetHealthPacket(); @@ -1300,10 +1300,10 @@ class Entity extends Position $pk->eid = $this->eid; $pk->event = 3; $this->server->api->player->broadcastPacket($this->level->players, $pk); - /*$this->server->api->dhandle("entity.event", [ + $this->server->api->dhandle("entity.event", [ "entity" => $this, "event" => 3 - ]); // Entity dead*/ + ]); // Entity dead } if($this->player instanceof Player){ $this->player->blocked = true; diff --git a/src/entity/ai/tasks/TaskLookAround.php b/src/entity/ai/tasks/TaskLookAround.php index ae15da59..9b9ecc3b 100644 --- a/src/entity/ai/tasks/TaskLookAround.php +++ b/src/entity/ai/tasks/TaskLookAround.php @@ -2,10 +2,10 @@ class TaskLookAround extends TaskBase { - private $finYaw = 0; + private $rotation = 0; public function shouldBeExecuted(EntityAI $ai) { - return !$ai->entity->isMoving() && $ai->entity->lookTime <= 0 && mt_rand(0,30) == 1 && $ai->entity->idleTime <= 0; + return !$ai->entity->isMoving() && $ai->entity->lookTime <= 0 && Utils::randomFloat() < 0.02 && $ai->entity->idleTime <= 0; } public function wasExecuted(EntityAI $ai){ @@ -14,8 +14,8 @@ class TaskLookAround extends TaskBase } public function onStart(EntityAI $ai){ - $ai->entity->lookTime = 120; - $this->finYaw = $ai->entity->yaw; + $ai->entity->lookTime = 20 + mt_rand(0, 20); + $this->rotation = mt_rand(-180,180); } public function onUpdate(EntityAI $ai) @@ -26,21 +26,13 @@ class TaskLookAround extends TaskBase if($ai->entity->lookTime === 1){ $ai->entity->idleTime = mt_rand(10, 40); } - if(Utils::in_range($ai->entity->lookTime, 45, 60) || Utils::in_range($ai->entity->lookTime, 0, 15)){ - $ai->entity->yaw -= 3; - } - if(Utils::in_range($ai->entity->lookTime, 15, 45)){ - $ai->entity->yaw += 3; - } - + $v = Utils::getSign($this->rotation) * 10; + $ai->entity->yaw += $v; $pk = new RotateHeadPacket(); $pk->eid = $ai->entity->eid; $pk->yaw = $ai->entity->yaw; $ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk); - } - public function testLook($pos){ - - + $this->rotation -= $v; } } diff --git a/src/entity/ai/tasks/TaskRandomWalk.php b/src/entity/ai/tasks/TaskRandomWalk.php index 1607499f..efca4052 100644 --- a/src/entity/ai/tasks/TaskRandomWalk.php +++ b/src/entity/ai/tasks/TaskRandomWalk.php @@ -21,23 +21,11 @@ class TaskRandomWalk extends TaskBase $this->z = mt_rand(-7, 7); $this->newPos = $ai->entity->add($this->x, 0, $this->z); $ai->entity->moveTime = floor(5 * Utils::distance($ai->entity, $this->newPos)); + $this->looking = true; } public function onUpdate(EntityAI $ai) { - if($this->delay > 0 && !$this->looking){ - --$this->delay; - try{ - return; - }finally{ - $this->testLook($ai, ($this->x > 0 ? 0.1 : ($this->x < 0 ? -0.1 : 0)), ($this->z > 0 ? 0.1 : ($this->z < 0 ? -0.1 : 0))); - $pk = new RotateHeadPacket(); - $pk->eid = $ai->entity->eid; - $pk->yaw = $ai->entity->yaw; - $ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk); - $this->looking = true; - } - } if($ai->entity->moveTime <= 1){ $ai->entity->idleTime = mt_rand(10,40); $this->x = 0; @@ -45,16 +33,21 @@ class TaskRandomWalk extends TaskBase $this->looking = false; } $ai->entity->moveEntityWithOffset(($this->x > 0 ? 1 : ($this->x < 0 ? -1 : 0)), 0, ($this->z > 0 ? 1 : ($this->z < 0 ? -1 : 0))); + if($this->looking){ + $this->testLook($ai, $ai->entity->speedX, $ai->entity->speedZ); + $pk = new RotateHeadPacket(); + $pk->eid = $ai->entity->eid; + $pk->yaw = $ai->entity->yaw; + $ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk); + $this->looking = false; + } } public function updateLook($ai){ $ai->entity->server->query("UPDATE entities SET pitch = ".$ai->entity->pitch.", yaw = ".$ai->entity->yaw." WHERE EID = ".$ai->entity->eid.";"); } public function testLook($ai, $vX, $vZ){ - $x = $this->newPos->x - $ai->entity->x; - $y = $this->newPos->y - $ai->entity->y; - $z = $this->newPos->z - $ai->entity->z; - $ai->entity->yaw = -atan2($x, $z) * 180 / M_PI; - $ai->entity->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt(pow($x, 2) + pow($z, 2)))); + $ai->entity->yaw = -atan2($vX, $vZ) * 180 / M_PI; + //nopitch $ai->entity->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt(pow($x, 2) + pow($z, 2)))); $ai->entity->server->query("UPDATE entities SET pitch = ".$ai->entity->pitch.", yaw = ".$ai->entity->yaw." WHERE EID = ".$ai->entity->eid.";"); } } \ No newline at end of file diff --git a/src/math/Vector3.php b/src/math/Vector3.php index 3b44c84a..0469cfdf 100644 --- a/src/math/Vector3.php +++ b/src/math/Vector3.php @@ -16,6 +16,10 @@ class Vector3{ $this->z = $z; } + public function copy(){ + return new Vector3($this->x, $this->y, $this->z); + } + public function toArray(){ return ["x" => $this->x, "y" => $this->y, "z" => $this->z]; } diff --git a/src/network/protocol/packet/AnimatePacket.php b/src/network/protocol/packet/AnimatePacket.php index 984ff9da..c743db66 100644 --- a/src/network/protocol/packet/AnimatePacket.php +++ b/src/network/protocol/packet/AnimatePacket.php @@ -1,6 +1,11 @@ 0 ? 1 : ($v < 0 ? -1 : 0); + } + + public static function clampDegrees($v){ + return floor(($v % 360 + 360) % 360); + } + public static function hasEmoji($s){ return preg_match(Utils::emojiRegex, $s, $matches); }