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


PHP math\Vector3类代码示例

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


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

示例1: getOptimalFlowDirections

 private function getOptimalFlowDirections()
 {
     if ($this->temporalVector === \null) {
         $this->temporalVector = new Vector3(0, 0, 0);
     }
     for ($j = 0; $j < 4; ++$j) {
         $this->flowCost[$j] = 1000;
         $x = $this->x;
         $y = $this->y;
         $z = $this->z;
         if ($j === 0) {
             --$x;
         } elseif ($j === 1) {
             ++$x;
         } elseif ($j === 2) {
             --$z;
         } elseif ($j === 3) {
             ++$z;
         }
         $block = $this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $z));
         if (!$block->canBeFlowedInto() and !$block instanceof Liquid) {
             continue;
         } elseif ($block instanceof Liquid and $block->getDamage() === 0) {
             continue;
         } elseif ($this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y - 1, $z))->canBeFlowedInto()) {
             $this->flowCost[$j] = 0;
         } else {
             $this->flowCost[$j] = $this->calculateFlowCost($block, 1, $j);
         }
     }
     $minCost = $this->flowCost[0];
     for ($i = 1; $i < 4; ++$i) {
         if ($this->flowCost[$i] < $minCost) {
             $minCost = $this->flowCost[$i];
         }
     }
     for ($i = 0; $i < 4; ++$i) {
         $this->isOptimalFlowDirection[$i] = $this->flowCost[$i] === $minCost;
     }
     return $this->isOptimalFlowDirection;
 }
开发者ID:ken77731,项目名称:PocketMine-0.13.0,代码行数:41,代码来源:Liquid.php

