当前位置: 首页>>代码示例>>PHP>>正文


PHP Vector3::distanceSquared方法代码示例

本文整理汇总了PHP中pocketmine\math\Vector3::distanceSquared方法的典型用法代码示例。如果您正苦于以下问题:PHP Vector3::distanceSquared方法的具体用法?PHP Vector3::distanceSquared怎么用?PHP Vector3::distanceSquared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\math\Vector3的用法示例。


在下文中一共展示了Vector3::distanceSquared方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: isInside

 public function isInside(Vector3 $v)
 {
     if (!$this->isValid()) {
         return false;
     }
     if ($v instanceof Position and $v->getLevel()->getName() !== $this->levelName) {
         return false;
     }
     return $v->distanceSquared($this->center) <= $this->radiusSquared;
 }
开发者ID:GoneTone,项目名称:WorldEditArt,代码行数:10,代码来源:SphereSpace.php

示例2: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->closed !== false) {
         return false;
     }
     if (++$this->switchDirectionTicker === 100) {
         $this->switchDirectionTicker = 0;
         if (mt_rand(0, 100) < 50) {
             $this->swimDirection = null;
         }
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if ($this->isAlive()) {
         if ($this->y > 62 and $this->swimDirection !== null) {
             $this->swimDirection->y = -0.5;
         }
         /*$inWater = $this->isInsideOfAir();
         		if(!$inWater){
         			//$this->motionY -= $this->gravity;
         			$this->swimDirection = null;
         		}else*/
         if ($this->swimDirection !== null) {
             if ($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2 <= $this->swimDirection->lengthSquared()) {
                 $this->motionX = $this->swimDirection->x * $this->swimSpeed;
                 $this->motionY = $this->swimDirection->y * $this->swimSpeed;
                 $this->motionZ = $this->swimDirection->z * $this->swimSpeed;
             }
         } else {
             $this->swimDirection = $this->generateRandomDirection();
             $this->swimSpeed = mt_rand(50, 100);
         }
         $expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         if ($expectedPos->distanceSquared($this) > 0) {
             $this->swimDirection = $this->generateRandomDirection();
             $this->swimSpeed = mt_rand(50, 100);
         }
         $friction = 1 - $this->drag;
         $this->motionX *= $friction;
         $this->motionY *= 1 - $this->drag;
         $this->motionZ *= $friction;
         $f = sqrt($this->motionX ** 2 + $this->motionZ ** 2);
         $this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
         $this->pitch = -atan2($f, $this->motionY) * 180 / M_PI;
         if ($this->onGround) {
             $this->motionY *= -0.5;
         }
         $this->updateMovement();
     }
     $this->timings->stopTiming();
     return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
 }
开发者ID:PepbookPvP,项目名称:Genisys,代码行数:54,代码来源:Bat.php

