RealmsCreateWorldFlow.java
com.mojang.realmsclient.client.worldupload.RealmsCreateWorldFlow
信息
- 全限定名:com.mojang.realmsclient.client.worldupload.RealmsCreateWorldFlow
- 类型:public class
- 包:com.mojang.realmsclient.client.worldupload
- 源码路径:src/main/java/com/mojang/realmsclient/client/worldupload/RealmsCreateWorldFlow.java
- 起始行号:L38
- 职责:
TODO
字段/常量
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L39 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void createWorld(Minecraft minecraft, Screen returnScreen, Screen lastScreen, int slot, RealmsServer realmsServer, RealmCreationTask realmCreationTask) @ L41
- 方法名:createWorld
- 源码定位:L41
- 返回类型:void
- 修饰符:public static
参数:
- minecraft: Minecraft
- returnScreen: Screen
- lastScreen: Screen
- slot: int
- realmsServer: RealmsServer
- realmCreationTask: RealmCreationTask
说明:
TODO
private static Path createTemporaryWorldFolder(RegistryAccess registryAccess, LevelDataAndDimensions.WorldDataAndGenSettings worldDataAndGenSettings, Optional<GameRules> gameRulesOpt, Path tempDataPackDir) @ L117
- 方法名:createTemporaryWorldFolder
- 源码定位:L117
- 返回类型:Path
- 修饰符:private static
参数:
- registryAccess: RegistryAccess
- worldDataAndGenSettings: LevelDataAndDimensions.WorldDataAndGenSettings
- gameRulesOpt: Optional
- tempDataPackDir: Path
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class RealmsCreateWorldFlow {
private static final Logger LOGGER = LogUtils.getLogger();
public static void createWorld(
Minecraft minecraft, Screen returnScreen, Screen lastScreen, int slot, RealmsServer realmsServer, @Nullable RealmCreationTask realmCreationTask
) {
CreateWorldScreen.openFresh(
minecraft,
() -> minecraft.setScreen(returnScreen),
(createWorldScreen, finalLayers, worldDataAndGenSettings, gameRules, tempDataPackDir) -> {
Path worldFolder;
try {
worldFolder = createTemporaryWorldFolder(finalLayers.compositeAccess(), worldDataAndGenSettings, gameRules, tempDataPackDir);
} catch (IOException var15) {
LOGGER.warn("Failed to create temporary world folder", (Throwable)var15);
minecraft.setScreen(new RealmsGenericErrorScreen(Component.translatable("mco.create.world.failed"), lastScreen));
return true;
}
RealmsWorldOptions realmsWorldOptions = RealmsWorldOptions.createFromSettings(
worldDataAndGenSettings.data().getLevelSettings(), SharedConstants.getCurrentVersion().name()
);
RealmsSlot realmsSlot = new RealmsSlot(
slot, realmsWorldOptions, List.of(RealmsSetting.hardcoreSetting(worldDataAndGenSettings.data().isHardcore()))
);
RealmsWorldUpload realmsWorldUpload = new RealmsWorldUpload(
worldFolder, realmsSlot, minecraft.getUser(), realmsServer.id, RealmsWorldUploadStatusTracker.noOp()
);
minecraft.setScreenAndShow(
new AlertScreen(
realmsWorldUpload::cancel,
Component.translatable("mco.create.world.reset.title"),
Component.empty(),
CommonComponents.GUI_CANCEL,
false
)
);
if (realmCreationTask != null) {
realmCreationTask.run();
}
realmsWorldUpload.packAndUpload().handleAsync((result, exception) -> {
if (exception != null) {
if (exception instanceof CompletionException e) {
exception = e.getCause();
}
if (exception instanceof RealmsUploadCanceledException) {
minecraft.setScreenAndShow(lastScreen);
} else {
if (exception instanceof RealmsUploadFailedException realmsUploadFailedException) {
LOGGER.warn("Failed to create realms world {}", realmsUploadFailedException.getStatusMessage());
} else {
LOGGER.warn("Failed to create realms world {}", exception.getMessage());
}
minecraft.setScreenAndShow(new RealmsGenericErrorScreen(Component.translatable("mco.create.world.failed"), lastScreen));
}
} else {
if (returnScreen instanceof RealmsConfigureWorldScreen configureWorldScreen) {
configureWorldScreen.fetchServerData(realmsServer.id);
}
if (realmCreationTask != null) {
RealmsMainScreen.play(realmsServer, returnScreen, true);
} else {
minecraft.setScreenAndShow(returnScreen);
}
RealmsMainScreen.refreshServerList();
}
return null;
}, minecraft);
return true;
}
);
}
private static Path createTemporaryWorldFolder(
RegistryAccess registryAccess,
LevelDataAndDimensions.WorldDataAndGenSettings worldDataAndGenSettings,
Optional<GameRules> gameRulesOpt,
@Nullable Path tempDataPackDir
) throws IOException {
Path worldFolder = Files.createTempDirectory("minecraft_realms_world_upload");
if (tempDataPackDir != null) {
Files.move(tempDataPackDir, worldFolder.resolve("datapacks"));
}
WorldData worldData = worldDataAndGenSettings.data();
CompoundTag dataTag = worldData.createTag(null);
CompoundTag root = new CompoundTag();
root.put("Data", dataTag);
Path levelDat = Files.createFile(worldFolder.resolve("level.dat"));
NbtIo.writeCompressed(root, levelDat);
LevelStorageSource.writeWorldGenSettings(registryAccess, worldFolder, worldDataAndGenSettings.genSettings());
if (gameRulesOpt.isPresent()) {
LevelStorageSource.writeGameRules(worldData, worldFolder, gameRulesOpt.get());
}
return worldFolder;
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
RealmsMainScreen.play(), RealmsMainScreen.refreshServerList()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
RealmsWorldUpload()
- 引用位置:
-
RealmsWorldUploadStatusTracker
- 引用位置:
方法调用 - 关联成员:
RealmsWorldUploadStatusTracker.noOp()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RealmsSetting.hardcoreSetting()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
RealmsSlot()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RealmsWorldOptions.createFromSettings()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
RealmsGenericErrorScreen()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SharedConstants.getCurrentVersion()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
AlertScreen()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
CreateWorldScreen.openFresh()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
CompoundTag()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
NbtIo.writeCompressed()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.empty(), Component.translatable()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LevelStorageSource.writeGameRules(), LevelStorageSource.writeWorldGenSettings()
- 引用位置: