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


PHP utils\Random类代码示例

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


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

示例1: growTree

 public static function growTree(ChunkManager $level, $x, $y, $z, Random $random, $type = 0)
 {
     switch ($type) {
         case Sapling::SPRUCE:
             $tree = new SpruceTree();
             break;
         case Sapling::BIRCH:
             if ($random->nextBoundedInt(39) === 0) {
                 $tree = new BirchTree(\true);
             } else {
                 $tree = new BirchTree();
             }
             break;
         case Sapling::JUNGLE:
             $tree = new JungleTree();
             break;
         case Sapling::OAK:
         default:
             $tree = new OakTree();
             /*if($random->nextRange(0, 9) === 0){
             			$tree = new BigTree();
             		}else{*/
             //}
             break;
     }
     if ($tree->canPlaceObject($level, $x, $y, $z, $random)) {
         $tree->placeObject($level, $x, $y, $z, $random);
     }
 }
开发者ID:xpyctum,项目名称:PocketMinePlusPlus,代码行数:29,代码来源:Tree.php

示例2: execute

 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     if (count($args) < 7) {
         $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
         return true;
     }
     if ($sender instanceof Player) {
         $level = $sender->getLevel();
     } else {
         $level = $sender->getServer()->getDefaultLevel();
     }
     $name = strtolower($args[0]);
     $pos = new Vector3((double) $args[1], (double) $args[2], (double) $args[3]);
     $xd = (double) $args[4];
     $yd = (double) $args[5];
     $zd = (double) $args[6];
     $count = isset($args[7]) ? max(1, (int) $args[7]) : 1;
     $data = isset($args[8]) ? (int) $args[8] : null;
     $particle = $this->getParticle($name, $pos, $xd, $yd, $zd, $data);
     if ($particle === null) {
         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.particle.notFound", [$name]));
         return true;
     }
     $sender->sendMessage(new TranslationContainer("commands.particle.success", [$name, $count]));
     $random = new Random((int) (microtime(true) * 1000) + mt_rand());
     for ($i = 0; $i < $count; ++$i) {
         $particle->setComponents($pos->x + $random->nextSignedFloat() * $xd, $pos->y + $random->nextSignedFloat() * $yd, $pos->z + $random->nextSignedFloat() * $zd);
         $level->addParticle($particle);
     }
     return true;
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:34,代码来源:ParticleCommand.php

示例3: execute

 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return \true;
     }
     if (\count($args) < 7) {
         return \true;
     }
     if ($sender instanceof Player) {
         $level = $sender->getLevel();
     } else {
         $level = $sender->getServer()->getDefaultLevel();
     }
     $name = \strtolower($args[0]);
     $pos = new Vector3((double) $args[1], (double) $args[2], (double) $args[3]);
     $xd = (double) $args[4];
     $yd = (double) $args[5];
     $zd = (double) $args[6];
     $count = isset($args[7]) ? \max(1, (int) $args[7]) : 1;
     $data = isset($args[8]) ? (int) $args[8] : \null;
     $particle = $this->getParticle($name, $pos, $xd, $yd, $zd, $data);
     if ($particle === \null) {
         return \true;
     }
     $random = new Random((int) (\microtime(\true) * 1000) + \mt_rand());
     for ($i = 0; $i < $count; ++$i) {
         $particle->setComponents($pos->x + $random->nextSignedFloat() * $xd, $pos->y + $random->nextSignedFloat() * $yd, $pos->z + $random->nextSignedFloat() * $zd);
         $level->addParticle($particle);
     }
     return \true;
 }
开发者ID:Edwardthedog2,项目名称:Steadfast2,代码行数:31,代码来源:ParticleCommand.php