示例3: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->closed !== false) {
         return false;
     }
     if ($this->getLevel()->getServer()->aiConfig["zombie"] != 2) {
         return parent::onUpdate($currentTick);
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if ($this->isAlive()) {
         /* Don't use time directly
          * Instead, get remainder of current time divided by 24,000
          * This tells us the time of day, which is what we really need
          */
         $timeOfDay = abs($this->getLevel()->getTime() % 24000);
         if (0 < $timeOfDay and $timeOfDay < 13000) {
             $this->setOnFire(2);
         }
         //僵尸起火
         $p = $this->getNearestPlayer();
         //找到最近的可以被仇恨的玩家
         if (!$p) {
             $this->hated = false;
             if (++$this->moveTicker >= 100) {
                 $this->moveDirection = $this->generateRandomDirection();
                 $this->moveTicker = 0;
             }
         } else {
             $this->hated = $p;
             if ($p->distance($this) <= $this->fire_r) {
                 $p->setOnFire(2);
             }
             //点燃玩家
             if (!$this->tempTicking) {
                 if (++$this->hateTicker >= 10 or $this->moveDirection == null) {
                     //每0.5秒获取僵尸前进的新方向
                     $this->moveDirection = $this->generateDirection($p);
                     $this->hateTicker = 0;
                 }
             }
         }
         if ($this->tempTicking) {
             //帮助僵尸寻找新的方向走出困境
             if (++$this->tempTicker >= 20) {
                 $this->tempTicking = false;
                 $this->tempTicker = 0;
             }
         }
         if ($this->hated instanceof Player) {
             //攻击玩家
             if ($this->hated->distance($this) < $this->attack_r) {
                 $this->hated->attack(2, new EntityDamageByEntityEvent($this, $this->hated, EntityDamageEvent::CAUSE_ENTITY_ATTACK, 2));
             }
         }
         if ($this->moveDirection != null) {
             if ($this->motionX ** 2 + $this->motionZ ** 2 <= $this->moveDirection->lengthSquared()) {
                 $motionY = $this->getVelY();
                 //僵尸运动计算
                 if ($motionY >= 0) {
                     $this->motionX = $this->moveDirection->x * $this->moveSpeed;
                     $this->motionZ = $this->moveDirection->z * $this->moveSpeed;
                     $this->motionY = $motionY;
                 } else {
                     $this->moveDirection = $this->generateRandomDirection();
                     //生成随机运动方向
                     $this->moveTicker = 0;
                     $this->tempTicking = true;
                 }
             }
         } else {
             $this->moveDirection = $this->generateRandomDirection();
             $this->moveTicker = 0;
         }
         //var_dump($this->moveDirection,$this->motionX,$this->motionZ);
         $expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
         if ($this->motionY == 0) {
             $this->motionY -= $this->gravity;
         }
         //重力计算
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         if ($expectedPos->distanceSquared($this) > 0) {
             $this->moveDirection = $this->generateRandomDirection();
         }
         $friction = 1 - $this->drag;
         $this->motionX *= $friction;
         //$this->motionY *= 1 - $this->drag;
         $this->motionZ *= $friction;
         $f = sqrt($this->motionX ** 2 + $this->motionZ ** 2);
         $this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
         //视角计算
         //$this->pitch = (-atan2($f, $this->motionY) * 180 / M_PI);
         $this->updateMovement();
     }
     $this->timings->stopTiming();
     return $hasUpdate or !$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5;
 }
开发者ID:AnonymousProjects,项目名称:PocketMine-MP-Original,代码行数:98,代码来源:Zombie.php

示例4: calculateIntercept

 /**
  * @param Vector3 $pos1
  * @param Vector3 $pos2
  *
  * @return MovingObjectPosition
  */
 public function calculateIntercept(Vector3 $pos1, Vector3 $pos2)
 {
     $bb = $this->getBoundingBox();
     if ($bb === null) {
         return null;
     }
     $v1 = $pos1->getIntermediateWithXValue($pos2, $bb->minX);
     $v2 = $pos1->getIntermediateWithXValue($pos2, $bb->maxX);
     $v3 = $pos1->getIntermediateWithYValue($pos2, $bb->minY);
     $v4 = $pos1->getIntermediateWithYValue($pos2, $bb->maxY);
     $v5 = $pos1->getIntermediateWithZValue($pos2, $bb->minZ);
     $v6 = $pos1->getIntermediateWithZValue($pos2, $bb->maxZ);
     if ($v1 !== null and !$bb->isVectorInYZ($v1)) {
         $v1 = null;
     }
     if ($v2 !== null and !$bb->isVectorInYZ($v2)) {
         $v2 = null;
     }
     if ($v3 !== null and !$bb->isVectorInXZ($v3)) {
         $v3 = null;
     }
     if ($v4 !== null and !$bb->isVectorInXZ($v4)) {
         $v4 = null;
     }
     if ($v5 !== null and !$bb->isVectorInXY($v5)) {
         $v5 = null;
     }
     if ($v6 !== null and !$bb->isVectorInXY($v6)) {
         $v6 = null;
     }
     $vector = $v1;
     if ($v2 !== null and ($vector === null or $pos1->distanceSquared($v2) < $pos1->distanceSquared($vector))) {
         $vector = $v2;
     }
     if ($v3 !== null and ($vector === null or $pos1->distanceSquared($v3) < $pos1->distanceSquared($vector))) {
         $vector = $v3;
     }
     if ($v4 !== null and ($vector === null or $pos1->distanceSquared($v4) < $pos1->distanceSquared($vector))) {
         $vector = $v4;
     }
     if ($v5 !== null and ($vector === null or $pos1->distanceSquared($v5) < $pos1->distanceSquared($vector))) {
         $vector = $v5;
     }
     if ($v6 !== null and ($vector === null or $pos1->distanceSquared($v6) < $pos1->distanceSquared($vector))) {
         $vector = $v6;
     }
     if ($vector === null) {
         return null;
     }
     $f = -1;
     if ($vector === $v1) {
         $f = 4;
     } elseif ($vector === $v2) {
         $f = 5;
     } elseif ($vector === $v3) {
         $f = 0;
     } elseif ($vector === $v4) {
         $f = 1;
     } elseif ($vector === $v5) {
         $f = 2;
     } elseif ($vector === $v6) {
         $f = 3;
     }
     return MovingObjectPosition::fromBlock($this->x, $this->y, $this->z, $f, $vector->add($this->x, $this->y, $this->z));
 }
