minecraft-src/com/mojang/realmsclient/util/task/DownloadTask.java
2025-07-04 03:45:38 +03:00

81 lines
2.2 KiB
Java

package com.mojang.realmsclient.util.task;
import com.mojang.logging.LogUtils;
import com.mojang.realmsclient.client.RealmsClient;
import com.mojang.realmsclient.dto.WorldDownload;
import com.mojang.realmsclient.exception.RealmsServiceException;
import com.mojang.realmsclient.exception.RetryCallException;
import com.mojang.realmsclient.gui.screens.RealmsDownloadLatestWorldScreen;
import com.mojang.realmsclient.gui.screens.RealmsGenericErrorScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.slf4j.Logger;
@Environment(EnvType.CLIENT)
public class DownloadTask extends LongRunningTask {
private static final Logger LOGGER = LogUtils.getLogger();
private static final Component TITLE = Component.translatable("mco.download.preparing");
private final long realmId;
private final int slot;
private final Screen lastScreen;
private final String downloadName;
public DownloadTask(long worldId, int slot, String downloadName, Screen lastScreen) {
this.realmId = worldId;
this.slot = slot;
this.lastScreen = lastScreen;
this.downloadName = downloadName;
}
public void run() {
RealmsClient realmsClient = RealmsClient.getOrCreate();
int i = 0;
while (i < 25) {
try {
if (this.aborted()) {
return;
}
WorldDownload worldDownload = realmsClient.requestDownloadInfo(this.realmId, this.slot);
pause(1L);
if (this.aborted()) {
return;
}
setScreen(new RealmsDownloadLatestWorldScreen(this.lastScreen, worldDownload, this.downloadName, bl -> {}));
return;
} catch (RetryCallException var4) {
if (this.aborted()) {
return;
}
pause(var4.delaySeconds);
i++;
} catch (RealmsServiceException var5) {
if (this.aborted()) {
return;
}
LOGGER.error("Couldn't download world data", (Throwable)var5);
setScreen(new RealmsGenericErrorScreen(var5, this.lastScreen));
return;
} catch (Exception var6) {
if (this.aborted()) {
return;
}
LOGGER.error("Couldn't download world data", (Throwable)var6);
this.error(var6);
return;
}
}
}
@Override
public Component getTitle() {
return TITLE;
}
}