示例4: placeObject

 public function placeObject(ChunkManager $level, $x, $y, $z, Random $random)
 {
     $this->treeHeight = $random->nextBoundedInt(4) + 6;
     $topSize = $this->treeHeight - (1 + $random->nextBoundedInt(2));
     $lRadius = 2 + $random->nextBoundedInt(2);
     $this->placeTrunk($level, $x, $y, $z, $random, $this->treeHeight - $random->nextBoundedInt(3));
     $radius = $random->nextBoundedInt(2);
     $maxR = 1;
     $minR = 0;
     for ($yy = 0; $yy <= $topSize; ++$yy) {
         $yyy = $y + $this->treeHeight - $yy;
         for ($xx = $x - $radius; $xx <= $x + $radius; ++$xx) {
             $xOff = abs($xx - $x);
             for ($zz = $z - $radius; $zz <= $z + $radius; ++$zz) {
                 $zOff = abs($zz - $z);
                 if ($xOff === $radius and $zOff === $radius and $radius > 0) {
                     continue;
                 }
                 if (!Block::$solid[$level->getBlockIdAt($xx, $yyy, $zz)]) {
                     $level->setBlockIdAt($xx, $yyy, $zz, $this->leafBlock);
                     $level->setBlockDataAt($xx, $yyy, $zz, $this->type);
                 }
             }
         }
         if ($radius >= $maxR) {
             $radius = $minR;
             $minR = 1;
             if (++$maxR > $lRadius) {
                 $maxR = $lRadius;
             }
         } else {
             ++$radius;
         }
     }
 }
开发者ID:TexusDark,项目名称:Ananas-MP,代码行数:35,代码来源:SpruceTree.php

示例5: growTree

 public static function growTree(ChunkManager $level, $x, $y, $z, Random $random, $type = 0)
 {
     switch ($type & 0x3) {
         case Sapling::SPRUCE:
             if ($random->nextRange(0, 1) === 1) {
                 $tree = new SpruceTree();
             } else {
                 $tree = new PineTree();
             }
             break;
         case Sapling::BIRCH:
             $tree = new SmallTree();
             $tree->type = Sapling::BIRCH;
             break;
         case Sapling::JUNGLE:
             $tree = new SmallTree();
             $tree->type = Sapling::JUNGLE;
             break;
         case Sapling::OAK:
         default:
             /*if($random->nextRange(0, 9) === 0){
             			$tree = new BigTree();
             		}else{*/
             $tree = new SmallTree();
             //}
             break;
     }
     if ($tree->canPlaceObject($level, $x, $y, $z, $random)) {
         $tree->placeObject($level, $x, $y, $z, $random);
     }
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:31,代码来源:Tree.php

示例6: placeObject

 public function placeObject(ChunkManager $level, $x, $y, $z, Random $random)
 {
     $this->treeHeight = $random->nextBoundedInt(3) + 5;
     if ($this->superBirch) {
         $this->treeHeight += 5;
     }
     parent::placeObject($level, $x, $y, $z, $random);
 }
开发者ID:kazuemon,项目名称:NIGHTMARE,代码行数:8,代码来源:BirchTree.php

示例7: addParticles

 public static function addParticles(Level $level, $name, Position $pos1, $count = 5)
 {
     $xd = (double) 280;
     $yd = (double) 260;
     $zd = (double) 280;
     $particle1 = self::getParticle($name, $pos1, $xd, $yd, $zd, 0);
     $random = new Random((int) (\microtime(\true) * 1000) + \mt_rand());
     for ($i = 0; $i < $count; ++$i) {
         $particle1->setComponents($pos1->x + $random->nextSignedFloat() * $xd, $pos1->y + $random->nextSignedFloat() * $yd, $pos1->z + $random->nextSignedFloat() * $zd);
         $level->addParticle($particle1);
     }
 }
开发者ID:robozeri,项目名称:SG,代码行数:12,代码来源:StatueBuilder.php

示例8: populate

 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     $this->level = $level;
     $type = new OreType(new Glowstone(), 1, 20, 128, 10);
     $ore = new ObjectOre($random, $type);
     for ($i = 0; $i < $ore->type->clusterCount; ++$i) {
         $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
         $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
         $y = $this->getHighestWorkableBlock($x, $z);
         $ore->placeObject($level, $x, $y, $z);
     }
 }
开发者ID:xpyctum,项目名称:Genisys,代码行数:12,代码来源:NetherGrowStone.php

