public function handlePackets()
 {
     while (strlen($packet = $this->generationThread->readThreadToMainPacket()) > 0) {
         $pid = ord($packet[0]);
         $offset = 1;
         if ($pid === GenerationManager::PACKET_REQUEST_CHUNK) {
             $levelID = Binary::readInt(substr($packet, $offset, 4));
             $offset += 4;
             $chunkX = Binary::readInt(substr($packet, $offset, 4));
             $offset += 4;
             $chunkZ = Binary::readInt(substr($packet, $offset, 4));
             $this->handleRequest($levelID, $chunkX, $chunkZ);
         } elseif ($pid === GenerationManager::PACKET_SEND_CHUNK) {
             $levelID = Binary::readInt(substr($packet, $offset, 4));
             $offset += 4;
             $len = ord($packet[$offset++]);
             /** @var FullChunk $class */
             $class = substr($packet, $offset, $len);
             $offset += $len;
             $level = $this->server->getLevel($levelID);
             if ($level instanceof Level) {
                 $chunk = $class::fromBinary(substr($packet, $offset), $level->getProvider());
                 $this->receiveChunk($levelID, $chunk);
             }
         }
     }
 }