예제 #1
0
 public function placeObject(ChunkManager $level, $x, $y, $z)
 {
     $clusterSize = (int) $this->type->clusterSize;
     $angle = $this->random->nextFloat() * M_PI;
     $offset = VectorMath::getDirection2D($angle)->multiply($clusterSize)->divide(8);
     $x1 = $x + 8 + $offset->x;
     $x2 = $x + 8 - $offset->x;
     $z1 = $z + 8 + $offset->y;
     $z2 = $z + 8 - $offset->y;
     $y1 = $y + $this->random->nextBoundedInt(3) + 2;
     $y2 = $y + $this->random->nextBoundedInt(3) + 2;
     for ($count = 0; $count <= $clusterSize; ++$count) {
         $seedX = $x1 + ($x2 - $x1) * $count / $clusterSize;
         $seedY = $y1 + ($y2 - $y1) * $count / $clusterSize;
         $seedZ = $z1 + ($z2 - $z1) * $count / $clusterSize;
         $size = ((sin($count * (M_PI / $clusterSize)) + 1) * $this->random->nextFloat() * $clusterSize / 16 + 1) / 2;
         $startX = (int) ($seedX - $size);
         $startY = (int) ($seedY - $size);
         $startZ = (int) ($seedZ - $size);
         $endX = (int) ($seedX + $size);
         $endY = (int) ($seedY + $size);
         $endZ = (int) ($seedZ + $size);
         //echo "ORE: $startX, $startY, $startZ,, $endX, $endY, $endZ\n";
         for ($x = $startX; $x <= $endX; ++$x) {
             $sizeX = ($x + 0.5 - $seedX) / $size;
             $sizeX *= $sizeX;
             if ($sizeX < 1) {
                 for ($y = $startY; $y <= $endY; ++$y) {
                     $sizeY = ($y + 0.5 - $seedY) / $size;
                     $sizeY *= $sizeY;
                     if ($y > 0 and $sizeX + $sizeY < 1) {
                         for ($z = $startZ; $z <= $endZ; ++$z) {
                             $sizeZ = ($z + 0.5 - $seedZ) / $size;
                             $sizeZ *= $sizeZ;
                             if ($sizeX + $sizeY + $sizeZ < 1 and $level->getBlockIdAt($x, $y, $z) === 0) {
                                 $level->setBlockIdAt($x, $y, $z, $this->type->material->getId());
                                 if ($this->type->material->getDamage() !== 0) {
                                     $level->setBlockDataAt($x, $y, $z, $this->type->material->getDamage());
                                 }
                                 $level->updateBlockLight($x, $y, $z);
                                 //echo "Placed to $x, $y, $z\n";
                             }
                         }
                     }
                 }
             }
         }
     }
 }
예제 #2
0
파일: Vector2.php 프로젝트: iTXTech/Genisys
 public static function createRandomDirection(Random $random)
 {
     return VectorMath::getDirection2D($random->nextFloat() * 2 * pi());
 }
예제 #3
0
파일: Cave.php 프로젝트: iTXTech/Genisys
 private function generateCaveBranch(ChunkManager $level, Vector3 $chunk, Vector3 $target, $horizontalScale, $verticalScale, $horizontalAngle, $verticalAngle, int $startingNode, int $nodeAmount, Random $random)
 {
     $middle = new Vector3($chunk->getX() + 8, 0, $chunk->getZ() + 8);
     $horizontalOffset = 0;
     $verticalOffset = 0;
     if ($nodeAmount <= 0) {
         $size = 7 * 16;
         $nodeAmount = $size - $random->nextBoundedInt($size / 4);
     }
     $intersectionMode = $random->nextBoundedInt($nodeAmount / 2) + $nodeAmount / 4;
     $extraVerticalScale = $random->nextBoundedInt(6) == 0;
     if ($startingNode == -1) {
         $startingNode = $nodeAmount / 2;
         $lastNode = true;
     } else {
         $lastNode = false;
     }
     for (; $startingNode < $nodeAmount; $startingNode++) {
         $horizontalSize = 1.5 + sin($startingNode * pi() / $nodeAmount) * $horizontalScale;
         $verticalSize = $horizontalSize * $verticalScale;
         $target = $target->add(VectorMath::getDirection3D($horizontalAngle, $verticalAngle));
         if ($extraVerticalScale) {
             $verticalAngle *= 0.92;
         } else {
             $verticalScale *= 0.7;
         }
         $verticalAngle += $verticalOffset * 0.1;
         $horizontalAngle += $horizontalOffset * 0.1;
         $verticalOffset *= 0.9;
         $horizontalOffset *= 0.75;
         $verticalOffset += ($random->nextFloat() - $random->nextFloat()) * $random->nextFloat() * 2;
         $horizontalOffset += ($random->nextFloat() - $random->nextFloat()) * $random->nextFloat() * 4;
         if (!$lastNode) {
             if ($startingNode == $intersectionMode and $horizontalScale > 1 and $nodeAmount > 0) {
                 $this->generateCaveBranch($level, $chunk, $target, $random->nextFloat() * 0.5 + 0.5, 1, $horizontalAngle - pi() / 2, $verticalAngle / 3, $startingNode, $nodeAmount, new Random($random->nextInt()));
                 $this->generateCaveBranch($level, $chunk, $target, $random->nextFloat() * 0.5 + 0.5, 1, $horizontalAngle - pi() / 2, $verticalAngle / 3, $startingNode, $nodeAmount, new Random($random->nextInt()));
                 return;
             }
             if ($random->nextBoundedInt(4) == 0) {
                 continue;
             }
         }
         $xOffset = $target->getX() - $middle->getX();
         $zOffset = $target->getZ() - $middle->getZ();
         $nodesLeft = $nodeAmount - $startingNode;
         $offsetHorizontalScale = $horizontalScale + 18;
         if ($xOffset * $xOffset + $zOffset * $zOffset - $nodesLeft * $nodesLeft > $offsetHorizontalScale * $offsetHorizontalScale) {
             return;
         }
         if ($target->getX() < $middle->getX() - 16 - $horizontalSize * 2 or $target->getZ() < $middle->getZ() - 16 - $horizontalSize * 2 or $target->getX() > $middle->getX() + 16 + $horizontalSize * 2 or $target->getZ() > $middle->getZ() + 16 + $horizontalSize * 2) {
             continue;
         }
         $start = new Vector3(floor($target->getX() - $horizontalSize) - $chunk->getX() - 1, floor($target->getY() - $verticalSize) - 1, floor($target->getZ() - $horizontalSize) - $chunk->getZ() - 1);
         $end = new Vector3(floor($target->getX() + $horizontalSize) - $chunk->getX() + 1, floor($target->getY() + $verticalSize) + 1, floor($target->getZ() + $horizontalSize) - $chunk->getZ() + 1);
         $node = new CaveNode($level, $chunk, $start, $end, $target, $verticalSize, $horizontalSize);
         if ($node->canPlace()) {
             $node->place();
         }
         if ($lastNode) {
             break;
         }
     }
 }