RealmsBrokenWorldScreen.java

com.mojang.realmsclient.gui.screens.RealmsBrokenWorldScreen

信息

  • 全限定名:com.mojang.realmsclient.gui.screens.RealmsBrokenWorldScreen
  • 类型:public class
  • 包:com.mojang.realmsclient.gui.screens
  • 源码路径:src/main/java/com/mojang/realmsclient/gui/screens/RealmsBrokenWorldScreen.java
  • 起始行号:L37
  • 继承:RealmsScreen
  • 职责:

    TODO

字段/常量

  • SLOT_FRAME_SPRITE

    • 类型: Identifier
    • 修饰符: private static final
    • 源码定位: L38
    • 说明:

      TODO

  • LOGGER

    • 类型: Logger
    • 修饰符: private static final
    • 源码定位: L39
    • 说明:

      TODO

  • DEFAULT_BUTTON_WIDTH

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L40
    • 说明:

      TODO

  • lastScreen

    • 类型: Screen
    • 修饰符: private final
    • 源码定位: L41
    • 说明:

      TODO

  • serverData

    • 类型: RealmsServer
    • 修饰符: private
    • 源码定位: L42
    • 说明:

      TODO

  • serverId

    • 类型: long
    • 修饰符: private final
    • 源码定位: L43
    • 说明:

      TODO

  • message

    • 类型: Component[]
    • 修饰符: private final
    • 源码定位: L44
    • 说明:

      TODO

  • leftX

    • 类型: int
    • 修饰符: private
    • 源码定位: L47
    • 说明:

      TODO

  • slotsThatHasBeenDownloaded

    • 类型: List<Integer>
    • 修饰符: private final
    • 源码定位: L48
    • 说明:

      TODO

  • animTick

    • 类型: int
    • 修饰符: private
    • 源码定位: L49
    • 说明:

      TODO

内部类/嵌套类型

构造器

public RealmsBrokenWorldScreen(Screen lastScreen, long serverId, boolean isMinigame) @ L51

  • 构造器名:RealmsBrokenWorldScreen
  • 源码定位:L51
  • 修饰符:public

参数:

  • lastScreen: Screen
  • serverId: long
  • isMinigame: boolean

说明:

TODO

方法

下面的方法块按源码顺序生成。

public void init() @ L57

  • 方法名:init
  • 源码定位:L57
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public Component getNarrationMessage() @ L70

  • 方法名:getNarrationMessage
  • 源码定位:L70
  • 返回类型:Component
  • 修饰符:public

参数:

说明:

TODO

private void addButtons() @ L75

  • 方法名:addButtons
  • 源码定位:L75
  • 返回类型:void
  • 修饰符:private

参数:

说明:

TODO

public void tick() @ L114

  • 方法名:tick
  • 源码定位:L114
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public void extractRenderState(GuiGraphicsExtractor graphics, int xm, int ym, float a) @ L119

  • 方法名:extractRenderState
  • 源码定位:L119
  • 返回类型:void
  • 修饰符:public

参数:

  • graphics: GuiGraphicsExtractor
  • xm: int
  • ym: int
  • a: float

说明:

TODO

private int getFramePositionX(int i) @ L163

  • 方法名:getFramePositionX
  • 源码定位:L163
  • 返回类型:int
  • 修饰符:private

参数:

  • i: int

说明:

TODO

public Screen createErrorScreen(RealmsServiceException exception) @ L167

  • 方法名:createErrorScreen
  • 源码定位:L167
  • 返回类型:Screen
  • 修饰符:public

参数:

  • exception: RealmsServiceException

说明:

TODO

private void fetchServerData(long realmId) @ L171

  • 方法名:fetchServerData
  • 源码定位:L171
  • 返回类型:void
  • 修饰符:private

参数:

  • realmId: long

说明:

TODO

public void doSwitchOrReset() @ L181

  • 方法名:doSwitchOrReset
  • 源码定位:L181
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

private void downloadWorld(int slotId) @ L205

  • 方法名:downloadWorld
  • 源码定位:L205
  • 返回类型:void
  • 修饰符:private

