public function onChunkChanged(FullChunk $chunk) { $this->loadQueue[Level::chunkHash($chunk->getX(), $chunk->getZ())] = abs(($this->x >> 4) - $chunk->getX()) + abs(($this->z >> 4) - $chunk->getZ()); }
public function addEntityMovement($chunkX, $chunkZ, $entityId, $x, $y, $z, $yaw, $pitch, $headYaw = null) { if (!isset($this->moveToSend[$index = Level::chunkHash($chunkX, $chunkZ)])) { $this->moveToSend[$index] = []; } $this->moveToSend[$index][$entityId] = [$entityId, $x, $y, $z, $yaw, $headYaw === null ? $yaw : $headYaw, $pitch]; }
protected function loadRegion($x, $z) { if (!isset($this->regions[$index = Level::chunkHash($x, $z)])) { $this->regions[$index] = new RegionLoader($this, $x, $z); } }
public function setChunk($chunkX, $chunkZ, FullChunk $chunk) { if (!$chunk instanceof Chunk) { throw new ChunkException("Invalid Chunk class"); } $chunk->setProvider($this); $chunk->setX($chunkX); $chunk->setZ($chunkZ); if (isset($this->chunks[$index = Level::chunkHash($chunkX, $chunkZ)]) and $this->chunks[$index] !== $chunk) { $this->unloadChunk($chunkX, $chunkZ, false); } $this->chunks[$index] = $chunk; }
public function generateChunk($chunkX, $chunkZ) { $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed()); $noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16); $chunk = $this->level->getChunk($chunkX, $chunkZ); $biomeCache = []; for ($x = 0; $x < 16; ++$x) { for ($z = 0; $z < 16; ++$z) { $minSum = 0; $maxSum = 0; $weightSum = 0; $biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z); $chunk->setBiomeId($x, $z, $biome->getId()); $color = [0, 0, 0]; for ($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx) { for ($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz) { $weight = self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE]; if ($sx === 0 and $sz === 0) { $adjacent = $biome; } else { $index = Level::chunkHash($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz); if (isset($biomeCache[$index])) { $adjacent = $biomeCache[$index]; } else { $biomeCache[$index] = $adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz); } } $minSum += ($adjacent->getMinElevation() - 1) * $weight; $maxSum += $adjacent->getMaxElevation() * $weight; $bColor = $adjacent->getColor(); $color[0] += ($bColor >> 16) ** 2 * $weight; $color[1] += ($bColor >> 8 & 0xff) ** 2 * $weight; $color[2] += ($bColor & 0xff) ** 2 * $weight; $weightSum += $weight; } } $minSum /= $weightSum; $maxSum /= $weightSum; $chunk->setBiomeColor($x, $z, sqrt($color[0] / $weightSum), sqrt($color[1] / $weightSum), sqrt($color[2] / $weightSum)); $solidLand = false; for ($y = 127; $y >= 0; --$y) { if ($y === 0) { $chunk->setBlockId($x, $y, $z, Block::BEDROCK); continue; } // A noiseAdjustment of 1 will guarantee ground, a noiseAdjustment of -1 will guarantee air. //$effHeight = min($y - $smoothHeight - $minSum, $noiseAdjustment = 2 * (($maxSum - $y) / ($maxSum - $minSum)) - 1; // To generate caves, we bring the noiseAdjustment down away from 1. $caveLevel = $minSum - 10; $distAboveCaveLevel = max(0, $y - $caveLevel); // must be positive $noiseAdjustment = min($noiseAdjustment, 0.4 + $distAboveCaveLevel / 10); $noiseValue = $noise[$x][$z][$y] + $noiseAdjustment; if ($noiseValue > 0) { $chunk->setBlockId($x, $y, $z, Block::STONE); $solidLand = true; } elseif ($y <= $this->waterHeight && $solidLand == false) { $chunk->setBlockId($x, $y, $z, Block::STILL_WATER); } } } } foreach ($this->generationPopulators as $populator) { $populator->populate($this->level, $chunkX, $chunkZ, $this->random); } }
/** * @param int $chunkX * @param int $chunkZ * @param FullChunk $chunk */ public function setChunk($chunkX, $chunkZ, FullChunk $chunk = null) { if ($chunk === null) { unset($this->chunks[Level::chunkHash($chunkX, $chunkZ)]); return; } $this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $chunk; }
/** * @param Player $player */ public function spawnTo(Player $player) { if (!isset($this->hasSpawned[$player->getLoaderId()]) and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])) { $this->hasSpawned[$player->getLoaderId()] = $player; } }