pocketmine\level\generator\object\NetherOre::placeObject PHP Метод

placeObject() публичный Метод

public placeObject ( pocketmine\level\ChunkManager $level, $x, $y, $z )
$level pocketmine\level\ChunkManager
    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) === 87) {
                                    $level->setBlockIdAt($x, $y, $z, $this->type->material->getId());
                                    if ($this->type->material->getDamage() !== 0) {
                                        $level->setBlockDataAt($x, $y, $z, $this->type->material->getDamage());
                                    }
                                    //echo "Placed to $x, $y, $z\n";
                                }
                            }
                        }
                    }
                }
            }
        }
    }

Usage Example

Пример #1
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);
             }
         }
     }
 }