package com.mojang.realmsclient; import com.mojang.realmsclient.util.RealmsPersistence; import net.minecraft.client.gui.components.TickableWidget; import com.mojang.realmsclient.util.RealmsTextureManager; import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.network.chat.TextComponent; import net.minecraft.ChatFormatting; import net.minecraft.client.gui.components.AbstractSelectionList; import com.mojang.realmsclient.gui.screens.RealmsCreateRealmScreen; import net.minecraft.client.gui.components.ObjectSelectionList; import net.minecraft.realms.RealmsObjectSelectionList; import org.apache.logging.log4j.LogManager; import net.minecraft.client.gui.Font; import net.minecraft.client.Minecraft; import com.mojang.realmsclient.gui.screens.RealmsPendingInvitesScreen; import java.util.Arrays; import java.util.Collection; import java.util.stream.Collector; import com.google.common.collect.ImmutableList; import net.minecraft.server.packs.resources.ResourceManager; import com.mojang.realmsclient.util.task.LongRunningTask; import com.mojang.realmsclient.gui.screens.RealmsLongRunningMcoTaskScreen; import com.mojang.realmsclient.util.task.GetServerDetailsTask; import java.util.concurrent.TimeUnit; import net.minecraft.util.Mth; import net.minecraft.network.chat.FormattedText; import net.minecraft.client.gui.GuiComponent; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.realmsclient.gui.screens.RealmsLongConfirmationScreen; import com.mojang.realmsclient.gui.screens.RealmsConfigureWorldScreen; import com.mojang.realmsclient.gui.screens.RealmsParentalConsentScreen; import com.mojang.realmsclient.exception.RealmsServiceException; import com.mojang.realmsclient.gui.screens.RealmsGenericErrorScreen; import com.mojang.realmsclient.gui.screens.RealmsClientOutdatedScreen; import com.mojang.realmsclient.dto.RegionPingResult; import com.mojang.realmsclient.dto.PingResult; import com.mojang.realmsclient.client.Ping; import com.mojang.realmsclient.dto.RealmsServerPlayerLists; import com.mojang.realmsclient.dto.RealmsServerPlayerList; import net.minecraft.realms.NarrationHelper; import net.minecraft.client.resources.language.I18n; import javax.annotation.Nullable; import net.minecraft.Util; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.client.gui.components.events.GuiEventListener; import com.mojang.realmsclient.client.RealmsClient; import java.util.Iterator; import com.google.common.collect.Lists; import java.util.concurrent.locks.ReentrantLock; import com.mojang.realmsclient.dto.RealmsServer; import net.minecraft.network.chat.Component; import net.minecraft.client.gui.components.Button; import com.google.common.util.concurrent.RateLimiter; import net.minecraft.client.gui.screens.Screen; import com.mojang.realmsclient.gui.RealmsDataFetcher; import java.util.List; import net.minecraft.resources.ResourceLocation; import org.apache.logging.log4j.Logger; import net.minecraft.realms.RealmsScreen; public class RealmsMainScreen extends RealmsScreen { private static final Logger LOGGER; private static final ResourceLocation ON_ICON_LOCATION; private static final ResourceLocation OFF_ICON_LOCATION; private static final ResourceLocation EXPIRED_ICON_LOCATION; private static final ResourceLocation EXPIRES_SOON_ICON_LOCATION; private static final ResourceLocation LEAVE_ICON_LOCATION; private static final ResourceLocation INVITATION_ICONS_LOCATION; private static final ResourceLocation INVITE_ICON_LOCATION; private static final ResourceLocation WORLDICON_LOCATION; private static final ResourceLocation LOGO_LOCATION; private static final ResourceLocation CONFIGURE_LOCATION; private static final ResourceLocation QUESTIONMARK_LOCATION; private static final ResourceLocation NEWS_LOCATION; private static final ResourceLocation POPUP_LOCATION; private static final ResourceLocation DARKEN_LOCATION; private static final ResourceLocation CROSS_ICON_LOCATION; private static final ResourceLocation TRIAL_ICON_LOCATION; private static final ResourceLocation BUTTON_LOCATION; private static List teaserImages; private static final RealmsDataFetcher REALMS_DATA_FETCHER; private static boolean overrideConfigure; private static int lastScrollYPosition; private static volatile boolean hasParentalConsent; private static volatile boolean checkedParentalConsent; private static volatile boolean checkedClientCompatability; private static Screen realmsGenericErrorScreen; private static boolean regionsPinged; private final RateLimiter inviteNarrationLimiter; private boolean dontSetConnectedToRealms; private final Screen lastScreen; private volatile RealmSelectionList realmSelectionList; private long selectedServerId; private Button playButton; private Button backButton; private Button renewButton; private Button configureButton; private Button leaveButton; private List toolTip; private List realmsServers; private volatile int numberOfPendingInvites; private int animTick; private boolean hasFetchedServers; private boolean popupOpenedByUser; private boolean justClosedPopup; private volatile boolean trialsAvailable; private volatile boolean createdTrial; private volatile boolean showingPopup; private volatile boolean hasUnreadNews; private volatile String newsLink; private int carouselIndex; private int carouselTick; private boolean hasSwitchedCarouselImage; private List keyCombos; private int clicks; private ReentrantLock connectLock; private HoveredElement hoveredElement; private Button showPopupButton; private Button pendingInvitesButton; private Button newsButton; private Button createTrialButton; private Button buyARealmButton; private Button closeButton; public RealmsMainScreen(final Screen dqs) { this.selectedServerId = -1L; this.realmsServers = Lists.newArrayList(); this.connectLock = new ReentrantLock(); this.lastScreen = dqs; this.inviteNarrationLimiter = RateLimiter.create(0.01666666753590107); } private boolean shouldShowMessageInList() { if (!hasParentalConsent() || !this.hasFetchedServers) { return false; } if (this.trialsAvailable && !this.createdTrial) { return true; } for (final RealmsServer dip3 : this.realmsServers) { if (dip3.ownerUUID.equals(this.minecraft.getUser().getUuid())) { return false; } } return true; } public boolean shouldShowPopup() { return hasParentalConsent() && this.hasFetchedServers && (this.popupOpenedByUser || (this.trialsAvailable && !this.createdTrial && this.realmsServers.isEmpty()) || this.realmsServers.isEmpty()); } public void init() { this.keyCombos = Lists.newArrayList(new KeyCombo(new char[] { '3', '2', '1', '4', '5', '6' }, () -> RealmsMainScreen.overrideConfigure = !RealmsMainScreen.overrideConfigure), new KeyCombo(new char[] { '9', '8', '7', '1', '2', '3' }, () -> { if (RealmsClient.currentEnvironment == RealmsClient.Environment.STAGE) { this.switchToProd(); } else { this.switchToStage(); } return; }), new KeyCombo(new char[] { '9', '8', '7', '4', '5', '6' }, () -> { if (RealmsClient.currentEnvironment == RealmsClient.Environment.LOCAL) { this.switchToProd(); } else { this.switchToLocal(); } return; })); if (RealmsMainScreen.realmsGenericErrorScreen != null) { this.minecraft.setScreen(RealmsMainScreen.realmsGenericErrorScreen); return; } this.connectLock = new ReentrantLock(); if (RealmsMainScreen.checkedClientCompatability && !hasParentalConsent()) { this.checkParentalConsent(); } this.checkClientCompatability(); this.checkUnreadNews(); if (!this.dontSetConnectedToRealms) { this.minecraft.setConnectedToRealms(false); } this.minecraft.keyboardHandler.setSendRepeatsToGui(true); if (hasParentalConsent()) { RealmsMainScreen.REALMS_DATA_FETCHER.forceUpdate(); } this.showingPopup = false; if (hasParentalConsent() && this.hasFetchedServers) { this.addButtons(); } this.realmSelectionList = new RealmSelectionList(); if (RealmsMainScreen.lastScrollYPosition != -1) { this.realmSelectionList.setScrollAmount(RealmsMainScreen.lastScrollYPosition); } this.addWidget(this.realmSelectionList); this.magicalSpecialHackyFocus(this.realmSelectionList); } private static boolean hasParentalConsent() { return RealmsMainScreen.checkedParentalConsent && RealmsMainScreen.hasParentalConsent; } public void addButtons() { this.configureButton = this.