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


PHP math\Math类代码示例

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


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

示例1: getNearbyEntities

 /**
  * Returns the entities near the current one inside the AxisAlignedBB
  *
  * @param AxisAlignedBB $bb
  * @param Entity        $entity
  *
  * @return Entity[]
  */
 public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null)
 {
     $nearby = [];
     $minX = Math::floorFloat(($bb->minX - 2) / 16);
     $maxX = Math::ceilFloat(($bb->maxX + 2) / 16);
     $minZ = Math::floorFloat(($bb->minZ - 2) / 16);
     $maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16);
     for ($x = $minX; $x <= $maxX; ++$x) {
         for ($z = $minZ; $z <= $maxZ; ++$z) {
             foreach ($this->getChunkEntities($x, $z) as $ent) {
                 if ($ent !== $entity and $ent->boundingBox->intersectsWith($bb)) {
                     $nearby[] = $ent;
                 }
             }
         }
     }
     return $nearby;
 }
开发者ID:robozeri,项目名称:Yuriko-MP,代码行数:26,代码来源:Level.php

示例2: isInsideOfWater

 public function isInsideOfWater()
 {
     $block = $this->level->getBlock($this->temporalVector->setComponents(Math::floorFloat($this->x), Math::floorFloat($y = $this->y + $this->getEyeHeight()), Math::floorFloat($this->z)));
     if ($block instanceof Water) {
         $f = $block->y + 1 - ($block->getFluidHeightPercent() - 0.1111111);
         return $y < $f;
     }
     return false;
 }
开发者ID:Cecil107,项目名称:PocketMine-0.13.0,代码行数:9,代码来源:Entity.php