示例2: ifjump

 /**
  * @param Level   $level
  * @param Vector3 $v3
  * @param bool    $hate
  * @param bool    $reason
  * @return bool|float|string
  * 判断某坐标是否可以行走
  * 并给出原因
  */
 public function ifjump(Level $level, Vector3 $v3, $hate = false, $reason = false)
 {
     //boybook Y轴算法核心函数
     $x = floor($v3->getX());
     $y = floor($v3->getY());
     $z = floor($v3->getZ());
     //echo ($y." ");
     if ($this->whatBlock($level, new Vector3($x, $y, $z)) == "air") {
         //echo "前方空气 ";
         if ($this->whatBlock($level, new Vector3($x, $y - 1, $z)) == "block" or new Vector3($x, $y - 1, $z) == "climb") {
             //方块
             //echo "考虑向前 ";
             if ($this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "block" or $this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "half" or $this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "high") {
                 //上方一格被堵住了
                 //echo "上方卡住 \n";
                 if ($reason) {
                     return 'up!';
                 }
                 return false;
                 //上方卡住
             } else {
                 //echo "GO向前走 \n";
                 if ($reason) {
                     return 'GO';
                 }
                 return $y;
                 //向前走
             }
         } elseif ($this->whatBlock($level, new Vector3($x, $y - 1, $z)) == "half") {
             //半砖
             //echo "下到半砖 \n";
             if ($reason) {
                 return 'half';
             }
             return $y - 0.5;
             //向下跳0.5格
         } elseif ($this->whatBlock($level, new Vector3($x, $y - 1, $z)) == "lava") {
             //岩浆
             //echo "前方岩浆 \n";
             if ($reason) {
                 return 'lava';
             }
             return false;
             //前方岩浆
         } elseif ($this->whatBlock($level, new Vector3($x, $y - 1, $z)) == "air") {
             //空气
             //echo "考虑向下跳 ";
             if ($this->whatBlock($level, new Vector3($x, $y - 2, $z)) == "block") {
                 //echo "GO向下跳 \n";
                 if ($reason) {
                     return 'down';
                 }
                 return $y - 1;
                 //向下跳
             } else {
                 //前方悬崖
                 //echo "前方悬崖 \n";
                 if ($reason) {
                     return 'fall';
                 }
                 /*	if ($hate === false) {
                 				return false;
                 			}
                 			else {
                 				return $y-1;  //向下跳
                 			}*/
             }
         }
     } elseif ($this->whatBlock($level, new Vector3($x, $y, $z)) == "half") {
         //半砖
         //echo "前方半砖 \n";
         if ($this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "block" or $this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "half" or $this->whatBlock($level, new Vector3($x, $y + 1, $z)) == "high") {
             //上方一格被堵住了
             //return false;  //上方卡住
         } else {
             if ($reason) {
                 return 'halfGO';
             }
             return $y + 0.5;
         }
     } elseif ($this->whatBlock($level, new Vector3($x, $y, $z)) == "lava") {
         //岩浆
         //echo "前方岩浆 \n";
         if ($reason) {
             return 'lava';
         }
         return false;
     } elseif ($this->whatBlock($level, new Vector3($x, $y, $z)) == "high") {
         //1.5格高方块
         //echo "前方栅栏 \n";
         if ($reason) {
//.........这里部分代码省略.........
开发者ID:yungtechboy1,项目名称:Genisys,代码行数:101,代码来源:AIHolder.php

示例3: getSafeSpawn

 /**
  * @param Vector3 $spawn default null
  *
  * @return bool|Position
  */
 public function getSafeSpawn($spawn = null)
 {
     if (!$spawn instanceof Vector3) {
         $spawn = $this->getSpawn();
     }
     if ($spawn instanceof Vector3) {
         $x = (int) round($spawn->x);
         $y = (int) round($spawn->y);
         $z = (int) round($spawn->z);
         for (; $y > 0; --$y) {
             $v = new Vector3($x, $y, $z);
             $b = $this->getBlock($v->getSide(0));
             if ($b === false) {
                 return $spawn;
             } elseif (!$b instanceof Air) {
                 break;
             }
         }
         for (; $y < 128; ++$y) {
             $v = new Vector3($x, $y, $z);
             if ($this->getBlock($v->getSide(1)) instanceof Air) {
                 if ($this->getBlock($v) instanceof Air) {
                     return new Position($x, $y, $z, $this);
                 }
             } else {
                 ++$y;
             }
         }
         return new Position($x, $y, $z, $this);
     }
     return false;
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:37,代码来源:Level.php

示例4: isInside

 public function isInside(Vector3 $v)
 {
     if (!$this->isValid()) {
         return false;
     }
     return min($this->x1, $this->x2) <= $v->x and min($this->y1, $this->y2) <= $v->y and min($this->z1, $this->z2) <= $v->z and max($this->x1, $this->x2) >= $v->x and max($this->y1, $this->y2) >= $v->y and max($this->z1, $this->z2) >= $v->z and !$v instanceof Position or $v->getLevel()->getName() === $this->levelName;
 }
开发者ID:GoneTone,项目名称:WorldEditArt,代码行数:7,代码来源:CuboidSpace.php

示例5: __construct

 /**
  * @param Vector3 $v
  * @param mixed $data
  * @param int $id
  * @param FullChunk $chunk
  */
 public function __construct($v, $data, $id = -2, $chunk = null)
 {
     $this->data = $data;
     if (!$v instanceof Vector3) {
         if ($v instanceof FullChunk) {
             $v->removeEntity($this);
         }
         throw new \RuntimeException("BadConstructCustomHuman");
     }
     $nbt = new Compound();
     $nbt->Pos = new Enum("Motion", [new Double(0, $v->x), new Double(1, $v->y), new Double(2, $v->z)]);
     $nbt->Motion = new Enum("Motion", [new Double(0, 0), new Double(1, 0), new Double(2, 0)]);
     $nbt->Rotation = new Enum("Rotation", [new Float(0, $this->getDefaultYaw()), new Float(1, $this->getDefaultPitch())]);
     $nbt->FallDistance = new Float("FallDistance", 0);
     $nbt->Fire = new Short("Fire", 0);
     $nbt->Air = new Short("Air", 0);
     $nbt->OnGround = new Byte("OnGround", 1);
     $nbt->Invulnerable = new Byte("Invulnerable", 1);
     $nbt->Health = new Short("Health", 20);
     $nbt->NameTag = $this->getDefaultName();
     $nbt->Inventory = new Enum("Inventory", []);
     $nbt->Inventory->setTagType(NBT::TAG_Compound);
     $this->inventory = new PlayerInventory($this);
     $this->setSkin($this->getDefaultSkin());
     parent::__construct($chunk, $nbt);
 }
开发者ID:legoboy0215,项目名称:LegionPE-Theta-Base,代码行数:32,代码来源:CustomHuman.php

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

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

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

示例9: isInside

 /**
  * Checks whether the passed {@link Vector3} is included in this {@link Space}.<br>
  * Floating point vectors are accepted.<br>
  * <br>
  * The contents of this function are based on <a
  * href="http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html">Wolfram|MathWorld: Point-Lne Distance
  * (3-Dimensional)</a>, whereas {@code X0 = $v, X1 = $this->baseCenter, X2 = $this->topCenter}.
  *
  * @param Vector3 $v the coordinates to check.
  *
  * @return bool whether <code> $v</code> is inside the space.
  */
 public function isInside(Vector3 $v)
 {
     if (!$this->isValid()) {
         return false;
     }
     if ($v instanceof Position and $v->getLevel()->getName() !== $this->levelName) {
         return false;
     }
     $distSquared = $v->subtract($this->baseCenter)->cross($v->subtract($this->topCenter))->lengthSquared() / $this->topCenter->subtract($this->baseCenter)->lengthSquared();
     // |---|
     return $distSquared <= $this->radiusSquared;
     // |(X0 - X1) x (X0 - X2)| / |X2 - X1|
 }
开发者ID:GoneTone,项目名称:WorldEditArt,代码行数:25,代码来源:CylinderSpace.php

示例10: createEffectArrow

 public static function createEffectArrow(Player $player, Vector3 $position, Vector3 $speed, $yaw, $pitch, $r, $g, $b, $critical)
 {
     $nbtTag = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $position->getX()), new Double("", $position->getY()), new Double("", $position->getZ())]), "Rotation" => new Enum("Rotation", [new Float("", $yaw), new Float("", $pitch)])]);
     $arrow = new EffectArrow($player->chunk, $nbtTag, $r, $g, $b, $player, $critical);
     $arrow->setMotion($speed);
     $launchEvent = new ProjectileLaunchEvent($arrow);
     Server::getInstance()->getPluginManager()->callEvent($launchEvent);
     if ($launchEvent->isCancelled()) {
         $arrow->kill();
         return null;
     } else {
         return $arrow;
     }
 }
