/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.logging.LogUtils * org.jspecify.annotations.Nullable * org.slf4j.Logger */ package com.mojang.realmsclient.gui.screens; import com.mojang.logging.LogUtils; import com.mojang.realmsclient.RealmsMainScreen; import com.mojang.realmsclient.client.RealmsClient; import com.mojang.realmsclient.client.worldupload.RealmsCreateWorldFlow; import com.mojang.realmsclient.dto.RealmsServer; import com.mojang.realmsclient.dto.WorldTemplate; import com.mojang.realmsclient.dto.WorldTemplatePaginatedList; import com.mojang.realmsclient.exception.RealmsServiceException; import com.mojang.realmsclient.gui.screens.RealmsLongRunningMcoTaskScreen; import com.mojang.realmsclient.gui.screens.RealmsSelectFileToUploadScreen; import com.mojang.realmsclient.gui.screens.RealmsSelectWorldTemplateScreen; import com.mojang.realmsclient.util.task.LongRunningTask; import com.mojang.realmsclient.util.task.RealmCreationTask; import com.mojang.realmsclient.util.task.ResettingTemplateWorldTask; import com.mojang.realmsclient.util.task.SwitchSlotTask; import java.util.ArrayList; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.StringWidget; import net.minecraft.client.gui.layouts.GridLayout; import net.minecraft.client.gui.layouts.HeaderAndFooterLayout; import net.minecraft.client.gui.layouts.LayoutSettings; import net.minecraft.client.gui.layouts.LinearLayout; import net.minecraft.client.gui.layouts.SpacerElement; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.RenderPipelines; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.realms.RealmsScreen; import net.minecraft.resources.Identifier; import net.minecraft.util.ARGB; import org.jspecify.annotations.Nullable; import org.slf4j.Logger; public class RealmsResetWorldScreen extends RealmsScreen { private static final Logger LOGGER = LogUtils.getLogger(); private static final Component CREATE_REALM_TITLE = Component.translatable("mco.selectServer.create"); private static final Component CREATE_REALM_SUBTITLE = Component.translatable("mco.selectServer.create.subtitle").withColor(-6250336); private static final Component CREATE_WORLD_TITLE = Component.translatable("mco.configure.world.switch.slot"); private static final Component CREATE_WORLD_SUBTITLE = Component.translatable("mco.configure.world.switch.slot.subtitle").withColor(-6250336); private static final Component GENERATE_NEW_WORLD = Component.translatable("mco.reset.world.generate"); private static final Component RESET_WORLD_TITLE = Component.translatable("mco.reset.world.title"); private static final Component RESET_WORLD_SUBTITLE = Component.translatable("mco.reset.world.warning").withColor(-65536); public static final Component CREATE_WORLD_RESET_TASK_TITLE = Component.translatable("mco.create.world.reset.title"); private static final Component RESET_WORLD_RESET_TASK_TITLE = Component.translatable("mco.reset.world.resetting.screen.title"); private static final Component WORLD_TEMPLATES_TITLE = Component.translatable("mco.reset.world.template"); private static final Component ADVENTURES_TITLE = Component.translatable("mco.reset.world.adventure"); private static final Component EXPERIENCES_TITLE = Component.translatable("mco.reset.world.experience"); private static final Component INSPIRATION_TITLE = Component.translatable("mco.reset.world.inspiration"); private final Screen lastScreen; private final RealmsServer serverData; private final Component subtitle; private final Component resetTaskTitle; private static final Identifier UPLOAD_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/upload.png"); private static final Identifier ADVENTURE_MAP_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/adventure.png"); private static final Identifier SURVIVAL_SPAWN_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/survival_spawn.png"); private static final Identifier NEW_WORLD_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/new_world.png"); private static final Identifier EXPERIENCE_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/experience.png"); private static final Identifier INSPIRATION_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/inspiration.png"); private WorldTemplatePaginatedList templates; private WorldTemplatePaginatedList adventuremaps; private WorldTemplatePaginatedList experiences; private WorldTemplatePaginatedList inspirations; public final int slot; private final @Nullable RealmCreationTask realmCreationTask; private final Runnable resetWorldRunnable; private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this); private RealmsResetWorldScreen(Screen lastScreen, RealmsServer serverData, int slot, Component title, Component subtitle, Component resetTaskTitle, Runnable resetWorldRunnable) { this(lastScreen, serverData, slot, title, subtitle, resetTaskTitle, null, resetWorldRunnable); } public RealmsResetWorldScreen(Screen lastScreen, RealmsServer serverData, int slot, Component title, Component subtitle, Component resetTaskTitle, @Nullable RealmCreationTask realmCreationTask, Runnable resetWorldRunnable) { super(title); this.lastScreen = lastScreen; this.serverData = serverData; this.slot = slot; this.subtitle = subtitle; this.resetTaskTitle = resetTaskTitle; this.realmCreationTask = realmCreationTask; this.resetWorldRunnable = resetWorldRunnable; } public static RealmsResetWorldScreen forNewRealm(Screen lastScreen, RealmsServer serverData, RealmCreationTask realmCreationTask, Runnable resetWorldRunnable) { return new RealmsResetWorldScreen(lastScreen, serverData, serverData.activeSlot, CREATE_REALM_TITLE, CREATE_REALM_SUBTITLE, CREATE_WORLD_RESET_TASK_TITLE, realmCreationTask, resetWorldRunnable); } public static RealmsResetWorldScreen forEmptySlot(Screen lastScreen, int slot, RealmsServer serverData, Runnable resetWorldRunnable) { return new RealmsResetWorldScreen(lastScreen, serverData, slot, CREATE_WORLD_TITLE, CREATE_WORLD_SUBTITLE, CREATE_WORLD_RESET_TASK_TITLE, resetWorldRunnable); } public static RealmsResetWorldScreen forResetSlot(Screen lastScreen, RealmsServer serverData, Runnable resetWorldRunnable) { return new RealmsResetWorldScreen(lastScreen, serverData, serverData.activeSlot, RESET_WORLD_TITLE, RESET_WORLD_SUBTITLE, RESET_WORLD_RESET_TASK_TITLE, resetWorldRunnable); } @Override public void init() { LinearLayout header = this.layout.addToHeader(LinearLayout.vertical()); header.defaultCellSetting().padding(this.font.lineHeight / 3); header.addChild(new StringWidget(this.title, this.font), LayoutSettings::alignHorizontallyCenter); header.addChild(new StringWidget(this.subtitle, this.font), LayoutSettings::alignHorizontallyCenter); new Thread("Realms-reset-world-fetcher"){ @Override public void run() { RealmsClient client = RealmsClient.getOrCreate(); try { WorldTemplatePaginatedList templates = client.fetchWorldTemplates(1, 10, RealmsServer.WorldType.NORMAL); WorldTemplatePaginatedList adventuremaps = client.fetchWorldTemplates(1, 10, RealmsServer.WorldType.ADVENTUREMAP); WorldTemplatePaginatedList experiences = client.fetchWorldTemplates(1, 10, RealmsServer.WorldType.EXPERIENCE); WorldTemplatePaginatedList inspirations = client.fetchWorldTemplates(1, 10, RealmsServer.WorldType.INSPIRATION); RealmsResetWorldScreen.this.minecraft.execute(() -> { RealmsResetWorldScreen.this.templates = templates; RealmsResetWorldScreen.this.adventuremaps = adventuremaps; RealmsResetWorldScreen.this.experiences = experiences; RealmsResetWorldScreen.this.inspirations = inspirations; }); } catch (RealmsServiceException e) { LOGGER.error("Couldn't fetch templates in reset world", (Throwable)e); } } }.start(); GridLayout grid = this.layout.addToContents(new GridLayout()); GridLayout.RowHelper helper = grid.createRowHelper(3); helper.defaultCellSetting().paddingHorizontal(16); helper.addChild(new FrameButton(this.minecraft.font, GENERATE_NEW_WORLD, NEW_WORLD_LOCATION, button -> RealmsCreateWorldFlow.createWorld(this.minecraft, this.lastScreen, this, this.slot, this.serverData, this.realmCreationTask))); helper.addChild(new FrameButton(this.minecraft.font, RealmsSelectFileToUploadScreen.TITLE, UPLOAD_LOCATION, button -> this.minecraft.setScreen(new RealmsSelectFileToUploadScreen(this.realmCreationTask, this.serverData.id, this.slot, this)))); helper.addChild(new FrameButton(this.minecraft.font, WORLD_TEMPLATES_TITLE, SURVIVAL_SPAWN_LOCATION, button -> this.minecraft.setScreen(new RealmsSelectWorldTemplateScreen(WORLD_TEMPLATES_TITLE, this::templateSelectionCallback, RealmsServer.WorldType.NORMAL, this.templates)))); helper.addChild(SpacerElement.height(16), 3); helper.addChild(new FrameButton(this.minecraft.font, ADVENTURES_TITLE, ADVENTURE_MAP_LOCATION, button -> this.minecraft.setScreen(new RealmsSelectWorldTemplateScreen(ADVENTURES_TITLE, this::templateSelectionCallback, RealmsServer.WorldType.ADVENTUREMAP, this.adventuremaps)))); helper.addChild(new FrameButton(this.minecraft.font, EXPERIENCES_TITLE, EXPERIENCE_LOCATION, button -> this.minecraft.setScreen(new RealmsSelectWorldTemplateScreen(EXPERIENCES_TITLE, this::templateSelectionCallback, RealmsServer.WorldType.EXPERIENCE, this.experiences)))); helper.addChild(new FrameButton(this.minecraft.font, INSPIRATION_TITLE, INSPIRATION_LOCATION, button -> this.minecraft.setScreen(new RealmsSelectWorldTemplateScreen(INSPIRATION_TITLE, this::templateSelectionCallback, RealmsServer.WorldType.INSPIRATION, this.inspirations)))); this.layout.addToFooter(Button.builder(CommonComponents.GUI_BACK, button -> this.onClose()).build()); this.layout.visitWidgets(x$0 -> { AbstractWidget cfr_ignored_0 = (AbstractWidget)this.addRenderableWidget(x$0); }); this.repositionElements(); } @Override protected void repositionElements() { this.layout.arrangeElements(); } @Override public Component getNarrationMessage() { return CommonComponents.joinForNarration(this.getTitle(), this.subtitle); } @Override public void onClose() { this.minecraft.setScreen(this.lastScreen); } private void templateSelectionCallback(@Nullable WorldTemplate template) { this.minecraft.setScreen(this); if (template != null) { this.runResetTasks(new ResettingTemplateWorldTask(template, this.serverData.id, this.resetTaskTitle, this.resetWorldRunnable)); } RealmsMainScreen.refreshServerList(); } private void runResetTasks(LongRunningTask resetTask) { ArrayList tasks = new ArrayList(); if (this.realmCreationTask != null) { tasks.add(this.realmCreationTask); } if (this.slot != this.serverData.activeSlot) { tasks.add(new SwitchSlotTask(this.serverData.id, this.slot, () -> {})); } tasks.add(resetTask); this.minecraft.setScreen(new RealmsLongRunningMcoTaskScreen(this.lastScreen, tasks.toArray(new LongRunningTask[0]))); } private class FrameButton extends Button { private static final Identifier SLOT_FRAME_SPRITE = Identifier.withDefaultNamespace("widget/slot_frame"); private static final int FRAME_SIZE = 60; private static final int FRAME_WIDTH = 2; private static final int IMAGE_SIZE = 56; private final Identifier image; private FrameButton(Font font, Component text, Identifier image, Button.OnPress onPress) { super(0, 0, 60, 60 + font.lineHeight, text, onPress, DEFAULT_NARRATION); this.image = image; } @Override public void renderContents(GuiGraphics graphics, int mouseX, int mouseY, float a) { boolean hoveredOrFocused = this.isHoveredOrFocused(); int color = -1; if (hoveredOrFocused) { color = ARGB.colorFromFloat(1.0f, 0.56f, 0.56f, 0.56f); } int x = this.getX(); int y = this.getY(); graphics.blit(RenderPipelines.GUI_TEXTURED, this.image, x + 2, y + 2, 0.0f, 0.0f, 56, 56, 56, 56, 56, 56, color); graphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_FRAME_SPRITE, x, y, 60, 60, color); int textColor = hoveredOrFocused ? -6250336 : -1; graphics.drawCenteredString(RealmsResetWorldScreen.this.font, this.getMessage(), x + 28, y - 14, textColor); } } }