示例3: getBlocksAround

 public function getBlocksAround()
 {
     if ($this->blocksAround === null) {
         $minX = Math::floorFloat($this->boundingBox->minX);
         $minY = Math::floorFloat($this->boundingBox->minY);
         $minZ = Math::floorFloat($this->boundingBox->minZ);
         $maxX = Math::ceilFloat($this->boundingBox->maxX);
         $maxY = Math::ceilFloat($this->boundingBox->maxY);
         $maxZ = Math::ceilFloat($this->boundingBox->maxZ);
         $this->blocksAround = [];
         for ($z = $minZ; $z <= $maxZ; ++$z) {
             for ($x = $minX; $x <= $maxX; ++$x) {
                 for ($y = $minY; $y <= $maxY; ++$y) {
                     $block = $this->level->getBlock($this->temporalVector->setComponents($x, $y, $z));
                     if ($block->hasEntityCollision()) {
                         $this->blocksAround[] = $block;
                     }
                 }
             }
         }
     }
     return $this->blocksAround;
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:23,代码来源:Entity.php

示例4: checkBlockCollision

 protected function checkBlockCollision()
 {
     $minX = Math::floorFloat($this->boundingBox->minX + 0.001);
     $minY = Math::floorFloat($this->boundingBox->minY + 0.001);
     $minZ = Math::floorFloat($this->boundingBox->minZ + 0.001);
     $maxX = Math::floorFloat($this->boundingBox->maxX - 0.001);
     $maxY = Math::floorFloat($this->boundingBox->maxY - 0.001);
     $maxZ = Math::floorFloat($this->boundingBox->maxZ - 0.001);
     $vector = new Vector3(0, 0, 0);
     $v = new Vector3(0, 0, 0);
     for ($v->z = $minZ; $v->z <= $maxZ; ++$v->z) {
         for ($v->x = $minX; $v->x <= $maxX; ++$v->x) {
             for ($v->y = $minY; $v->y <= $maxY; ++$v->y) {
                 $block = $this->level->getBlock($v);
                 if ($block->hasEntityCollision()) {
                     $block->onEntityCollide($this);
                     if (!$this instanceof Player) {
                         $block->addVelocityToEntity($this, $vector);
                     }
                 }
             }
         }
     }
     if (!$this instanceof Player and $vector->length() > 0) {
         $vector = $vector->normalize();
         $d = 0.014;
         $this->motionX += $vector->x * $d;
         $this->motionY += $vector->y * $d;
         $this->motionZ += $vector->z * $d;
     }
 }
开发者ID:Cybertechpp,项目名称:Steadfast2,代码行数:31,代码来源:Entity.php

示例5: getLevelFromXp

 /**
  * Converts a quantity of exp into a level and a progress percentage
  *
  * @param int $xp
  *
  * @return int[]
  */
 public static function getLevelFromXp(int $xp) : array
 {
     $xp &= 0x7fffffff;
     /** These values are correct up to and including level 16 */
     $a = 1;
     $b = 6;
     $c = -$xp;
     if ($xp > self::getTotalXpRequirement(16)) {
         /** Modify the coefficients to fit the relevant equation */
         if ($xp <= self::getTotalXpRequirement(31)) {
             /** Levels 16-31 */
             $a = 2.5;
             $b = -40.5;
             $c += 360;
         } else {
             /** Level 32+ */
             $a = 4.5;
             $b = -162.5;
             $c += 2220;
         }
     }
     $answer = max(Math::solveQuadratic($a, $b, $c));
     //Use largest result value
     $level = floor($answer);
     $progress = $answer - $level;
     return [$level, $progress];
 }
开发者ID:kniffo80,项目名称:Genisys,代码行数:34,代码来源:Human.php

示例6: onTick

 public function onTick()
 {
     foreach ($this->getServer()->getOnlinePlayers() as $p) {
         if ($p->hasPermission("debe.damageblock.inv")) {
             continue;
         }
         $bb = $p->getBoundingBox();
         $minX = Math::floorFloat($bb->minX - 0.001);
         $minY = Math::floorFloat($bb->minY - 0.001);
         $minZ = Math::floorFloat($bb->minZ - 0.001);
         $maxX = Math::floorFloat($bb->maxX + 0.001);
         $maxY = Math::floorFloat($bb->maxY + 0.001);
         $maxZ = Math::floorFloat($bb->maxZ + 0.001);
         $block = [];
         $damage = 0;
         for ($z = $minZ; $z <= $maxZ; ++$z) {
             for ($x = $minX; $x <= $maxX; ++$x) {
                 for ($y = $minY; $y <= $maxY; ++$y) {
                     $getDamage = $this->getDamage($p->getLevel()->getBlock(new Vector3($x, $y, $z)));
                     if (!in_array($getDamage[1], $block)) {
                         $damage += $getDamage[0];
                         $block[] = $getDamage[1];
                     }
                 }
             }
         }
         if ($damage !== 0) {
             $p->attack($damage);
         }
     }
 }
开发者ID:stoastye85,项目名称:Plugins,代码行数:31,代码来源:DamageBlock.php

示例7: updateMove

 public function updateMove()
 {
     if (!$this->isMovement()) {
         return null;
     }
     /** @var Vector3 $target */
     if ($this->attacker instanceof Entity) {
         if ($this->atkTime == 16) {
             $target = $this->attacker;
             $x = $target->x - $this->x;
             $z = $target->z - $this->z;
             $diff = abs($x) + abs($z);
             $this->motionX = -0.5 * ($diff == 0 ? 0 : $x / $diff);
             $this->motionZ = -0.5 * ($diff == 0 ? 0 : $z / $diff);
             --$this->atkTime;
         }
         $y = [11 => 0.3, 12 => 0.3, 13 => 0.4, 14 => 0.4, 15 => 0.5, 16 => 0.5];
         $this->move($this->motionX, isset($y[$this->atkTime]) ? $y[$this->atkTime] : -0.2, $this->motionZ);
         if (--$this->atkTime <= 0) {
             $this->attacker = null;
             $this->motionX = 0;
             $this->motionY = 0;
             $this->motionZ = 0;
         }
         return null;
     }
     $before = $this->baseTarget;
     $this->checkTarget();
     if ($this->baseTarget instanceof Creature or $before !== $this->baseTarget) {
         $x = $this->baseTarget->x - $this->x;
         $y = $this->baseTarget->y - $this->y;
         $z = $this->baseTarget->z - $this->z;
         if ($this->stayTime > 0 || $x ** 2 + $z ** 2 < 0.5) {
             $this->motionX = 0;
             $this->motionZ = 0;
         } else {
             $diff = abs($x) + abs($z);
             $this->motionX = $this->speed * 0.15 * ($x / $diff);
             $this->motionZ = $this->speed * 0.15 * ($z / $diff);
         }
         //$this->yaw = rad2deg(atan2($z, $x) - M_PI_2);
         $this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
         $this->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt($x ** 2 + $z ** 2)));
     }
     $target = $this->mainTarget != null ? $this->mainTarget : $this->baseTarget;
     if ($this->stayTime > 0) {
         --$this->stayTime;
     } else {
         $isJump = false;
         $dx = $this->motionX;
         $dy = $this->motionY;
         $dz = $this->motionZ;
         $be = new Vector2($this->x + $dx, $this->z + $dz);
         $this->move($dx, $dy, $dz);
         $af = new Vector2($this->x, $this->z);
         if ($be->x != $af->x || $be->y != $af->y) {
             $x = 0;
             $z = 0;
             if ($be->x - $af->x != 0) {
                 $x += $be->x - $af->x > 0 ? 1 : -1;
             }
             if ($be->y - $af->y != 0) {
                 $z += $be->y - $af->y > 0 ? 1 : -1;
             }
             $block = $this->level->getBlock((new Vector3(Math::floorFloat($be->x) + $x, $this->y, Math::floorFloat($af->y) + $z))->floor());
             $block2 = $this->level->getBlock((new Vector3(Math::floorFloat($be->x) + $x, $this->y + 1, Math::floorFloat($af->y) + $z))->floor());
             if (!$block->canPassThrough()) {
                 $bb = $block2->getBoundingBox();
                 if ($block2->canPassThrough() || ($bb == null || $bb != null && $bb->maxY - $this->y <= 1)) {
                     $isJump = true;
                     $this->motionY = 0.2;
                 } else {
                     if ($this->level->getBlock($block->add(-$x, 0, -$z))->getId() == Item::LADDER) {
                         $isJump = true;
                         $this->motionY = 0.2;
                     }
                 }
             }
             if (!$isJump) {
                 $this->moveTime = 0;
             }
         }
         if ($this->onGround && !$isJump) {
             $this->motionY = 0;
         } elseif (!$isJump) {
             $this->motionY -= $this->gravity;
         }
     }
     $this->updateMovement();
     return $target;
 }
