本文整理汇总了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);
}
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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]);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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);
}
}
}
}