开发者ID:1455931078,项目名称:Genisys,代码行数:71,代码来源:Block.php

示例5: handleDataPacket


//.........这里部分代码省略.........
             $pk->z = (int) $spawnPosition->z;
             $this->dataPacket($pk);
             if ($this->getHealth() <= 0) {
                 $this->dead = true;
             }
             $pk = new SetDifficultyPacket();
             $pk->difficulty = $this->server->getDifficulty();
             $this->dataPacket($pk);
             $this->server->getLogger()->info(TextFormat::AQUA . $this->username . TextFormat::WHITE . "/" . TextFormat::AQUA . $this->ip . " connected");
             if ($this->gamemode === Player::SPECTATOR) {
                 $pk = new ContainerSetContentPacket();
                 $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
                 $this->dataPacket($pk);
             } else {
                 $pk = new ContainerSetContentPacket();
                 $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
                 foreach (Item::getCreativeItems() as $item) {
                     $pk->slots[] = clone $item;
                 }
                 $this->dataPacket($pk);
             }
             $this->server->sendFullPlayerListData($this);
             $this->server->sendRecipeList($this);
             //				$this->orderChunks();
             //				$this->sendNextChunk();
             break;
         case ProtocolInfo::MOVE_PLAYER_PACKET:
             $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z);
             $revert = false;
             if ($this->dead === true or $this->spawned !== true) {
                 $revert = true;
                 $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
             }
             if ($this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.04 or $revert)) {
                 $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
             } else {
                 $packet->yaw %= 360;
                 $packet->pitch %= 360;
                 if ($packet->yaw < 0) {
                     $packet->yaw += 360;
                 }
                 $this->setRotation($packet->yaw, $packet->pitch);
                 $this->newPosition = $newPos;
                 $this->forceMovement = null;
             }
             break;
         case ProtocolInfo::MOB_EQUIPMENT_PACKET:
             if ($this->spawned === false or $this->dead === true) {
                 break;
             }
             if ($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255) {
                 //0 for 0.8.0 compatibility
                 $packet->slot = -1;
                 //Air
             } else {
                 $packet->slot -= 9;
                 //Get real block slot
             }
             /** @var Item $item */
             $item = null;
             if ($this->isCreative()) {
                 //Creative mode match
                 $item = $packet->item;
                 $slot = Item::getCreativeItemIndex($item);
             } else {
                 $item = $this->inventory->getItem($packet->slot);
开发者ID:WonderlandPE,项目名称:Steadfast2,代码行数:67,代码来源:Player.php

示例6: handleDataPacket


//.........这里部分代码省略.........
             $pk->started = $this->level->stopTime == false;
             $this->dataPacket($pk);
             $pk = new SetSpawnPositionPacket();
             $pk->x = (int) $spawnPosition->x;
             $pk->y = (int) $spawnPosition->y;
             $pk->z = (int) $spawnPosition->z;
             $this->dataPacket($pk);
             $pk = new SetHealthPacket();
             $pk->health = $this->getHealth();
             $this->dataPacket($pk);
             if ($this->getHealth() <= 0) {
                 $this->dead = true;
             }
             $pk = new SetDifficultyPacket();
             $pk->difficulty = $this->server->getDifficulty();
             $this->dataPacket($pk);
             $this->server->getLogger()->info(TextFormat::AQUA . $this->username . TextFormat::WHITE . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->level->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")");
             $this->orderChunks();
             $this->sendNextChunk();
             break;
         case ProtocolInfo::ROTATE_HEAD_PACKET:
             if ($this->spawned === false or $this->dead === true) {
                 break;
             }
             $this->setRotation($packet->yaw, $this->pitch);
             break;
         case ProtocolInfo::MOVE_PLAYER_PACKET:
             $newPos = new Vector3($packet->x, $packet->y, $packet->z);
             $revert = false;
             if ($this->dead === true or $this->spawned !== true) {
                 $revert = true;
                 $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
             }
             if ($this->forceMovement instanceof Vector3 and ($revert or $newPos->distanceSquared($this->forceMovement) > 0.04)) {
                 $pk = new MovePlayerPacket();
                 $pk->eid = 0;
                 $pk->x = $this->forceMovement->x;
                 $pk->y = $this->forceMovement->y + $this->getEyeHeight();
                 $pk->z = $this->forceMovement->z;
                 $pk->bodyYaw = $packet->bodyYaw;
                 $pk->pitch = $packet->pitch;
                 $pk->yaw = $packet->yaw;
                 $pk->teleport = true;
                 $this->directDataPacket($pk);
             } else {
                 $packet->yaw %= 360;
                 $packet->pitch %= 360;
                 if ($packet->yaw < 0) {
                     $packet->yaw += 360;
                 }
                 $this->setRotation($packet->yaw, $packet->pitch);
                 $this->newPosition = $newPos;
                 $this->forceMovement = null;
             }
             break;
         case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
             if ($this->spawned === false or $this->dead === true) {
                 break;
             }
             if ($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255) {
                 //0 for 0.8.0 compatibility
                 $packet->slot = -1;
                 //Air
             } else {
                 $packet->slot -= 9;
                 //Get real block slot
开发者ID:rryy,项目名称:PocketMine-MP,代码行数:67,代码来源:Player.php

示例7: calculateInterceptVector

 /**
  *
  * Calculates interception vector
  * @param Vector3 $pos1
  * @param Vector3[] $intermediateVectors
  *
  * @return null|Vector3
  */
 public function calculateInterceptVector(Vector3 $pos1, array &$intermediateVectors)
 {
     if ($intermediateVectors['v1'] !== null and !$this->isVectorInYZ($intermediateVectors['v1'])) {
         $intermediateVectors['v1'] = null;
     }
     if ($intermediateVectors['v2'] !== null and !$this->isVectorInYZ($intermediateVectors['v2'])) {
         $intermediateVectors['v2'] = null;
     }
     if ($intermediateVectors['v3'] !== null and !$this->isVectorInXZ($intermediateVectors['v3'])) {
         $intermediateVectors['v3'] = null;
     }
     if ($intermediateVectors['v4'] !== null and !$this->isVectorInXZ($intermediateVectors['v4'])) {
         $intermediateVectors['v4'] = null;
     }
     if ($intermediateVectors['v5'] !== null and !$this->isVectorInXY($intermediateVectors['v5'])) {
         $intermediateVectors['v5'] = null;
     }
     if ($intermediateVectors['v6'] !== null and !$this->isVectorInXY($intermediateVectors['v6'])) {
         $intermediateVectors['v6'] = null;
     }
     $vector = null;
     if ($intermediateVectors['v1'] !== null and ($vector === null or $pos1->distanceSquared($intermediateVectors['v1']) < $pos1->distanceSquared($vector))) {
         $vector = $intermediateVectors['v1'];
     }
     if ($intermediateVectors['v2'] !== null and ($vector === null or $pos1->distanceSquared($intermediateVectors['v2']) < $pos1->distanceSquared($vector))) {
         $vector = $intermediateVectors['v2'];
     }
     if ($intermediateVectors['v3'] !== null and ($vector === null or $pos1->distanceSquared($intermediateVectors['v3']) < $pos1->distanceSquared($vector))) {
         $vector = $intermediateVectors['v3'];
     }
     if ($intermediateVectors['v4'] !== null and ($vector === null or $pos1->distanceSquared($intermediateVectors['v4']) < $pos1->distanceSquared($vector))) {
         $vector = $intermediateVectors['v4'];
     }
     if ($intermediateVectors['v5'] !== null and ($vector === null or $pos1->distanceSquared($intermediateVectors['v5']) < $pos1->distanceSquared($vector))) {
         $vector = $intermediateVectors['v5'];
     }
     if ($intermediateVectors['v6'] !== null and ($vector === null or $pos1->distanceSquared($intermediateVectors['v6']) < $pos1->distanceSquared($vector))) {
         $vector = $intermediateVectors['v6'];
     }
     return $vector;
 }
开发者ID:Guillaume351,项目名称:Katana,代码行数:49,代码来源:AxisAlignedBB.php

示例8: handleDataPacket


//.........这里部分代码省略.........
             }
             if (strlen($packet->skin) != 64 * 64 * 4 and strlen($packet->skin) != 64 * 32 * 4) {
                 $this->close("", "disconnectionScreen.invalidSkin");
                 break;
             }
             $this->setSkin($packet->skin, $packet->skinId);
             $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
             if ($ev->isCancelled()) {
                 $this->close("", $ev->getKickMessage());
                 break;
             }
             if ($this->isConnected()) {
                 $this->onPlayerPreLogin();
             }
             break;
         case ProtocolInfo::MOVE_PLAYER_PACKET:
             if ($this->linkedEntity instanceof Entity) {
                 $entity = $this->linkedEntity;
                 if ($entity instanceof Boat) {
                     $entity->setPosition($this->temporalVector->setComponents($packet->x, $packet->y - 0.3, $packet->z));
                 }
                 /*if($entity instanceof Minecart){
                 			$entity->isFreeMoving = true;
                 			$entity->motionX = -sin($packet->yaw / 180 * M_PI);
                 			$entity->motionZ = cos($packet->yaw / 180 * M_PI);
                 		}*/
             }
             $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z);
             $revert = false;
             if (!$this->isAlive() or $this->spawned !== true) {
                 $revert = true;
                 $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
             }
             if ($this->teleportPosition !== null or $this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)) {
                 if ($this->forceMovement instanceof Vector3) {
                     $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
                 }
             } else {
                 $packet->yaw %= 360;
                 $packet->pitch %= 360;
                 if ($packet->yaw < 0) {
                     $packet->yaw += 360;
                 }
                 $this->setRotation($packet->yaw, $packet->pitch);
                 $this->newPosition = $newPos;
             }
             $this->forceMovement = null;
             break;
         case ProtocolInfo::MOB_EQUIPMENT_PACKET:
             if ($this->spawned === false or !$this->isAlive()) {
                 break;
             }
             /**
              * Handle hotbar slot remapping
              * This is the only time and place when hotbar mapping should ever be changed.
              * Changing hotbar slot mapping at will has been deprecated because it causes far too many
              * issues with Windows 10 Edition Beta.
              */
             $this->inventory->setHeldItemIndex($packet->selectedSlot, false, $packet->slot);
             $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
             break;
         case ProtocolInfo::USE_ITEM_PACKET:
             if ($this->spawned === false or !$this->isAlive() or $this->blocked) {
                 break;
             }
             $blockVector = new Vector3($packet->x, $packet->y, $packet->z);