开发者ID:organization,项目名称:DummyPlayer,代码行数:91,代码来源:WalkEntity.php

示例8: getNearestRail

 /**
  * @return Rail
  */
 public function getNearestRail()
 {
     $minX = Math::floorFloat($this->boundingBox->minX);
     $minY = Math::floorFloat($this->boundingBox->minY);
     $minZ = Math::floorFloat($this->boundingBox->minZ);
     $maxX = Math::ceilFloat($this->boundingBox->maxX);
     $maxY = Math::ceilFloat($this->boundingBox->maxY);
     $maxZ = Math::ceilFloat($this->boundingBox->maxZ);
     $rails = [];
     for ($z = $minZ; $z <= $maxZ; ++$z) {
         for ($x = $minX; $x <= $maxX; ++$x) {
             for ($y = $minY; $y <= $maxY; ++$y) {
                 $block = $this->level->getBlock($this->temporalVector->setComponents($x, $y, $z));
                 if (in_array($block->getId(), [Block::RAIL, Block::ACTIVATOR_RAIL, Block::DETECTOR_RAIL, Block::POWERED_RAIL])) {
                     $rails[] = $block;
                 }
             }
         }
     }
     $minDistance = PHP_INT_MAX;
     $nearestRail = null;
     foreach ($rails as $rail) {
         $dis = $this->distance($rail);
         if ($dis < $minDistance) {
             $nearestRail = $rail;
             $minDistance = $dis;
         }
     }
     return $nearestRail;
 }
开发者ID:yungtechboy1,项目名称:Genisys,代码行数:33,代码来源:Minecart.php

