示例#1
0
 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
0
 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;
 }
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 public function populateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0.0 ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     foreach ($this->populators as $populator) {
         $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
     }
 }
示例#16
0
 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);
             }
         }
     }
 }
示例#17
0
 public function populateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     foreach ($this->populators as $populator) {
         $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
     }
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     $biome = Biome::getBiome($chunk->getBiomeId(7, 7));
     $biome->populateChunk($this->level, $chunkX, $chunkZ, $this->random);
 }
示例#18
0
 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]);
         }
     }
 }
示例#19
0
 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);
                 }
             }
         }
     }
 }
示例#20
0
 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);
         }
     }
 }
示例#21
0
 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;
 }
示例#22
0
 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);
             }
         }
     }
 }
示例#23
0
 public function __construct(Random $random, $octaves, $persistence, $expansion = 1)
 {
     $this->octaves = $octaves;
     $this->persistence = $persistence;
     $this->expansion = $expansion;
     $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->nextBoundedInt(256);
     }
     for ($i = 0; $i < 256; ++$i) {
         $pos = $random->nextBoundedInt(256 - $i) + $i;
         $old = $this->perm[$i];
         $this->perm[$i] = $this->perm[$pos];
         $this->perm[$pos] = $old;
         $this->perm[$i + 256] = $this->perm[$i];
     }
 }
示例#24
0
 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];
     }
 }
示例#25
0
 public function __construct(Random $random, $octaves, $frequency, $amplitude, $lacunarity)
 {
     $this->octaves = $octaves;
     $this->frequency = $frequency;
     $this->lacunarity = $lacunarity;
     $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->nextBoundedInt(256);
     }
     for ($i = 0; $i < 256; ++$i) {
         $pos = $random->nextBoundedInt(256 - $i) + $i;
         $old = $this->perm[$i];
         $this->perm[$i] = $this->perm[$pos];
         $this->perm[$pos] = $old;
         $this->perm[$i + 256] = $this->perm[$i];
     }
 }
示例#26
0
 public static function createRandomDirection(Random $random)
 {
     return VectorMath::getDirection2D($random->nextFloat() * 2 * pi());
 }
示例#27
0
 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     if ($random->nextRange(0, self::$ODD) === 0) {
         //$mineshaft = new Mineshaft($random);
     }
 }
示例#28
0
 public function placeObject(ChunkManager $level, $x, $y, $z, Random $random)
 {
     $this->treeHeight = $random->nextBoundedInt(3) + 4;
     parent::placeObject($level, $x, $y, $z, $random);
 }
示例#29
0
 private function findRandomLeavesSize(Random $random)
 {
     $this->totalHeight += $random->nextRange(-1, 2);
     $this->leavesBottomY = (int) ($this->totalHeight - $random->nextRange(1, 2) - 3);
     $this->leavesMaxRadius = 1 + $random->nextRange(0, 1);
 }
