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 $seedX = $x1 + ($x2 - $x1) * $count / $clusterSize;
68 $seedY = $y1 + ($y2 - $y1) * $count / $clusterSize;
69 $seedZ = $z1 + ($z2 - $z1) * $count / $clusterSize;
70 $size = ((sin($count * (M_PI / $clusterSize)) + 1) * $this->random->nextFloat() * $clusterSize / 16 + 1) / 2;
72 $startX = (int) ($seedX - $size);
73 $startY = (int) ($seedY - $size);
74 $startZ = (int) ($seedZ - $size);
75 $endX = (int) ($seedX + $size);
76 $endY = (int) ($seedY + $size);
77 $endZ = (int) ($seedZ + $size);
79 for($xx = $startX; $xx <= $endX; ++$xx){
80 $sizeX = ($xx + 0.5 - $seedX) / $size;
84 for($yy = $startY; $yy <= $endY; ++$yy){
85 $sizeY = ($yy + 0.5 - $seedY) / $size;
88 if($yy > 0 && ($sizeX + $sizeY) < 1){
89 for($zz = $startZ; $zz <= $endZ; ++$zz){
90 $sizeZ = ($zz + 0.5 - $seedZ) / $size;
93 if(($sizeX + $sizeY + $sizeZ) < 1){
95 if(isset($tried[$hash])){
100 throw new \LogicException(
"Unavailable chunk at block x=$xx, y=$yy, z=$zz");
102 $stateId = $explorer->currentSubChunk->getBlockStateId($xx & SubChunk::COORD_MASK, $yy & SubChunk::COORD_MASK, $zz & SubChunk::COORD_MASK);
103 $replaceable = $replaceableStateIds[$stateId] ??= $world->
getBlockAt($xx, $yy, $zz)->hasSameTypeId($this->type->replaces);
105 $explorer->currentSubChunk->setBlockStateId($xx & SubChunk::COORD_MASK, $yy & SubChunk::COORD_MASK, $zz & SubChunk::COORD_MASK, $materialStateId);