示例9: updateMove

 public function updateMove(int $tickDiff)
 {
     if (!$this->isMovement()) {
         return null;
     }
     if ($this->isKnockback()) {
         $this->move($this->motionX * $tickDiff, $this->motionY, $this->motionZ * $tickDiff);
         $this->motionY -= 0.15 * $tickDiff;
         $this->updateMovement();
         return null;
     }
     $before = $this->baseTarget;
     $this->checkTarget();
     if ($this->baseTarget instanceof Creature or $before !== $this->baseTarget) {
         $x = $this->baseTarget->x - $this->x;
         $y = $this->baseTarget->y - $this->y;
         $z = $this->baseTarget->z - $this->z;
         if ($this->stayTime > 0 || $x ** 2 + $z ** 2 < 0.7) {
             $this->motionX = 0;
             $this->motionZ = 0;
         } else {
             $diff = abs($x) + abs($z);
             $this->motionX = $this->getSpeed() * 0.15 * ($x / $diff);
             $this->motionZ = $this->getSpeed() * 0.15 * ($z / $diff);
         }
         $this->yaw = -atan2($this->motionX, $this->motionZ) * 180 / M_PI;
         $this->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt($x ** 2 + $z ** 2)));
     }
     $target = $this->mainTarget != null ? $this->mainTarget : $this->baseTarget;
     if ($this->stayTime > 0) {
         $this->stayTime -= 1;
     } else {
         $isJump = false;
         $dx = $this->motionX * $tickDiff;
         $dy = $this->motionY * $tickDiff;
         $dz = $this->motionZ * $tickDiff;
         $be = new Vector2($this->x + $dx, $this->z + $dz);
         $this->move($dx, $dy, $dz);
         $af = new Vector2($this->x, $this->z);
         if ($be->x != $af->x || $be->y != $af->y) {
             $x = 0;
             $z = 0;
             if ($be->x - $af->x != 0) {
                 $x += $be->x - $af->x > 0 ? 1 : -1;
             }
             if ($be->y - $af->y != 0) {
                 $z += $be->y - $af->y > 0 ? 1 : -1;
             }
             $vec = new Vector3(Math::floorFloat($be->x), (int) $this->y, Math::floorFloat($be->y));
             $block = $this->level->getBlock($vec->add($x, 0, $z));
             $block2 = $this->level->getBlock($vec->add($x, 1, $z));
             if (!$block->canPassThrough()) {
                 $bb = $block2->getBoundingBox();
                 if ($this->motionY > -$this->gravity * 4 && ($block2->canPassThrough() || ($bb == null || $bb != null && $bb->maxY - $this->y <= 1))) {
                     $isJump = true;
                     if ($this->motionY >= 0.3) {
                         $this->motionY += $this->gravity;
                     } else {
                         $this->motionY = 0.3;
                     }
                 } elseif ($this->level->getBlock($vec)->getId() == Item::LADDER) {
                     $isJump = true;
                     $this->motionY = 0.15;
                 }
             }
             if (!$isJump) {
                 $this->moveTime -= 90 * $tickDiff;
             }
         }
         if ($this->onGround && !$isJump) {
             $this->motionY = 0;
         } elseif (!$isJump) {
             if ($this->motionY > -$this->gravity * 4) {
                 $this->motionY = -$this->gravity * 4;
             } else {
                 $this->motionY -= $this->gravity;
             }
         }
     }
     $this->updateMovement();
     return $target;
 }
开发者ID:steveritter,项目名称:EntityManager,代码行数:82,代码来源:WalkingEntity.php

示例10: checkBlockCollision

 protected function checkBlockCollision()
 {
     $minX = Math::ceilFloat($this->boundingBox->minX);
     $minY = Math::ceilFloat($this->boundingBox->minY);
     $minZ = Math::ceilFloat($this->boundingBox->minZ);
     $maxX = Math::floorFloat($this->boundingBox->maxX);
     $maxY = Math::floorFloat($this->boundingBox->maxY);
     $maxZ = Math::floorFloat($this->boundingBox->maxZ);
     $blocksInside = [];
     for ($z = $minZ; $z <= $maxZ; ++$z) {
         for ($x = $minX; $x <= $maxX; ++$x) {
             for ($y = $minY; $y <= $maxY; ++$y) {
                 $block = $this->level->getBlock($this->temporalVector->setComponents($x, $y, $z));
                 if ($block->hasEntityCollision()) {
                     $blocksInside[Level::blockHash($block->x, $block->y, $block->z)] = $block;
                 }
             }
         }
     }
     foreach ($blocksInside as $block) {
         $block->onEntityCollide($this);
     }
 }
开发者ID:robske110,项目名称:ClearSky,代码行数:23,代码来源:Player.php