开发者ID:HelloWorld017,项目名称:ToAruArcher,代码行数:14,代码来源:Archery.php

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

示例12: onUpdate

 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         $faces = array_flip(array(2 => 2, 3 => 4, 4 => 5, 5 => 3));
         if ($this->getSide(Vector3::getOppositeSide($faces[$this->meta % 4 + 2]))->isTransparent() === true) {
             $this->getLevel()->useBreakOn($this);
             return Level::BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if (mt_rand(0, 2) === 1) {
             if ($this->meta < 8) {
                 $block = clone $this;
                 $block->meta += 4;
                 Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
                 if (!$ev->isCancelled()) {
                     $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
                 } else {
                     return Level::BLOCK_UPDATE_RANDOM;
                 }
             }
         } else {
             return Level::BLOCK_UPDATE_RANDOM;
         }
     }
     return false;
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:26,代码来源:CocoaPod.php

示例13: onUpdate

 public function onUpdate($currentTick)
 {
     if ($this->closed !== false) {
         return false;
     }
     $this->lastUpdate = $currentTick;
     $this->timings->startTiming();
     $hasUpdate = true;
     //parent::onUpdate($currentTick);
     if ($this->isAlive()) {
         $expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
         $expBlock0 = $this->getLevel()->getBlock($expectedPos->add(0, -1, 0)->round());
         $expBlock1 = $this->getLevel()->getBlock($expectedPos->add(0, 0, 0)->round());
         if ($expBlock0->getId() == 0) {
             $this->motionY -= $this->gravity;
             //重力计算
             $this->motionX = 0;
             $this->motionZ = 0;
         } else {
             $this->motionY = 0;
         }
         if ($expBlock1->getId() != 0) {
             $this->motionY += 0.1;
         }
         $this->move($this->motionX, $this->motionY, $this->motionZ);
         if ($this->isFreeMoving) {
             $this->motionX = 0;
             $this->motionZ = 0;
             $this->isFreeMoving = false;
         }
         /*$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:1455931078,项目名称:Genisys,代码行数:44,代码来源:Minecart.php

示例14: __construct

 public function __construct(Level $level, Vector3 $pos)
 {
     if (!($pos instanceof Vector3 && $level instanceof Level)) {
         echo "this is not Floor!\n";
     }
     $this->vector = $pos;
     $this->x = $pos->getX();
     $this->y = $pos->getY();
     $this->z = $pos->getZ();
     $this->level = $level;
     $this->block = $level->getBlock($pos);
     $this->id = $this->block->getId();
     $this->data = $this->block->getDamage();
     $this->height = 128;
     //$this->level->getHeightMap($this->x, $this->z);
     echo "max height: {$this->height}\n";
     if (!($this->isElevatorBlock($this->block) || $this->isExtensionFloorBlock($this->block))) {
         echo "THIS IS NOT FLOOR!\n";
     }
 }
开发者ID:JungHyun3459,项目名称:PMMP-Plugins,代码行数:20,代码来源:Floor.php

示例15: place

 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($face !== 0 && $face !== 1) {
         $faces = [3 => 3, 2 => 4, 4 => 2, 5 => 1];
         $this->meta = $faces[$face];
         if ($this->getSide(Vector3::getOppositeSide($face))->getId() === Block::TRIPWIRE) {
             $this->meta & 0x1;
         }
         $this->getLevel()->setBlock($block, Block::get(Block::TRIPWIRE_HOOK, $this->meta), true);
         return true;
     }
     return false;
 }
开发者ID:zzz1999,项目名称:ImagicalMine,代码行数:13,代码来源:TripwireHook.php


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