當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Random::nextRange方法代碼示例

本文整理匯總了PHP中pocketmine\utils\Random::nextRange方法的典型用法代碼示例。如果您正苦於以下問題:PHP Random::nextRange方法的具體用法?PHP Random::nextRange怎麽用?PHP Random::nextRange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pocketmine\utils\Random的用法示例。


在下文中一共展示了Random::nextRange方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

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

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

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

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

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

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

示例8: growTree

 public static function growTree(ChunkManager $level, $x, $y, $z, Random $random, $type = 0, bool $noBigTree = true)
 {
     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::ACACIA:
             $tree = new AcaciaTree();
             break;
         case Sapling::DARK_OAK:
             $tree = new DarkOakTree();
             break;
         case Sapling::OAK:
         default:
             if (!$noBigTree and $random->nextRange(0, 9) === 0) {
                 $tree = new BigTree();
             } else {
                 $tree = new OakTree();
             }
             break;
     }
     if ($tree->canPlaceObject($level, $x, $y, $z, $random)) {
         $tree->placeObject($level, $x, $y, $z, $random);
     }
 }
開發者ID:iTXTech,項目名稱:Genisys,代碼行數:35,代碼來源:Tree.php

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

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

示例11: 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);
         for ($size = 30; $size > 0; --$size) {
             $xx = $x - 7 + $random->nextRange(0, 15);
             $zz = $z - 7 + $random->nextRange(0, 15);
             $yy = $this->getHighestWorkableBlock($xx, $zz);
             if ($yy !== -1 and $this->canTallGrassStay($xx, $yy, $zz)) {
                 $this->level->setBlockIdAt($xx, $yy, $zz, Block::TALL_GRASS);
                 $this->level->setBlockDataAt($xx, $yy, $zz, 1);
             }
         }
     }
 }
開發者ID:boybook,項目名稱:PocketMine-MP,代碼行數:18,代碼來源: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);
         $tallRand = $random->nextRange(0, 17);
         $yMax = $y + 1 + (int) ($tallRand > 10) + (int) ($tallRand > 15);
         if ($y !== -1) {
             for (; $y < 127 and $y < $yMax; $y++) {
                 if ($this->canCactusStay($x, $y, $z)) {
                     $this->level->setBlockIdAt($x, $y, $z, Block::CACTUS);
                     $this->level->setBlockDataAt($x, $y, $z, 1);
                 }
             }
         }
     }
 }
開發者ID:iTXTech,項目名稱:Genisys,代碼行數:20,代碼來源:Cactus.php

示例13: populate

 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     $this->level = $level;
     $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
     if (count($this->flowerTypes) === 0) {
         $this->addType([Block::DANDELION, 0]);
         $this->addType([Block::RED_FLOWER, FlowerBlock::TYPE_POPPY]);
     }
     $endNum = count($this->flowerTypes) - 1;
     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->canFlowerStay($x, $y, $z)) {
             $type = mt_rand(0, $endNum);
             $this->level->setBlockIdAt($x, $y, $z, $this->flowerTypes[$type][0]);
             $this->level->setBlockDataAt($x, $y, $z, $this->flowerTypes[$type][1]);
         }
     }
 }
開發者ID:Creeperface01,項目名稱:ImagicalMine,代碼行數:20,代碼來源:Flower.php

示例14: placeObject

 public function placeObject(ChunkManager $level, $x, $y, $z, Random $random)
 {
     // The base dirt block
     $level->setBlockIdAt($x, $y, $z, Block::DIRT);
     // Adjust the tree trunk's height randomly
     //    plot [-14:11] int( x / 8 ) + 5
     //    - min=4 (all leaves are 4 tall, some trunk must show)
     //    - max=6 (top leaves are within ground-level whacking range
     //             on all small trees)
     $heightPre = $random->nextRange(-14, 11);
     $this->trunkHeight = intval($heightPre / 8) + 5;
     // Adjust the starting leaf density using the trunk height as a
     // starting position (tall trees with skimpy leaves don't look
     // too good)
     $leafPre = $random->nextRange($this->trunkHeight, 10) / 20;
     // (TODO: seed may apply)
     // Now build the tree (from the top down)
     $leaflevel = 0;
     for ($yy = $this->trunkHeight + 1; $yy >= 0; --$yy) {
         if ($leaflevel < self::$leavesHeight) {
             // The size is a slight variation on the trunkheight
             $radius = self::$leafRadii[$leaflevel] + $leafPre;
             $bRadius = 3;
             for ($xx = -$bRadius; $xx <= $bRadius; ++$xx) {
                 for ($zz = -$bRadius; $zz <= $bRadius; ++$zz) {
                     if (sqrt($xx ** 2 + $zz ** 2) <= $radius) {
                         $level->setBlockIdAt($x + $xx, $y + $yy, $z + $zz, Block::LEAVES);
                         $level->setBlockDataAt($x + $xx, $y + $yy, $z + $zz, $this->type);
                     }
                 }
             }
             $leaflevel++;
         }
         // Place the trunk last
         if ($leaflevel > 1) {
             $level->setBlockIdAt($x, $y + $yy, $z, Block::TRUNK);
             $level->setBlockDataAt($x, $y + $yy, $z, $this->type);
         }
     }
 }
開發者ID:rryy,項目名稱:PocketMine-MP,代碼行數:40,代碼來源:SmallTree.php

示例15: __construct

 public function __construct(Random $random, $octaves, $frequency, $amplitude)
 {
     $this->octaves = $octaves;
     $this->frequency = $frequency;
     $this->amplitude = $amplitude;
     $this->offsetX = $random->nextFloat() * 256;
     $this->offsetY = $random->nextFloat() * 256;
     $this->offsetZ = $random->nextFloat() * 256;
     for ($i = 0; $i < 512; ++$i) {
         $this->perm[$i] = 0;
     }
     for ($i = 0; $i < 256; ++$i) {
         $this->perm[$i] = $random->nextRange(0, 255);
     }
     for ($i = 0; $i < 256; ++$i) {
         $pos = $random->nextRange(0, 255 - $i) + $i;
         $old = $this->perm[$i];
         $this->perm[$i] = $this->perm[$pos];
         $this->perm[$pos] = $old;
         $this->perm[$i + 256] = $this->perm[$i];
     }
 }
開發者ID:boybook,項目名稱:PocketMine-MP,代碼行數:22,代碼來源:Perlin.php


注:本文中的pocketmine\utils\Random::nextRange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。