示例11: entityBaseTick

 public function entityBaseTick($tickDiff = 1)
 {
     Timings::$timerEntityBaseTick->startTiming();
     if (!$this->isCreated()) {
         return false;
     }
     $hasUpdate = Entity::entityBaseTick($tickDiff);
     if ($this->attackTime > 0) {
         $this->attackTime -= $tickDiff;
     }
     if ($this->isInsideOfSolid()) {
         $hasUpdate = true;
         $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
         $this->attack($ev->getFinalDamage(), $ev);
     }
     if ($this instanceof Enderman) {
         if ($this->level->getBlock(new Vector3(Math::floorFloat($this->x), (int) $this->y, Math::floorFloat($this->z))) instanceof Water) {
             $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
             $this->attack($ev->getFinalDamage(), $ev);
             $this->move(mt_rand(-20, 20), mt_rand(-20, 20), mt_rand(-20, 20));
         }
     } else {
         if (!$this->hasEffect(Effect::WATER_BREATHING) && $this->isInsideOfWater()) {
             $hasUpdate = true;
             $airTicks = $this->getDataProperty(self::DATA_AIR) - $tickDiff;
             if ($airTicks <= -20) {
                 $airTicks = 0;
                 $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
                 $this->attack($ev->getFinalDamage(), $ev);
             }
             $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks);
         } else {
             $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300);
         }
     }
     Timings::$timerEntityBaseTick->stopTiming();
     return $hasUpdate;
 }
开发者ID:rilex04,项目名称:EntityManager,代码行数:38,代码来源:Monster.php

示例12: isInsidePortal

 public function isInsidePortal(Player $player)
 {
     $block = $player->getLevel()->getBlock($player->temporalVector->setComponents(Math::floorFloat($player->x), Math::floorFloat($y = $player->y + $player->getEyeHeight()), Math::floorFloat($player->z)));
     return $block->getId() == 90;
 }
开发者ID:JiangsNetworkAlpha,项目名称:JiangsNeather,代码行数:5,代码来源:NetherWorld.php

示例13: getCollisionCubes

 /**
  * @param AxisAlignedBB $bb
  *
  * @return Block[]|Entity[]
  */
 public function getCollisionCubes(AxisAlignedBB $bb)
 {
     $minX = Math::floorFloat($bb->minX);
     $minY = Math::floorFloat($bb->minY);
     $minZ = Math::floorFloat($bb->minZ);
     $maxX = Math::ceilFloat($bb->maxX);
     $maxY = Math::ceilFloat($bb->maxY);
     $maxZ = Math::ceilFloat($bb->maxZ);
     $collides = [];
     $v = new Vector3();
     for ($v->z = $minZ; $v->z <= $maxZ; ++$v->z) {
         for ($v->x = $minX; $v->x <= $maxX; ++$v->x) {
             for ($v->y = $minY - 1; $v->y <= $maxY; ++$v->y) {
                 $block = $this->level->getBlock($v);
                 if ($block->getBoundingBox() !== null) {
                     $collides[] = $block;
                 }
             }
         }
     }
     return $collides;
 }
开发者ID:Cybertechpp,项目名称:EntityManager,代码行数:27,代码来源:BaseEntity.php

示例14: clamp

 private function clamp(Vector3 $pos)
 {
     return new Vector3(Math::clamp($pos->getFloorX(), 0, 16), Math::clamp($pos->getFloorY(), 1, 120), Math::clamp($pos->getFloorZ(), 0, 16));
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:4,代码来源:Cave.php

示例15: getSafeSpawn

 /**
  * @param Vector3 $spawn default null
  *
  * @return bool|Position
  */
 public function getSafeSpawn($spawn = null)
 {
     if (!$spawn instanceof Vector3) {
         $spawn = $this->getSpawnLocation();
     }
     if ($spawn instanceof Vector3) {
         $v = $spawn->floor();
         $chunk = $this->getChunk($v->x >> 4, $v->z >> 4, false);
         $x = $v->x & 0xf;
         $z = $v->z & 0xf;
         if ($chunk !== null) {
             for (; $v->y > 0; --$v->y) {
                 if ($v->y < 127 and Block::$solid[$chunk->getBlockId($x, $v->y & 0x7f, $z)]) {
                     $v->y++;
                     break;
                 }
             }
             for (; $v->y < 128; ++$v->y) {
                 if (!Block::$solid[$chunk->getBlockId($x, $v->y + 1, $z)]) {
                     if (!Block::$solid[$chunk->getBlockId($x, $v->y, $z)]) {
                         return new Position($spawn->x, $v->y === Math::floorFloat($spawn->y) ? $spawn->y : $v->y, $spawn->z, $this);
                     }
                 } else {
                     ++$v->y;
                 }
             }
         }
         return new Position($spawn->x, $v->y, $spawn->z, $this);
     }
     return false;
 }
开发者ID:RedstoneAlmeida,项目名称:Steadfast2,代码行数:36,代码来源:Level.php


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