SwitchSlotTask .java

com.mojang.realmsclient.util.task.SwitchSlotTask (class, 61 lines): members: realmId, getTitle, callback, slot, TITLE, run, LOGGER. imports: RealmsClient.

com.mojang.realmsclient.util.taskclass61 linescommonextends LongRunningTask1.4 KB

API Surface (2)

void run()
Component getTitle()

Fields & Constants (5)

LOGGER
TITLE
realmId
slot
callback

String literals (2)

"mco.minigame.world.slot.screen.title"
"Couldn't switch world!"

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SwitchSlotTask.java61 lines · Minecraft 26.3 · verbatim
1
package com.mojang.realmsclient.util.task;
2
3
import com.mojang.logging.LogUtils;
4
import com.mojang.realmsclient.client.RealmsClient;
5
import com.mojang.realmsclient.exception.RetryCallException;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import net.minecraft.network.chat.Component;
9
import org.slf4j.Logger;
10
11
@Environment(EnvType.CLIENT)
12
public class SwitchSlotTask extends LongRunningTask {
13
	private static final Logger LOGGER = LogUtils.getLogger();
14
	private static final Component TITLE = Component.translatable("mco.minigame.world.slot.screen.title");
15
	private final long realmId;
16
	private final int slot;
17
	private final Runnable callback;
18
19
	public SwitchSlotTask(final long realmId, final int slot, final Runnable callback) {
20
		this.realmId = realmId;
21
		this.slot = slot;
22
		this.callback = callback;
23
	}
24
25
	@Override
26
	public void run() {
27
		RealmsClient client = RealmsClient.getOrCreate();
28
29
		for (int i = 0; i < 25; i++) {
30
			try {
31
				if (this.aborted()) {
32
					return;
33
				}
34
35
				if (client.switchSlot(this.realmId, this.slot)) {
36
					this.callback.run();
37
					break;
38
				}
39
			} catch (RetryCallException e) {
40
				if (this.aborted()) {
41
					return;
42
				}
43
44
				pause(e.delaySeconds);
45
			} catch (Exception e) {
46
				if (this.aborted()) {
47
					return;
48
				}
49
50
				LOGGER.error("Couldn't switch world!");
51
				this.error(e);
52
			}
53
		}
54
	}
55
56
	@Override
57
	public Component getTitle() {
58
		return TITLE;
59
	}
60
}
61

Decompiled Minecraft 26.3 source of SwitchSlotTask (com/mojang/realmsclient/util/task/SwitchSlotTask.java) with Mojang official mappings, stored verbatim on the site.