public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) { if ($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) { $this->findRandomLeavesSize($random); } $level->setBlockIdAt($x, $y - 1, $z, Block::DIRT); $leavesRadius = 0; for ($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy) { for ($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) { for ($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) { if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) { $level->setBlockIdAt($x + $xx, $y + $yy, $z + $zz, Block::LEAVES); $level->setBlockDataAt($x + $xx, $y + $yy, $z + $zz, $this->type); } } } if ($leavesRadius > 0 and $yy === $y + $this->leavesBottomY + 1) { --$leavesRadius; } elseif ($leavesRadius < $this->leavesMaxRadius) { ++$leavesRadius; } } for ($yy = 0; $yy < $this->totalHeight - 1; ++$yy) { $level->setBlockIdAt($x, $y + $yy, $z, Block::TRUNK); $level->setBlockDataAt($x, $y + $yy, $z, $this->type); } }
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); } } }
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); } } }
private function flowIntoBlock($x, $y, $z, $newFlowDecay) { if ($this->level->getBlockIdAt($x, $y, $z) === Block::AIR) { $this->level->setBlockIdAt($x, $y, $z, Block::LAVA); $this->level->setBlockDataAt($x, $y, $z, $newFlowDecay); $this->level->updateBlockLight($x, $y, $z); $this->lavaSpread($x, $y, $z); } }
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); } } } }
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]); } } }
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); } } } } }
protected function placeTrunk(ChunkManager $level, $x, $y, $z, Random $random, $trunkHeight) { // The base dirt block $level->setBlockIdAt($x, $y - 1, $z, Block::DIRT); for ($yy = 0; $yy < $trunkHeight; ++$yy) { $blockId = $level->getBlockIdAt($x, $y + $yy, $z); if (isset($this->overridable[$blockId])) { $level->setBlockIdAt($x, $y + $yy, $z, $this->trunkBlock); $level->setBlockDataAt($x, $y + $yy, $z, $this->type); } } }
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); } } }
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]); } } }
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"; } } } } } } } }
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) { if ($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) { $this->findRandomLeavesSize($random); } $level->setBlockIdAt($x, $y - 1, $z, Block::DIRT); $leavesRadius = 0; $leavesMaxRadius = 1; $leavesBottomY = $this->totalHeight - $this->leavesSizeY; $firstMaxedRadius = \false; for ($leavesY = 0; $leavesY <= $leavesBottomY; ++$leavesY) { $yy = $this->totalHeight - $leavesY; for ($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) { for ($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) { if (\abs($xx) != $leavesRadius or \abs($zz) != $leavesRadius or $leavesRadius <= 0) { $level->setBlockIdAt($x + $xx, $y + $yy, $z + $zz, Block::LEAVES); $level->setBlockDataAt($x + $xx, $y + $yy, $z + $zz, $this->type); } } } if ($leavesRadius >= $leavesMaxRadius) { $leavesRadius = $firstMaxedRadius ? 1 : 0; $firstMaxedRadius = \true; if (++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius) { $leavesMaxRadius = $this->leavesAbsoluteMaxRadius; } } else { ++$leavesRadius; } } $trunkHeightReducer = $random->nextRange(0, 3); for ($yy = 0; $yy < $this->totalHeight - $trunkHeightReducer; ++$yy) { $level->setBlockIdAt($x, $y + $yy, $z, Block::TRUNK); $level->setBlockDataAt($x, $y + $yy, $z, $this->type); } }
public function place() { for ($x = $this->start->getFloorX(); $x < $this->end->getFloorX(); $x++) { $xOffset = ($this->chunk->getX() + $x + 0.5 - $this->target->getX()) / $this->horizontalSize; for ($z = $this->start->getFloorZ(); $z < $this->end->getFloorZ(); $z++) { $zOffset = ($this->chunk->getZ() + $z + 0.5 - $this->target->getZ()) / $this->horizontalSize; if ($xOffset * $xOffset + $zOffset * $zOffset >= 1) { continue; } for ($y = $this->end->getFloorY() - 1; $y >= $this->start->getFloorY(); $y--) { $yOffset = ($y + 0.5 - $this->target->getY()) / $this->verticalSize; if ($yOffset > -0.7 and $xOffset * $xOffset + $yOffset * $yOffset + $zOffset * $zOffset < 1) { $xx = $this->chunk->getX() + $x; $zz = $this->chunk->getZ() + $z; $blockId = $this->level->getBlockIdAt($xx, $y, $zz); if ($blockId == Block::STONE or $blockId == Block::DIRT or $blockId == Block::GRASS) { if ($y < 10) { $this->level->setBlockIdAt($xx, $y, $zz, Block::STILL_LAVA); } else { if ($blockId == Block::GRASS and $this->level->getBlockIdAt($xx, $y - 1, $zz) == Block::DIRT) { $this->level->setBlockIdAt($xx, $y - 1, $zz, Block::GRASS); } $this->level->setBlockIdAt($xx, $y, $zz, Block::AIR); } } } } } } }
private function generateBranches(ChunkManager $level, int $x, int $y, int $z, array $groups) { foreach ($groups as $group) { $baseY = $group[1]; if ($baseY - $y >= $this->totalHeight * 0.2) { $base = new Vector3($x, $baseY, $z); $branch = new VectorIterator($level, $base, $group[0]); while ($branch->valid()) { $branch->next(); $pos = $branch->current(); $level->setBlockIdAt((int) $pos->x, (int) $pos->y, (int) $pos->z, Block::LOG); $level->updateBlockLight((int) $pos->x, (int) $pos->y, (int) $pos->z); } } } }