示例#30
0
 public function blockBreak(BlockBreakEvent $event)
 {
     $block = $event->getBlock();
     if ($block->getId() === $this->data["lucky_block"] && $this->isAllowedWorld($block->getLevel())) {
         $player = $event->getPlayer();
         if (!$player->hasPermission("luckyblock.use")) {
             $player->sendMessage($this->tag . $this->message->get("not_allowed"));
             return;
         }
         $event->setCancelled();
         $player->getLevel()->setBlock($block, new Block(Block::AIR), false, true);
         $rand = new Random();
         switch ($rand->nextRange(1, 12)) {
             case 1:
                 if (!isset($this->data["functions"]["spawnTree"]) || $this->data["functions"]["spawnTree"]) {
                     $type = Sapling::OAK;
                     switch ($rand->nextRange(0, 3)) {
                         case 1:
                             $type = Sapling::BIRCH;
                             break;
                         case 2:
                             $type = Sapling::SPRUCE;
                             break;
                         case 3:
                             $type = Sapling::JUNGLE;
                             break;
                     }
                     if ($player->getLevel()->setBlock($block, new Sapling($type), true, true)) {
                         $player->getLevel()->getBlock($block)->onActivate(new Item(Item::DYE, 15), $player);
                         $player->sendMessage($this->tag . $this->message->get("tree"));
                     }
                     break;
                 }
             case 2:
                 if (!isset($this->data["functions"]["explosion"]) || $this->data["functions"]["explosion"]) {
                     $explosion = new Explosion($block, mt_rand($this->data["explosion_min"], $this->data["explosion_max"]));
                     if ($explosion->explodeA()) {
                         $explosion->explodeB();
                     }
                     $player->sendMessage($this->tag . $this->message->get("explosion"));
                     break;
                 }
             case 3:
                 if (!isset($this->data["functions"]["dropItem"]) || $this->data["functions"]["dropItem"]) {
                     if (mt_rand(0, 1)) {
                         if ($this->itemLoop($player, $block)) {
                             break;
                         }
                     }
                     if (count($this->data["items_dropped"]) === 0) {
                         $item = $this->randItem();
                     } else {
                         $item = $this->data["items_dropped"][mt_rand(0, count($this->data["items_dropped"]) - 1)];
                     }
                     $player->getLevel()->dropItem($block, $item);
                     $player->sendMessage($this->tag . $this->message->get("drop"));
                     break;
                 }
             case 4:
                 if (!isset($this->data["functions"]["bedrock"]) || $this->data["functions"]["bedrock"]) {
                     $player->getLevel()->setBlock($block, new Block(Block::BEDROCK));
                     $p = new Position($block->x, $block->y + 1, $block->z, $block->level);
                     if ($player->getLevel()->getBlock($p)->getId() != Block::AIR) {
                         break;
                     }
                     $block->getLevel()->setBlock($p, Block::get(Item::SIGN_POST));
                     $sign = new Sign($player->getLevel()->getChunk($block->x >> 4, $block->z >> 4), new CompoundTag(false, array(new IntTag("x", (int) $block->x), new IntTag("y", (int) $block->y + 1), new IntTag("z", (int) $block->z), new StringTag("Text1", $this->tag), new StringTag("Text2", $this->message->get("signText")))));
                     $sign->spawnToAll();
                     $player->sendMessage($this->tag . $this->message->get("sign"));
                     break;
                 }
             case 5:
                 if (!isset($this->data["functions"]["prison"]) || $this->data["functions"]["prison"]) {
                     $pos = $event->getPlayer();
                     $pos->x = round($pos->x) + 0.5;
                     $pos->y = round($pos->y);
                     $pos->z = round($pos->z) + 0.5;
                     $player->teleport($pos, $player->getYaw(), $player->getPitch());
                     $arr = [];
                     switch ($rand->nextRange(1, 5)) {
                         case 1:
                             $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 1, $pos->z, $pos->getLevel()), new Block(Block::OBSIDIAN));
                             for ($x = $pos->x - 1; $x <= $pos->x + 1; $x++) {
                                 for ($z = $pos->z - 1; $z <= $pos->z + 1; $z++) {
                                     if (!($x === $pos->x && $z === $pos->z)) {
                                         for ($y = $pos->y; $y <= $pos->y + 2; $y++) {
                                             $player->getLevel()->setBlock(new Position($x, $y, $z, $pos->getLevel()), new Block(Block::OBSIDIAN));
                                         }
                                     }
                                 }
                             }
                             $player->getLevel()->updateAround($pos);
                             $player->sendMessage($this->tag . $this->message->get("prison"));
                             break;
                         case 2:
                             $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 1, $pos->z, $pos->getLevel()), new Block(Block::STILL_LAVA));
                             $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 2, $pos->z, $pos->getLevel()), new Block(Block::GLASS));
                             for ($x = $pos->x - 1; $x <= $pos->x + 1; $x++) {
                                 for ($z = $pos->z - 1; $z <= $pos->z + 1; $z++) {
                                     if (!($x === $pos->x && $z === $pos->z)) {
                                         for ($y = $pos->y; $y <= $pos->y + 2; $y++) {
                                             $player->getLevel()->setBlock(new Position($x, $y, $z, $pos->getLevel()), new Block(Block::IRON_BAR));
                                         }
                                     }
                                 }
                             }
                             $player->getLevel()->updateAround($pos);
                             $player->sendMessage($this->tag . $this->message->get("prison"));
                             break;
                         case 3:
                             $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 1, $pos->z, $pos->getLevel()), new Block(Block::SANDSTONE));
                             for ($x = $pos->x - 1; $x <= $pos->x + 1; $x++) {
                                 for ($z = $pos->z - 1; $z <= $pos->z + 1; $z++) {
                                     if (!($x === $pos->x && $z === $pos->z)) {
                                         for ($y = $pos->y; $y <= $pos->y + 2; $y++) {
                                             $player->getLevel()->setBlock(new Position($x, $y, $z, $pos->getLevel()), new Block(Block::IRON_BAR));
                                         }
                                     }
                                 }
                             }
                             break;
                         case 4:
                             $arr = [["x" => -1, "y" => -1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => -1, "z" => 0, "block" => Block::OBSIDIAN], ["x" => -1, "y" => -1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => -1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => -1, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 0, "y" => -1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => -1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => -1, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 1, "y" => -1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 0, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 0, "z" => 0, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 0, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 0, "z" => 0, "block" => Block::STILL_WATER], ["x" => 0, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 1, "z" => 0, "block" => Block::GLASS], ["x" => -1, "y" => 1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 1, "z" => -1, "block" => Block::GLASS], ["x" => 0, "y" => 1, "z" => 0, "block" => Block::STILL_WATER], ["x" => 0, "y" => 1, "z" => 1, "block" => Block::GLASS], ["x" => 1, "y" => 1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 1, "z" => 0, "block" => Block::GLASS], ["x" => 1, "y" => 1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 2, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 2, "z" => 0, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 2, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 2, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 2, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 2, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 2, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 2, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 2, "z" => 1, "block" => Block::OBSIDIAN]];
                             break;
                         case 5:
                             $arr = [["x" => -1, "y" => 0, "z" => -1, "block" => Block::STILL_LAVA], ["x" => -1, "y" => 0, "z" => 0, "block" => Block::STILL_LAVA], ["x" => -1, "y" => 0, "z" => 1, "block" => Block::STILL_LAVA], ["x" => 0, "y" => 0, "z" => -1, "block" => Block::STILL_LAVA], ["x" => 0, "y" => 0, "z" => 0, "block" => Block::STILL_LAVA], ["x" => 0, "y" => 0, "z" => 1, "block" => Block::STILL_LAVA], ["x" => 1, "y" => 0, "z" => -1, "block" => Block::STILL_LAVA], ["x" => 1, "y" => 0, "z" => 0, "block" => Block::STILL_LAVA], ["x" => 1, "y" => 0, "z" => 1, "block" => Block::STILL_LAVA], ["x" => -1, "y" => 1, "z" => -1, "block" => Block::COBWEB], ["x" => -1, "y" => 1, "z" => 0, "block" => Block::COBWEB], ["x" => -1, "y" => 1, "z" => 1, "block" => Block::COBWEB], ["x" => 0, "y" => 1, "z" => -1, "block" => Block::COBWEB], ["x" => 0, "y" => 1, "z" => 0, "block" => Block::COBWEB], ["x" => 0, "y" => 1, "z" => 1, "block" => Block::COBWEB], ["x" => 1, "y" => 1, "z" => -1, "block" => Block::COBWEB], ["x" => 1, "y" => 1, "z" => 0, "block" => Block::COBWEB], ["x" => 1, "y" => 1, "z" => 1, "block" => Block::COBWEB]];
                             break;
                     }
                     $pos = $player->getPosition();
                     foreach ($arr as $i => $c) {
                         $player->getLevel()->setBlock($pos->add($c["x"], $c["y"], $c["z"]), Block::get($c["block"]), true, true);
                     }
                     break;
                 }
             case 6:
                 if (!isset($this->data["functions"]["chest"]) || $this->data["functions"]["chest"]) {
                     $player->getLevel()->setBlock($block, new Block(Block::CHEST), true, true);
                     $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z)]);
                     $nbt->Items->setTagType(NBT::TAG_Compound);
                     $tile = Tile::createTile("Chest", $block->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt);
                     if ($tile instanceof Chest) {
                         for ($i = 0; $i <= mt_rand(1, $this->data["max_chest_item"]); $i++) {
                             if (count($this->data["items_dropped"]) === 0) {
                                 $item = $this->randItem();
                             } else {
                                 $item = $this->data["items_dropped"][mt_rand(0, count($this->data["items_dropped"]) - 1)];
                             }
                             $tile->getInventory()->setItem($i, $item);
                         }
                         $player->sendMessage($this->tag . $this->message->get("chest"));
                     }
                     break;
                 }
             case 7:
                 if (!isset($this->data["functions"]["teleport"]) || $this->data["functions"]["teleport"]) {
                     $player->teleport($player->getLevel()->getSpawnLocation(), $player->getYaw(), $player->getPitch());
                     $player->sendMessage($this->tag . $this->message->get("spawn"));
                     break;
                 }
             case 8:
                 if (!isset($this->data["functions"]["potion"]) || $this->data["functions"]["potion"]) {
                     if (count($this->data["potions"])) {
                         $effect = Effect::getEffectByName($this->data["potions"][$rand->nextRange(0, count($this->data["potions"]) - 1)]);
                         $effect->setDuration($rand->nextRange(20, $this->data["max_duration"] * 20));
                         $player->addEffect($effect);
                         $player->sendMessage($this->tag . $this->message->get("effect"));
                     } else {
                         $player->sendMessage($this->tag . $this->message->get("unlucky"));
                     }
                     break;
                 }
             case 9:
                 //exec command
                 if (!isset($this->data["functions"]["execCmd"]) || $this->data["functions"]["execCmd"]) {
                     if (count($this->data["commands"])) {
                         $cmd = $this->data["commands"][$rand->nextRange(0, count($this->data["commands"]) - 1)];
                         $cmd = str_replace(["%PLAYER%", "%X%", "%Y%", "%Z%", "%WORLD%", "%IP%", "%XP%"], [$player->getName(), $player->getX(), $player->getY(), $player->getZ(), $player->getLevel()->getName(), $player->getAddress(), $player->getXpLevel()], $cmd);
                         $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $cmd);
                         $player->sendMessage($this->tag . $this->message->get("command"));
                         break;
                     }
                 }
             case 10:
                 //mob
                 if (!isset($this->data["functions"]["mob"]) || $this->data["functions"]["mob"]) {
                     if (count($this->data["mob"])) {
                         $mob = $this->data["mob"][$rand->nextRange(0, count($this->data["mob"]) - 1)];
                         if ($this->isExistsEntity($mob)) {
                             $nbt = new CompoundTag("", [new ListTag("Pos", [new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ())]), new ListTag("Rotation", [new FloatTag("", $player->getYaw()), new FloatTag("", $player->getPitch())]), new StringTag("CustomName", $this->tag)]);
                             $entity = Entity::createEntity($mob, $player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt);
                             if ($entity instanceof Entity) {
                                 $entity->spawnToAll();
                                 $this->getServer()->getScheduler()->scheduleDelayedTask(new TaskExplodeMob($this, $entity, mt_rand($this->data["explosion_min"], $this->data["explosion_max"])), 20 * mt_rand(1, $this->data["mob_explosion_delay"]));
                                 $player->sendMessage($this->tag . $this->message->get("mob"));
                                 break;
                             }
                         }
                     }
                 }
             case 11:
                 if (!isset($this->data["functions"]["lightning"]) || $this->data["functions"]["lightning"]) {
                     $player->getLevel()->spawnLightning($player);
                     $player->sendMessage($this->tag . $this->message->get("lightning"));
                     break;
                 }
             case 12:
                 $player->sendMessage($this->tag . $this->message->get("unlucky"));
                 break;
         }
         $player->getLevel()->save();
     }
 }