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


PHP Vector3::distance方法代码示例

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


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

示例1: onPlayerInteract

 public function onPlayerInteract(PlayerInteractEvent $e)
 {
     // Implement the CompassTP thingie...
     $pl = $e->getPlayer();
     if (!$pl->hasPermission("toybox.compasstp")) {
         return;
     }
     $hand = $pl->getInventory()->getItemInHand();
     if ($hand->getID() != $this->item) {
         return;
     }
     $pos = $pl->getPosition()->add(0, $pl->getEyeHeight(), 0);
     $start = new Vector3($pos->getX(), $pos->getY(), $pos->getZ());
     $lv = $pl->getLevel();
     for ($start = new Vector3($pos->getX(), $pos->getY(), $pos->getZ()); $start->distance($pos) < 120; $pos = $pos->add($pl->getDirectionVector())) {
         $block = $lv->getBlock($pos->floor());
         if ($block->getId() != 0) {
             break;
         }
     }
     if ($block->getId() == 0) {
         $pl->sendMessage(mc::_("Can not teleport to the void!"));
         return;
     }
     $pos = $pos->subtract($pl->getDirectionVector());
     $dist = $start->distance($pos);
     if ($dist < 2.8) {
         $pl->sendMessage(mc::_("Not teleporting..."));
         $pl->sendMessage(mc::_("You could easily walk there!"));
         return;
     }
     //echo "Block: ".$block->getName()." (".$block->getId().")\n";
     //print_r($pos);
     //echo "Distance: ".$start->distance($pos)."\n";
     $pl->sendMessage(mc::_("Teleporting... %1%", intval($dist)));
     $pos = $pos->add(0, 1, 0);
     /*$cb = new CallbackTask([$this,"delayedTP"],[$pl->getName(),
       $pos->getX(),
       $pos->getY(),
       $pos->getZ()]);
       $this->owner->getServer()->getScheduler()->scheduleDelayedTask($cb,20);
       //$pl->teleport($pos);
       return;*/
     $m = 5.0;
     for ($f = 1.0; $f <= $m; $f++) {
         $ticks = intval($f) * 5;
         $x = ($pos->getX() - $start->getX()) * $f / $m + $start->getX();
         $y = ($pos->getY() - $start->getY()) * $f / $m + $start->getY();
         $z = ($pos->getZ() - $start->getZ()) * $f / $m + $start->getZ();
         $c = new PluginCallbackTask($this->owner, [$this, "delayedTP"], [$pl->getName(), $x, $y, $z]);
         $this->owner->getServer()->getScheduler()->scheduleDelayedTask($c, $ticks);
     }
 }
开发者ID:DWWf,项目名称:pocketmine-plugins,代码行数:53,代码来源:CompassTp.php

示例2: isInside

 public function isInside(Vector3 $v)
 {
     $out = true;
     $out = ($out and $v->distance($this->centre) <= $this->radius);
     if ($v instanceof Position) {
         $out = ($out and $v->getLevel()->getName() === $this->centre->getLevel()->getName());
     }
     return $out;
 }
开发者ID:barnseyminesuk,项目名称:Small-ZC-Plugins,代码行数:9,代码来源:SphereSpace.php

示例3: sleepOn

 /**
  * @param Vector3 $pos
  *
  * @return boolean
  */
 public function sleepOn(Vector3 $pos)
 {
     if (!$this->isOnline()) {
         return false;
     }
     foreach ($this->level->getNearbyEntities($this->boundingBox->grow(2, 1, 2), $this) as $p) {
         if ($p instanceof Player) {
             if ($p->sleeping !== null and $pos->distance($p->sleeping) <= 0.1) {
                 return false;
             }
         }
     }
     $this->server->getPluginManager()->callEvent($ev = new PlayerBedEnterEvent($this, $this->level->getBlock($pos)));
     if ($ev->isCancelled()) {
         return false;
     }
     $this->sleeping = clone $pos;
     $this->teleport(new Position($pos->x + 0.5, $pos->y - 0.5, $pos->z + 0.5, $this->level));
     $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]);
     $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true);
     $this->setSpawn($pos);
     $this->level->sleepTicks = 60;
     return true;
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:29,代码来源:Player.php

示例4: getpitch

 /**
  * @param Vector3 $from
  * @param Vector3 $to
  * @return float|int
  * 获取pitch角度
  */
 public function getpitch(Vector3 $from, Vector3 $to)
 {
     $distance = $from->distance($to);
     $height = $to->y - $from->y;
     if ($height > 0) {
         return -rad2deg(asin($height / $distance));
     } elseif ($height < 0) {
         return rad2deg(asin(-$height / $distance));
     } else {
         return 0;
     }
 }
开发者ID:yungtechboy1,项目名称:Genisys,代码行数:18,代码来源:AIHolder.php

示例5: handleDataPacket


//.........这里部分代码省略.........
             $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 . "/" . 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->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)) {
                 $pk = new MovePlayerPacket();
                 $pk->eid = $this->getId();
                 $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 = 1;
                 $this->directDataPacket($pk);
                 $this->forceMovement = null;
             } 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;
开发者ID:ZenaGamingsky,项目名称:Steadfast2,代码行数:67,代码来源:Player.php

