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

    • 引用位置: 方法调用
    • 关联成员: RealmsMainScreen.play(), RealmsMainScreen.refreshServerList()
  • RealmsWorldUpload

    • 引用位置: 构造调用
    • 关联成员: RealmsWorldUpload()
  • RealmsWorldUploadStatusTracker

    • 引用位置: 方法调用
    • 关联成员: RealmsWorldUploadStatusTracker.noOp()
  • RealmsServer

    • 引用位置: 参数
  • RealmsSetting

    • 引用位置: 方法调用
    • 关联成员: RealmsSetting.hardcoreSetting()
  • RealmsSlot

    • 引用位置: 构造调用
    • 关联成员: RealmsSlot()
  • RealmsWorldOptions

    • 引用位置: 方法调用
    • 关联成员: RealmsWorldOptions.createFromSettings()
  • RealmsGenericErrorScreen

    • 引用位置: 构造调用
    • 关联成员: RealmsGenericErrorScreen()
  • RealmCreationTask

    • 引用位置: 参数
  • SharedConstants

    • 引用位置: 方法调用
    • 关联成员: SharedConstants.getCurrentVersion()
  • Minecraft

    • 引用位置: 参数
  • AlertScreen

    • 引用位置: 构造调用
    • 关联成员: AlertScreen()
  • Screen

    • 引用位置: 参数
  • CreateWorldScreen

    • 引用位置: 方法调用
    • 关联成员: CreateWorldScreen.openFresh()
  • RegistryAccess

    • 引用位置: 参数
  • CompoundTag

    • 引用位置: 构造调用
    • 关联成员: CompoundTag()
  • NbtIo

    • 引用位置: 方法调用
    • 关联成员: NbtIo.writeCompressed()
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.empty(), Component.translatable()
  • GameRules

    • 引用位置: 参数
  • LevelDataAndDimensions

    • 引用位置: 参数
  • LevelStorageSource

    • 引用位置: 方法调用
    • 关联成员: LevelStorageSource.writeGameRules(), LevelStorageSource.writeWorldGenSettings()