参数:

  • slotId: int

说明:

TODO

public void onClose() @ L228

  • 方法名:onClose
  • 源码定位:L228
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

private boolean isMinigame() @ L233

  • 方法名:isMinigame
  • 源码定位:L233
  • 返回类型:boolean
  • 修饰符:private

参数:

说明:

TODO

private void extractSlotFrame(GuiGraphicsExtractor graphics, int x, int y, int xm, int ym, boolean active, String text, int i, long imageId, String image, boolean empty) @ L237

  • 方法名:extractSlotFrame
  • 源码定位:L237
  • 返回类型:void
  • 修饰符:private

参数:

  • graphics: GuiGraphicsExtractor
  • x: int
  • y: int
  • xm: int
  • ym: int
  • active: boolean
  • text: String
  • i: int
  • imageId: long
  • image: String
  • empty: boolean

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class RealmsBrokenWorldScreen extends RealmsScreen {
    private static final Identifier SLOT_FRAME_SPRITE = Identifier.withDefaultNamespace("widget/slot_frame");
    private static final Logger LOGGER = LogUtils.getLogger();
    private static final int DEFAULT_BUTTON_WIDTH = 80;
    private final Screen lastScreen;
    private @Nullable RealmsServer serverData;
    private final long serverId;
    private final Component[] message = new Component[]{
        Component.translatable("mco.brokenworld.message.line1"), Component.translatable("mco.brokenworld.message.line2")
    };
    private int leftX;
    private final List<Integer> slotsThatHasBeenDownloaded = Lists.newArrayList();
    private int animTick;
 
    public RealmsBrokenWorldScreen(Screen lastScreen, long serverId, boolean isMinigame) {
        super(isMinigame ? Component.translatable("mco.brokenworld.minigame.title") : Component.translatable("mco.brokenworld.title"));
        this.lastScreen = lastScreen;
        this.serverId = serverId;
    }
 
    @Override
    public void init() {
        this.leftX = this.width / 2 - 150;
        this.addRenderableWidget(
            Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).bounds((this.width - 150) / 2, row(13) - 5, 150, 20).build()
        );
        if (this.serverData == null) {
            this.fetchServerData(this.serverId);
        } else {
            this.addButtons();
        }
    }
 
    @Override
    public Component getNarrationMessage() {
        return ComponentUtils.formatList(Stream.concat(Stream.of(this.title), Stream.of(this.message)).collect(Collectors.toList()), CommonComponents.SPACE);
    }
 
    private void addButtons() {
        for (Entry<Integer, RealmsSlot> entry : this.serverData.slots.entrySet()) {
            int slot = entry.getKey();
            boolean canPlay = slot != this.serverData.activeSlot || this.serverData.isMinigameActive();
            Button playOrDownloadButton;
            if (canPlay) {
                playOrDownloadButton = Button.builder(
                        Component.translatable("mco.brokenworld.play"),
                        button -> this.minecraft
                            .setScreen(new RealmsLongRunningMcoTaskScreen(this.lastScreen, new SwitchSlotTask(this.serverData.id, slot, this::doSwitchOrReset)))
                    )
                    .bounds(this.getFramePositionX(slot), row(8), 80, 20)
                    .build();
                playOrDownloadButton.active = !this.serverData.slots.get(slot).options.empty;
            } else {
                playOrDownloadButton = Button.builder(
                        Component.translatable("mco.brokenworld.download"),
                        button -> this.minecraft
                            .setScreen(
                                RealmsPopups.infoPopupScreen(
                                    this,
                                    Component.translatable("mco.configure.world.restore.download.question.line1"),
                                    popupScreen -> this.downloadWorld(slot)
                                )
                            )
                    )
                    .bounds(this.getFramePositionX(slot), row(8), 80, 20)
                    .build();
            }
 
            if (this.slotsThatHasBeenDownloaded.contains(slot)) {
                playOrDownloadButton.active = false;
                playOrDownloadButton.setMessage(Component.translatable("mco.brokenworld.downloaded"));
            }
 
            this.addRenderableWidget(playOrDownloadButton);
        }
    }
 
    @Override
    public void tick() {
        this.animTick++;
    }
 
    @Override
    public void extractRenderState(GuiGraphicsExtractor graphics, int xm, int ym, float a) {
        super.extractRenderState(graphics, xm, ym, a);
        graphics.centeredText(this.font, this.title, this.width / 2, 17, -1);
 
        for (int i = 0; i < this.message.length; i++) {
            graphics.centeredText(this.font, this.message[i], this.width / 2, row(-1) + 3 + i * 12, -6250336);
        }
 
        if (this.serverData != null) {
            for (Entry<Integer, RealmsSlot> entry : this.serverData.slots.entrySet()) {
                if (entry.getValue().options.templateImage != null && entry.getValue().options.templateId != -1L) {
                    this.extractSlotFrame(
                        graphics,
                        this.getFramePositionX(entry.getKey()),
                        row(1) + 5,
                        xm,
                        ym,
                        this.serverData.activeSlot == entry.getKey() && !this.isMinigame(),
                        entry.getValue().options.getSlotName(entry.getKey()),
                        entry.getKey(),
                        entry.getValue().options.templateId,
                        entry.getValue().options.templateImage,
                        entry.getValue().options.empty
                    );
                } else {
                    this.extractSlotFrame(
                        graphics,
                        this.getFramePositionX(entry.getKey()),
                        row(1) + 5,
                        xm,
                        ym,
                        this.serverData.activeSlot == entry.getKey() && !this.isMinigame(),
                        entry.getValue().options.getSlotName(entry.getKey()),
                        entry.getKey(),
                        -1L,
                        null,
                        entry.getValue().options.empty
                    );
                }
            }
        }
    }
 
    private int getFramePositionX(int i) {
        return this.leftX + (i - 1) * 110;
    }
 
    public Screen createErrorScreen(RealmsServiceException exception) {
        return new RealmsGenericErrorScreen(exception, this.lastScreen);
    }
 
    private void fetchServerData(long realmId) {
        RealmsUtil.<RealmsServer>supplyAsync(
                client -> client.getOwnRealm(realmId), RealmsUtil.openScreenAndLogOnFailure(this::createErrorScreen, "Couldn't get own world")
            )
            .thenAcceptAsync(serverData -> {
                this.serverData = serverData;
                this.addButtons();
            }, this.minecraft);
    }
 
    public void doSwitchOrReset() {
        new Thread(
                () -> {
                    RealmsClient client = RealmsClient.getOrCreate();
                    if (this.serverData.state == RealmsServer.State.CLOSED) {
                        this.minecraft
                            .execute(
                                () -> this.minecraft
                                    .setScreen(new RealmsLongRunningMcoTaskScreen(this, new OpenServerTask(this.serverData, this, true, this.minecraft)))
                            );
                    } else {
                        try {
                            RealmsServer ownRealm = client.getOwnRealm(this.serverId);
                            this.minecraft.execute(() -> RealmsMainScreen.play(ownRealm, this));
                        } catch (RealmsServiceException var3) {
                            LOGGER.error("Couldn't get own world", (Throwable)var3);
                            this.minecraft.execute(() -> this.minecraft.setScreen(this.createErrorScreen(var3)));
                        }
                    }
                }
            )
            .start();
    }
 
    private void downloadWorld(int slotId) {
        RealmsClient client = RealmsClient.getOrCreate();
 
        try {
            WorldDownload worldDownload = client.requestDownloadInfo(this.serverData.id, slotId);
            RealmsDownloadLatestWorldScreen downloadScreen = new RealmsDownloadLatestWorldScreen(
                this, worldDownload, this.serverData.getWorldName(slotId), result -> {
                    if (result) {
                        this.slotsThatHasBeenDownloaded.add(slotId);
                        this.clearWidgets();
                        this.addButtons();
                    } else {
                        this.minecraft.setScreen(this);
                    }
                }
            );
            this.minecraft.setScreen(downloadScreen);
        } catch (RealmsServiceException var5) {
            LOGGER.error("Couldn't download world data", (Throwable)var5);
            this.minecraft.setScreen(new RealmsGenericErrorScreen(var5, this));
        }
    }
 
    @Override
    public void onClose() {
        this.minecraft.setScreen(this.lastScreen);
    }
 
    private boolean isMinigame() {
        return this.serverData != null && this.serverData.isMinigameActive();
    }
 
    private void extractSlotFrame(
        GuiGraphicsExtractor graphics, int x, int y, int xm, int ym, boolean active, String text, int i, long imageId, @Nullable String image, boolean empty
    ) {
        Identifier texture;
        if (empty) {
            texture = RealmsWorldSlotButton.EMPTY_SLOT_LOCATION;
        } else if (image != null && imageId != -1L) {
            texture = RealmsTextureManager.worldTemplate(String.valueOf(imageId), image);
        } else if (i == 1) {
            texture = RealmsWorldSlotButton.DEFAULT_WORLD_SLOT_1;
        } else if (i == 2) {
            texture = RealmsWorldSlotButton.DEFAULT_WORLD_SLOT_2;
        } else if (i == 3) {
            texture = RealmsWorldSlotButton.DEFAULT_WORLD_SLOT_3;
        } else {
            texture = RealmsTextureManager.worldTemplate(String.valueOf(this.serverData.minigameId), this.serverData.minigameImage);
        }
 
        if (active) {
            float c = 0.9F + 0.1F * Mth.cos(this.animTick * 0.2F);
            graphics.blit(RenderPipelines.GUI_TEXTURED, texture, x + 3, y + 3, 0.0F, 0.0F, 74, 74, 74, 74, 74, 74, ARGB.colorFromFloat(1.0F, c, c, c));
            graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_FRAME_SPRITE, x, y, 80, 80);
        } else {
            int color = ARGB.colorFromFloat(1.0F, 0.56F, 0.56F, 0.56F);
            graphics.blit(RenderPipelines.GUI_TEXTURED, texture, x + 3, y + 3, 0.0F, 0.0F, 74, 74, 74, 74, 74, 74, color);
            graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_FRAME_SPRITE, x, y, 80, 80, color);
        }
 
        graphics.centeredText(this.font, text, x + 40, y + 66, -1);
    }
}

