downloadAssets method

Future<void> downloadAssets(
  1. VersionInfo versionInfo, {
  2. VersionInfo? inheritsFrom,
})

Downloads all assets required for the specified Minecraft version.

First downloads the asset index file, then iterates through all assets listed in the index and downloads them. Progress is reported via callbacks.

versionInfo Information about the Minecraft version whose assets should be downloaded.

inheritsFrom Optional version info of the version to download. If not provided, uses the versionInfo.

Throws an exception if the asset index is missing or if any part of the download process fails.

Implementation

Future<void> downloadAssets(
  VersionInfo versionInfo, {
  VersionInfo? inheritsFrom,
}) async {
  if (versionInfo.assetIndex == null && inheritsFrom?.assetIndex == null) {
    throw Exception('Failed to get asset index info');
  }

  // Use inheritsFrom if provided and has valid assetIndex, otherwise use versionInfo
  final targetVersionInfo =
      (inheritsFrom != null && inheritsFrom.assetIndex != null)
          ? inheritsFrom
          : versionInfo;

  await _downloadAssets(targetVersionInfo);
}