Fix download assets for 1.13+

This commit is contained in:
khanhduytran0 2020-09-11 20:13:18 +07:00
parent 71fcfa4ed1
commit 5980b5822f
2 changed files with 10 additions and 5 deletions

View File

@ -15,6 +15,7 @@ public class JMinecraftVersionList {
public static class Version {
// Since 1.13, so it's one of ways to check
public Arguments arguments;
public AssetIndex assetIndex;
public String assets;
public Map<String, MinecraftClientInfo> downloads;
@ -46,5 +47,9 @@ public class JMinecraftVersionList {
}
}
}
public static class AssetIndex {
public String id, sha1, url;
public long size, totalSize;
}
}

View File

@ -469,8 +469,7 @@ public class MCLauncherActivity extends AppCompatActivity
statusIsLaunching(true);
}
private int maxSubProgress = 1;
private int valSubProgress = 1;
private JMinecraftVersionList.Version verInfo;
@Override
protected Throwable doInBackground(final String[] p1) {
Throwable throwable = null;
@ -480,8 +479,6 @@ public class MCLauncherActivity extends AppCompatActivity
//Downloading libraries
String inputPath = Tools.versnDir + downVName + ".jar";
JMinecraftVersionList.Version verInfo;
try {
//com.pojavdx.dx.mod.Main.debug = true;
@ -593,6 +590,8 @@ public class MCLauncherActivity extends AppCompatActivity
try {
downloadAssets(verInfo.assets, new File(Tools.ASSETS_PATH));
} catch (Exception e) {
e.printStackTrace();
// Ignore it
launchWithError = false;
} finally {
@ -691,12 +690,13 @@ public class MCLauncherActivity extends AppCompatActivity
public static final String MINECRAFT_RES = "http://resources.download.minecraft.net/";
public JAssets downloadIndex(String versionName, File output) throws Exception {
String versionJson = DownloadUtils.downloadString("http://s3.amazonaws.com/Minecraft.Download/indexes/" + versionName + ".json");
String versionJson = DownloadUtils.downloadString(verInfo.assetIndex != null ? verInfo.assetIndex.url : "http://s3.amazonaws.com/Minecraft.Download/indexes/" + versionName + ".json");
JAssets version = gsonss.fromJson(versionJson, JAssets.class);
output.getParentFile().mkdirs();
Tools.write(output.getAbsolutePath(), versionJson.getBytes(Charset.forName("UTF-8")));
return version;
}
public void downloadAsset(JAssetInfo asset, File objectsDir) throws IOException, Throwable {
String assetPath = asset.hash.substring(0, 2) + "/" + asset.hash;
File outFile = new File(objectsDir, assetPath);