开发者ID:iTXTech,项目名称:Genisys,代码行数:67,代码来源:Player.php

示例9: isLocalChat

 /**
  * @param Vector3 $from
  * @param Vector3 $to
  * @return mixed
  */
 public static function isLocalChat($from, $to)
 {
     return $from->distanceSquared($to) <= 1600;
 }
开发者ID:Addison118,项目名称:LegionPE-Theta-Base,代码行数:9,代码来源:Settings.php

示例10: handleDataPacket


//.........这里部分代码省略.........
                 if ($c >= ord("a") and $c <= ord("z") or $c >= ord("A") and $c <= ord("Z") or $c >= ord("0") and $c <= ord("9") or $c === ord("_")) {
                     continue;
                 }
                 $valid = false;
                 break;
             }
             if (!$valid or $this->iusername === "rcon" or $this->iusername === "console") {
                 $this->close("", "disconnectionScreen.invalidName");
                 break;
             }
             if (strlen($packet->skin) !== 64 * 32 * 4 and strlen($packet->skin) !== 64 * 64 * 4) {
                 $this->close("", "disconnectionScreen.invalidSkin");
                 break;
             }
             $this->setSkin($packet->skin, $packet->skinId);
             $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
             if ($ev->isCancelled()) {
                 $this->close("", $ev->getKickMessage());
                 break;
             }
             $this->onPlayerPreLogin();
             break;
         case ProtocolInfo::MOVE_PLAYER_PACKET:
             /*
             /** EntityLink ** /
             if($this->getlinkType() === Entity::LINK_MASTER){
             	$this->getlinkedTarget()->followEntity($this);
             }
             */
             if ($this->teleportPosition !== null) {
                 break;
             }
             $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z);
             if ($newPos->distanceSquared($this) < 0.01 and $packet->yaw % 360 === $this->yaw and $packet->pitch % 360 === $this->pitch) {
                 //player hasn't moved, just client spamming packets
                 break;
             }
             $revert = false;
             if (!$this->isAlive() or $this->spawned !== true) {
                 $revert = true;
                 $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
             }
             if ($this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)) {
                 $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
             } else {
                 $packet->yaw %= 360;
                 $packet->pitch %= 360;
                 if ($packet->yaw < 0) {
                     $packet->yaw += 360;
                 }
                 $this->setRotation($packet->yaw, $packet->pitch);
                 $this->newPosition = $newPos;
             }
             $this->forceMovement = null;
             break;
         case ProtocolInfo::ADVENTURE_SETTINGS_PACKET:
             //TODO: player abilities, check for other changes
             if ($packet->isFlying and !$this->allowFlight) {
                 $this->kick("Flying is not enabled on this server");
                 break;
             } else {
                 $this->server->getPluginManager()->callEvent($ev = new PlayerToggleFlightEvent($this, $packet->isFlying));
                 if ($ev->isCancelled()) {
                     $this->sendSettings();
                 } else {
                     $this->flying = $ev->isFlying();
开发者ID:robske110,项目名称:ClearSky,代码行数:67,代码来源:Player.php

示例11: handleDataPacket


//.........这里部分代码省略.........
             if ($this->getHealth() <= 0) {
                 $this->dead = true;
             }
             $pk = new SetDifficultyPacket();
             $pk->difficulty = $this->server->getDifficulty();
             $this->dataPacket($pk->setChannel(Network::CHANNEL_PRIORITY));
             $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logIn", [TextFormat::AQUA . $this->username . TextFormat::WHITE, $this->ip, $this->port, $this->id, $this->level->getName(), round($this->x, 4), round($this->y, 4), round($this->z, 4)]));
             if ($this->isOp()) {
                 $this->setRemoveFormat(false);
             }
             if ($this->gamemode === Player::SPECTATOR) {
                 $pk = new ContainerSetContentPacket();
                 $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
                 $this->dataPacket($pk->setChannel(Network::CHANNEL_PRIORITY));
             } else {
                 $pk = new ContainerSetContentPacket();
                 $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
                 foreach (Item::getCreativeItems() as $item) {
                     $pk->slots[] = clone $item;
                 }
                 $this->dataPacket($pk->setChannel(Network::CHANNEL_PRIORITY));
             }
             $this->teleportPosition = $this->getPosition();
             $this->orderChunks();
             $this->sendNextChunk();
             break;
         case ProtocolInfo::MOVE_PLAYER_PACKET:
             $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z);
             $revert = false;
             if ($this->dead === true or $this->spawned !== true) {
                 $revert = true;
                 $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
             }
             if ($this->teleportPosition !== null or $this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)) {
                 $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
             } else {
                 $packet->yaw %= 360;
                 $packet->pitch %= 360;
                 if ($packet->yaw < 0) {
                     $packet->yaw += 360;
                 }
                 $this->setRotation($packet->yaw, $packet->pitch);
                 $this->newPosition = $newPos;
                 $this->forceMovement = null;
             }
             break;
         case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
             if ($this->spawned === false or $this->dead === true) {
                 break;
             }
             if ($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255) {
                 //0 for 0.8.0 compatibility
                 $packet->slot = -1;
                 //Air
             } else {
                 $packet->slot -= 9;
                 //Get real block slot
             }
             if ($this->isCreative()) {
                 //Creative mode match
                 $item = Item::get($packet->item, $packet->meta, 1);
                 $slot = Item::getCreativeItemIndex($item);
             } else {
                 $item = $this->inventory->getItem($packet->slot);
                 $slot = $packet->slot;
             }
