作者:xpyctu
项目:PocketMinePlusPlu
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);
}
}
作者:ClearSkyTea
项目:ClearSk
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;
}
作者:Edwardthedog
项目:Steadfast
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;
}
作者:TexusDar
项目:Ananas-M
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;
}
}
}
作者:boyboo
项目:PocketMine-M
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);
}
}
作者:kazuemo
项目:NIGHTMAR
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);
}
作者:robozer
项目:S
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);
}
}
作者:xpyctu
项目:Genisy
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);
}
}
作者:xHF
项目:ImagicalMin
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);
}
}
}
作者:ClearSkyTea
项目:ClearSk
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);
}
}
作者:xpyctu
项目:PocketMinePlusPlu
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]);
}
}
}
作者:xpyctu
项目:Genisy
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);
}
}
}
作者:xpyctu
项目:PocketMinePlusPlu
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);
}
}
}
}
作者:iTXTec
项目:Genisy
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);
}
}
}
作者:iTXTec
项目:Genisy
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);
}
}
}
}
作者:Creeperface0
项目:ImagicalMin
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]);
}
}
}
作者:iTXTec
项目:Genisy
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);
}
}
}
}
}
作者:rry
项目:PocketMine-M
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);
}
}
}
作者:iTXTec
项目:Genisy
private function getLeafGroupPoints(ChunkManager $level, $x, $y, $z)
{
$amount = $this->leafAmount * $this->totalHeight / 13;
$groupsPerLayer = (int) (1.382 + $amount * $amount);
if ($groupsPerLayer == 0) {
$groupsPerLayer = 1;
}
$trunkTopY = $y + $this->trunkHeight;
$groups = [];
$groupY = $y + $this->totalHeight - $this->leafDistanceLimit;
$groups[] = [new Vector3($x, $groupY, $z), $trunkTopY];
for ($currentLayer = (int) ($this->totalHeight - $this->leafDistanceLimit); $currentLayer >= 0; $currentLayer--) {
$layerSize = $this->getRoughLayerSize($currentLayer);
if ($layerSize < 0) {
$groupY--;
continue;
}
for ($count = 0; $count < $groupsPerLayer; $count++) {
$scale = $this->widthScale * $layerSize * ($this->random->nextFloat() + 0.328);
$randomOffset = Vector2::createRandomDirection($this->random)->multiply($scale);
$groupX = (int) ($randomOffset->getX() + $x + 0.5);
$groupZ = (int) ($randomOffset->getY() + $z + 0.5);
$group = new Vector3($groupX, $groupY, $groupZ);
if ($this->getAvailableBlockSpace($level, $group, $group->add(0, $this->leafDistanceLimit, 0)) != -1) {
continue;
}
$xOff = (int) ($x - $groupX);
$zOff = (int) ($z - $groupZ);
$horizontalDistanceToTrunk = sqrt($xOff * $xOff + $zOff * $zOff);
$verticalDistanceToTrunk = $horizontalDistanceToTrunk * $this->branchSlope;
$yDiff = (int) ($groupY - $verticalDistanceToTrunk);
if ($yDiff > $trunkTopY) {
$base = $trunkTopY;
} else {
$base = $yDiff;
}
if ($this->getAvailableBlockSpace($level, new Vector3($x, $base, $z), $group) == -1) {
$groups[] = [$group, $base];
}
}
$groupY--;
}
return $groups;
}
作者:boyboo
项目:PocketMine-M
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);
}
}
}
}