37 public function __construct(
42 public function getType() :
OreType{
46 public function canPlaceObject(
ChunkManager $world,
int $x,
int $y,
int $z) :
bool{
47 return $world->
getBlockAt($x, $y, $z)->hasSameTypeId($this->type->replaces);
50 public function placeObject(
ChunkManager $world,
int $x,
int $y,
int $z) :
void{
51 $clusterSize = $this->type->clusterSize;
52 $angle = $this->random->nextFloat() * M_PI;
53 $offset = VectorMath::getDirection2D($angle)->multiply($clusterSize / 8);
54 $x1 = $x + 8 + $offset->x;
55 $x2 = $x + 8 - $offset->x;
56 $z1 = $z + 8 + $offset->y;
57 $z2 = $z + 8 - $offset->y;
58 $y1 = $y + $this->random->nextBoundedInt(3) + 2;
59 $y2 = $y + $this->random->nextBoundedInt(3) + 2;
64 $replaceableStateIds = [];
65 $materialStateId = $this->type->material->getStateId();
66 for($count = 0; $count <= $clusterSize; ++$count){
67 $centerX = $x1 + ($x2 - $x1) * $count / $clusterSize;
68 $centerY = $y1 + ($y2 - $y1) * $count / $clusterSize;
69 $centerZ = $z1 + ($z2 - $z1) * $count / $clusterSize;
70 $radius = ((sin($count * (M_PI / $clusterSize)) + 1) * $this->random->nextFloat() * $clusterSize / 16 + 1) / 2;
72 $this->placeSphere($world, $explorer, $centerX, $centerY, $centerZ, $radius, $tried, $replaceableStateIds, $materialStateId);
86 private function placeSphere(
94 array &$replaceableStateIds,
97 $startX = (int) ($centerX - $radius);
98 $startY = (int) ($centerY - $radius);
99 $startZ = (int) ($centerZ - $radius);
100 $endX = (int) ($centerX + $radius);
101 $endY = (int) ($centerY + $radius);
102 $endZ = (int) ($centerZ + $radius);
104 for($xx = $startX; $xx <= $endX; ++$xx){
105 $sizeX = ($xx + 0.5 - $centerX) / $radius;
109 for($yy = $startY; $yy <= $endY; ++$yy){
110 $sizeY = ($yy + 0.5 - $centerY) / $radius;
113 if($yy > 0 && ($sizeX + $sizeY) < 1){
114 for($zz = $startZ; $zz <= $endZ; ++$zz){
115 $sizeZ = ($zz + 0.5 - $centerZ) / $radius;
118 if(($sizeX + $sizeY + $sizeZ) < 1){
120 if(isset($visited[$hash])){
123 $visited[$hash] =
true;
125 throw new \LogicException(
"Unavailable chunk at block x=$xx, y=$yy, z=$zz");
127 $stateId = $explorer->currentSubChunk->getBlockStateId($xx & SubChunk::COORD_MASK, $yy & SubChunk::COORD_MASK, $zz & SubChunk::COORD_MASK);
128 $replaceable = $replaceableStateIds[$stateId] ??= $world->
getBlockAt($xx, $yy, $zz)->hasSameTypeId($this->type->replaces);
130 $explorer->currentSubChunk->setBlockStateId($xx & SubChunk::COORD_MASK, $yy & SubChunk::COORD_MASK, $zz & SubChunk::COORD_MASK, $materialStateId);