开发者ID:TylerGames,项目名称:PocketMine-MP,代码行数:67,代码来源:Player.php

示例12: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->closed !== \false) {
         return \false;
     }
     if (++$this->switchDirectionTicker === 100) {
         $this->switchDirectionTicker = 0;
         if (\mt_rand(0, 100) < 50) {
             $this->swimDirection = \null;
         }
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if (!$this->dead) {
         if ($this->y > 62 and $this->swimDirection !== \null) {
             $this->swimDirection->y = -0.5;
         }
         $inWater = $this->isInsideOfWater();
         if (!$inWater) {
             $this->motionY -= $this->gravity;
             $this->swimDirection = \null;
         } elseif ($this->swimDirection !== \null) {
             if ($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2 <= $this->swimDirection->lengthSquared()) {
                 $this->motionX = $this->swimDirection->x * $this->swimSpeed;
                 $this->motionY = $this->swimDirection->y * $this->swimSpeed;
                 $this->motionZ = $this->swimDirection->z * $this->swimSpeed;
             }
         } else {
             $this->swimDirection = $this->generateRandomDirection();
             $this->swimSpeed = \mt_rand(50, 100) / 2000;
         }
         $expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         if ($expectedPos->distanceSquared($this) > 0) {
             $this->swimDirection = $this->generateRandomDirection();
             $this->swimSpeed = \mt_rand(50, 100) / 2000;
         }
         $friction = 1 - $this->drag;
         $this->motionX *= $friction;
         $this->motionY *= 1 - $this->drag;
         $this->motionZ *= $friction;
         $f = \sqrt($this->motionX ** 2 + $this->motionZ ** 2);
         $this->yaw = -\atan2($this->motionX, $this->motionZ) * 180 / M_PI;
         $this->pitch = -\atan2($f, $this->motionY) * 180 / M_PI;
         if ($this->onGround) {
             $this->motionY *= -0.5;
         }
     }
     $this->timings->stopTiming();
     return $hasUpdate or !$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0;
 }