引用的其他类

  • RealmsMainScreen

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

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

    • 引用位置: 字段
  • RealmsServiceException

    • 引用位置: 参数
  • RealmsDownloadLatestWorldScreen

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

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

    • 引用位置: 构造调用
    • 关联成员: RealmsLongRunningMcoTaskScreen()
  • RealmsPopups

    • 引用位置: 方法调用
    • 关联成员: RealmsPopups.infoPopupScreen()
  • RealmsTextureManager

    • 引用位置: 方法调用
    • 关联成员: RealmsTextureManager.worldTemplate()
  • RealmsUtil

    • 引用位置: 方法调用
    • 关联成员: RealmsUtil.openScreenAndLogOnFailure()
  • OpenServerTask

    • 引用位置: 构造调用
    • 关联成员: OpenServerTask()
  • SwitchSlotTask

    • 引用位置: 构造调用
    • 关联成员: SwitchSlotTask()
  • GuiGraphicsExtractor

    • 引用位置: 参数
  • Button

    • 引用位置: 方法调用
    • 关联成员: Button.builder()
  • Screen

    • 引用位置: 参数/字段/返回值
  • Component

    • 引用位置: 字段/方法调用/返回值
    • 关联成员: Component.translatable()
  • ComponentUtils

    • 引用位置: 方法调用
    • 关联成员: ComponentUtils.formatList()
  • RealmsScreen

    • 引用位置: 继承
  • Identifier

    • 引用位置: 字段/方法调用
    • 关联成员: Identifier.withDefaultNamespace()
  • ARGB

    • 引用位置: 方法调用
    • 关联成员: ARGB.colorFromFloat()
  • Mth

    • 引用位置: 方法调用
    • 关联成员: Mth.cos()