示例6: distance

 /**
  * Returns the distance between two points or objects
  *
  * @param Vector3 $pos
  *
  * @return float
  */
 public function distance(Vector3 $pos)
 {
     if ($pos instanceof Position and $pos->getLevel() !== $this->getLevel()) {
         return PHP_INT_MAX;
     }
     return parent::distance($pos);
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:14,代码来源:Position.php

示例7: 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

示例8: onRun


//.........这里部分代码省略.........
                                 if ($p->getNameTag() == $p->getName()) {
                                     $AT = $this->plugin->getAvailableTeam($arena);
                                     $p->setNameTag($this->plugin->getTeamColor($AT) . $pn);
                                 }
                                 $this->plugin->TeleportToTeamSpawn($p, $this->plugin->getTeam($p->getNameTag()), $arena);
                             } else {
                                 $this->plugin->removePlayerFromArena($arena, $pn);
                             }
                         }
                         $config->set("Status", "Ingame");
                         $config->save();
                     }
                 }
             } elseif ($status == "Ingame") {
                 if (count($aliveTeams) <= 1) {
                     if (count($aliveTeams) == 1) {
                         $winnerteam = $aliveTeams[0];
                         $this->plugin->getServer()->broadcastMessage($this->prefix . "Team " . TextFormat::GOLD . $winnerteam . TextFormat::WHITE . " hat Die Bedwars Runde in Arena " . TextFormat::GOLD . $arena . TextFormat::WHITE . " Gewonnen!");
                     }
                     $config->set("Status", "Ende");
                     $config->save();
                 } else {
                     if (Time() % 1 == 0) {
                         $tiles = $level->getTiles();
                         foreach ($tiles as $tile) {
                             if ($tile instanceof Sign) {
                                 $text = $tile->getText();
                                 if (strtolower($text[0]) == "bronze" || strtolower($text[1]) == "bronze" || strtolower($text[2]) == "bronze" || strtolower($text[3]) == "bronze") {
                                     $loc = new Vector3($tile->getX() + 0.5, $tile->getY() + 2, $tile->getZ() + 0.5);
                                     $needDrop = false;
                                     foreach ($players as $pn) {
                                         $p = $this->plugin->getServer()->getPlayerExact($pn);
                                         if ($p != null) {
                                             $dis = $loc->distance($p);
                                             if ($dis <= 10) {
                                                 $needDrop = true;
                                             }
                                         }
                                     }
                                     if ($needDrop === true) {
                                         $level->dropItem(new Vector3($tile->getX() + 0.5, $tile->getY() + 2, $tile->getZ() + 0.5), Item::get(Item::BRICK, 0, 1));
                                         $level->dropItem(new Vector3($tile->getX() + 0.5, $tile->getY() + 2, $tile->getZ() + 0.5), Item::get(Item::BRICK, 0, 1));
                                     }
                                 }
                             }
                         }
                     }
                     if (Time() % 8 == 0) {
                         $tiles = $level->getTiles();
                         foreach ($tiles as $tile) {
                             if ($tile instanceof Sign) {
                                 $text = $tile->getText();
                                 if (strtolower($text[0]) == "eisen" || strtolower($text[1]) == "eisen" || strtolower($text[2]) == "eisen" || strtolower($text[3]) == "eisen") {
                                     $level->dropItem(new Vector3($tile->getX() + 0.5, $tile->getY() + 2, $tile->getZ() + 0.5), Item::get(Item::IRON_INGOT, 0, 1));
                                 }
                             }
                         }
                     }
                     if (Time() % 30 == 0) {
                         $tiles = $level->getTiles();
                         foreach ($tiles as $tile) {
                             if ($tile instanceof Sign) {
                                 $text = $tile->getText();
                                 if (strtolower($text[0]) == "gold" || strtolower($text[1]) == "gold" || strtolower($text[2]) == "gold" || strtolower($text[3]) == "gold") {
                                     $level->dropItem(new Vector3($tile->getX() + 0.5, $tile->getY() + 2, $tile->getZ() + 0.5), Item::get(Item::GOLD_INGOT, 0, 1));
                                 }
开发者ID:Bluplayz,项目名称:BedwarsPE,代码行数:67,代码来源:Bedwars.php

示例9: targetPos

 protected function targetPos($pos, $dir)
 {
     $lv = $pos->getLevel();
     for ($start = new Vector3($pos->getX(), $pos->getY(), $pos->getZ()); $start->distance($pos) < $this->max_dist; $pos = $pos->add($dir)) {
         $block = $lv->getBlock($pos->floor());
         if ($block->getId() != 0) {
             break;
         }
     }
     while ($block->getId() != 0) {
         $block = $block->getSide(Vector3::SIDE_UP);
     }
     return $block;
 }
开发者ID:DWWf,项目名称:pocketmine-plugins,代码行数:14,代码来源:Main.php

示例10: isInside

 public function isInside(Vector3 $v)
 {
     $out = true;
     switch ($this->axis) {
         case self::X:
             $out = ($out and $this->base->getX() <= $v->getX() and $v->getX() <= $this->base->getX() + $this->height);
             $out = ($out and $v->distance(new Vector3($v->getX(), $this->base->getY(), $this->base->getZ())) <= $this->radius);
             break;
         case self::Y:
             $out = ($out and $this->base->getY() <= $v->getY() and $v->getY() <= $this->base->getY() + $this->height);
             $out = ($out and $v->distance(new Vector3($this->base->getX(), $v->getY(), $this->base->getZ())) <= $this->radius);
             break;
         case self::Z:
             $out = ($out and $this->base->getZ() <= $v->getZ() and $v->getZ() <= $this->base->getZ() + $this->height);
             $out = ($out and $v->distance(new Vector3($this->base->getX(), $this->base->getY(), $v->getZ())) <= $this->radius);
             break;
     }
     if ($v instanceof Position) {
         $out = ($out and $v->getLevel()->getName() === $this->base->getLevel()->getName());
     }
     return $out;
 }
开发者ID:barnseyminesuk,项目名称:Small-ZC-Plugins,代码行数:22,代码来源:CylinderSpace.php


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