开发者ID:Edwardthedog2,项目名称:Steadfast2,代码行数:52,代码来源:Squid.php

示例13: handleDataPacket


//.........这里部分代码省略.........
                 $this->close("", "disconnectionScreen.invalidName");
                 break;
             }
             if (strlen($packet->skin) != 64 * 64 * 4 and strlen($packet->skin) != 64 * 32 * 4) {
                 $this->close("", "disconnectionScreen.invalidSkin");
                 break;
             }
             $this->setSkin($packet->skin, $packet->skinId);
             $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
             if ($ev->isCancelled()) {
                 $this->close("", $ev->getKickMessage());
                 break;
             }
             $this->onPlayerPreLogin();
             break;
         case ProtocolInfo::MOVE_PLAYER_PACKET:
             if ($this->linkedEntity instanceof Entity) {
                 $entity = $this->linkedEntity;
                 if ($entity instanceof Boat) {
                     $entity->setPosition($this->temporalVector->setComponents($packet->x, $packet->y - 0.3, $packet->z));
                 }
                 /*if($entity instanceof Minecart){
                 			$entity->isFreeMoving = true;
                 			$entity->motionX = -sin($packet->yaw / 180 * M_PI);
                 			$entity->motionZ = cos($packet->yaw / 180 * M_PI);
                 		}*/
             }
             $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z);
             $revert = false;
             if (!$this->isAlive() or $this->spawned !== true) {
                 $revert = true;
                 $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
             }
             if ($this->teleportPosition !== null or $this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)) {
                 if ($this->forceMovement instanceof Vector3) {
                     $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
                 }
             } else {
                 $packet->yaw %= 360;
                 $packet->pitch %= 360;
                 if ($packet->yaw < 0) {
                     $packet->yaw += 360;
                 }
                 $this->setRotation($packet->yaw, $packet->pitch);
                 $this->newPosition = $newPos;
                 $this->forceMovement = null;
             }
             break;
         case ProtocolInfo::MOB_EQUIPMENT_PACKET:
             if ($this->spawned === false or !$this->isAlive()) {
                 break;
             }
             if ($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255) {
                 //0 for 0.8.0 compatibility
                 $packet->slot = -1;
                 //Air
             } else {
                 $packet->slot -= 9;
                 //Get real block slot
             }
             /** @var Item $item */
             $item = null;
             if ($this->isCreative()) {
                 //Creative mode match
                 $item = $packet->item;
                 $slot = Item::getCreativeItemIndex($item);
开发者ID:yungtechboy1,项目名称:Genisys,代码行数:67,代码来源:Player.php

示例14: handleDataPacket

 /**
  * Handles a Minecraft packet
  * TODO: Separate all of this in handlers
  *
  * WARNING: Do not use this, it's only for internal use.
  * Changes to this function won't be recorded on the version.
  *
  * @param DataPacket $packet
  */
 public function handleDataPacket(DataPacket $packet)
 {
     if ($this->connected === false) {
         return;
     }
     if ($packet::NETWORK_ID === ProtocolInfo::BATCH_PACKET) {
         /** @var BatchPacket $packet */
         $this->server->getNetwork()->processBatch($packet, $this);
         return;
     }
     $timings = Timings::getReceiveDataPacketTimings($packet);
     $timings->startTiming();
     $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
     if ($ev->isCancelled()) {
         $timings->stopTiming();
         return;
     }
     switch ($packet::NETWORK_ID) {
         case ProtocolInfo::LOGIN_PACKET:
             if ($this->loggedIn) {
                 break;
             }
             $this->username = TextFormat::clean($packet->username);
             $this->displayName = $this->username;
             $this->setNameTag($this->username);
             $this->iusername = strtolower($this->username);
             if (count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)) {
                 break;
             }
             if ($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL) {
                 if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) {
                     $message = "disconnectionScreen.outdatedClient";
                     $pk = new PlayStatusPacket();
                     $pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT;
                     $this->directDataPacket($pk);
                 } else {
                     $message = "disconnectionScreen.outdatedServer";
                     $pk = new PlayStatusPacket();
                     $pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER;
                     $this->directDataPacket($pk);
                 }
                 $this->close("", $message, false);
                 break;
             }
             $this->randomClientId = $packet->clientId;
             $this->loginData = ["clientId" => $packet->clientId, "loginData" => null];
             $this->uuid = $packet->clientUUID;
             $this->rawUUID = $this->uuid->toBinary();
             $this->clientSecret = $packet->clientSecret;
             $valid = true;
             $len = strlen($packet->username);
             if ($len > 16 or $len < 3) {
                 $valid = false;
             }
             for ($i = 0; $i < $len and $valid; ++$i) {
                 $c = ord($packet->username[$i]);
                 if ($c >= ord("a") and $c <= ord("z") or $c >= ord("A") and $c <= ord("Z") or $c >= ord("0") and $c <= ord("9") or $c === ord("_")) {
                     continue;
                 }
                 $valid = false;
                 break;
             }
             if (!$valid or $this->iusername === "rcon" or $this->iusername === "console") {
                 $this->close("", "disconnectionScreen.invalidName");
                 break;
             }
             if (strlen($packet->skin) !== 64 * 32 * 4 and strlen($packet->skin) !== 64 * 64 * 4) {
                 $this->close("", "disconnectionScreen.invalidSkin");
                 break;
             }
             $this->setSkin($packet->skin, $packet->skinname, $packet->oldclient, $packet->slim, $packet->transparent);
             $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
             if ($ev->isCancelled()) {
                 $this->close("", $ev->getKickMessage());
                 break;
             }
             $this->onPlayerPreLogin();
             break;
         case ProtocolInfo::MOVE_PLAYER_PACKET:
             $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z);
             $revert = false;
             if (!$this->isAlive() or $this->spawned !== true) {
                 $revert = true;
                 $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
             }
             if ($this->teleportPosition !== null or $this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)) {
                 $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
             } else {
                 $packet->yaw %= 360;
                 $packet->pitch %= 360;
                 if ($packet->yaw < 0) {
//.........这里部分代码省略.........
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:101,代码来源:Player.php


注:本文中的pocketmine\math\Vector3::distanceSquared方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。