示例9: populate

 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     if ($random->nextRange(0, $this->waterOdd) === 0) {
         $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16);
         $y = $random->nextBoundedInt(128);
         $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16);
         $pond = new \pocketmine\level\generator\object\Pond($random, new Water());
         if ($pond->canPlaceObject($level, $x, $y, $z)) {
             $pond->placeObject($level, $x, $y, $z);
         }
     }
 }
开发者ID:xHFx,项目名称:ImagicalMine,代码行数:12,代码来源:Pond.php

示例10: populate

 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     $this->level = $level;
     $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
     for ($i = 0; $i < $amount; ++$i) {
         $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
         $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
         $y = $this->getHighestWorkableBlock($x, $z);
         if ($y === -1) {
             continue;
         }
         ObjectTree::growTree($this->level, $x, $y, $z, $random, $this->type);
     }
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:14,代码来源:Tree.php

示例11: growGrass

 public static function growGrass(ChunkManager $level, Vector3 $pos, Random $random, $count = 15, $radius = 10)
 {
     $arr = [[Block::DANDELION, 0], [Block::POPPY, 0], [Block::TALL_GRASS, 1], [Block::TALL_GRASS, 1], [Block::TALL_GRASS, 1], [Block::TALL_GRASS, 1]];
     $arrC = \count($arr) - 1;
     for ($c = 0; $c < $count; ++$c) {
         $x = $random->nextRange($pos->x - $radius, $pos->x + $radius);
         $z = $random->nextRange($pos->z - $radius, $pos->z + $radius);
         if ($level->getBlockIdAt($x, $pos->y + 1, $z) === Block::AIR and $level->getBlockIdAt($x, $pos->y, $z) === Block::GRASS) {
             $t = $arr[$random->nextRange(0, $arrC)];
             $level->setBlockIdAt($x, $pos->y + 1, $z, $t[0]);
             $level->setBlockDataAt($x, $pos->y + 1, $z, $t[1]);
         }
     }
 }
开发者ID:xpyctum,项目名称:PocketMinePlusPlus,代码行数:14,代码来源:TallGrass.php

示例12: populate

 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     $this->level = $level;
     $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
     for ($i = 0; $i < $amount; ++$i) {
         $x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15);
         $z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15);
         $y = $this->getHighestWorkableBlock($x, $z);
         //echo "Fire to $x, $y, $z\n";
         if ($y !== -1 and $this->canGroundFireStay($x, $y, $z)) {
             $this->level->setBlockIdAt($x, $y, $z, Block::FIRE);
         }
     }
 }
开发者ID:xpyctum,项目名称:Genisys,代码行数:14,代码来源:GroundFire.php

示例13: populate

 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     foreach ($this->oreTypes as $type) {
         $ore = new ObjectOre($random, $type);
         for ($i = 0; $i < $ore->type->clusterCount; ++$i) {
             $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
             $y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight);
             $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
             if ($ore->canPlaceObject($level, $x, $y, $z)) {
                 $ore->placeObject($level, $x, $y, $z);
             }
         }
     }
 }
开发者ID:xpyctum,项目名称:PocketMinePlusPlus,代码行数:14,代码来源:Ore.php

示例14: populate

 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     $this->level = $level;
     $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
     for ($i = 0; $i < $amount; ++$i) {
         $x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15);
         $z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15);
         $y = $this->getHighestWorkableBlock($x, $z);
         if ($y !== -1 and $this->canLilyPadStay($x, $y, $z)) {
             $this->level->setBlockIdAt($x, $y, $z, Block::WATER_LILY);
             $this->level->setBlockDataAt($x, $y, $z, 1);
         }
     }
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:14,代码来源:LilyPad.php

示例15: populate

 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     if (mt_rand(0, 100) < 5) {
         $this->level = $level;
         $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
         for ($i = 0; $i < $amount; ++$i) {
             $x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15);
             $z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15);
             $y = $this->getHighestWorkableBlock($x, $z);
             if ($y !== -1 and $this->canNetherLavaStay($x, $y, $z)) {
                 $this->level->setBlockIdAt($x, $y, $z, Block::LAVA);
                 $this->level->updateBlockLight($x, $y, $z);
                 $this->lavaSpread($x, $y, $z);
             }
         }
     }
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:17,代码来源:NetherLava.php


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