Something went wrong. Try again.
The Minecraft: Java Edition decompiled source code.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179package com.mojang.realmsclient.gui;
import com.mojang.realmsclient.RealmsMainScreen;import com.mojang.realmsclient.dto.RealmsServer;import com.mojang.realmsclient.dto.RealmsSlot;import com.mojang.realmsclient.util.RealmsTextureManager;import net.minecraft.client.Minecraft;import net.minecraft.client.gui.Font;import net.minecraft.client.gui.GuiGraphics;import net.minecraft.client.gui.components.Button;import net.minecraft.client.gui.components.Tooltip;import net.minecraft.client.renderer.RenderPipelines;import net.minecraft.network.chat.CommonComponents;import net.minecraft.network.chat.Component;import net.minecraft.network.chat.MutableComponent;import net.minecraft.resources.Identifier;import net.minecraft.util.ARGB;import org.jspecify.annotations.Nullable;
public class RealmsWorldSlotButton extends Button { private static final Identifier SLOT_FRAME_SPRITE = Identifier.withDefaultNamespace("widget/slot_frame"); public static final Identifier EMPTY_SLOT_LOCATION = Identifier.withDefaultNamespace("textures/gui/realms/empty_frame.png"); public static final Identifier DEFAULT_WORLD_SLOT_1 = Identifier.withDefaultNamespace("textures/gui/title/background/panorama_0.png"); public static final Identifier DEFAULT_WORLD_SLOT_2 = Identifier.withDefaultNamespace("textures/gui/title/background/panorama_2.png"); public static final Identifier DEFAULT_WORLD_SLOT_3 = Identifier.withDefaultNamespace("textures/gui/title/background/panorama_3.png"); private static final Component SWITCH_TO_MINIGAME_SLOT_TOOLTIP = Component.translatable("mco.configure.world.slot.tooltip.minigame"); private static final Component SWITCH_TO_WORLD_SLOT_TOOLTIP = Component.translatable("mco.configure.world.slot.tooltip"); static final Component MINIGAME = Component.translatable("mco.worldSlot.minigame"); private static final int WORLD_NAME_MAX_WIDTH = 64; private static final String DOTS = "..."; private final int slotIndex; private RealmsWorldSlotButton.State state;
public RealmsWorldSlotButton(int i, int j, int k, int l, int m, RealmsServer realmsServer, Button.OnPress onPress) { super(i, j, k, l, CommonComponents.EMPTY, onPress, DEFAULT_NARRATION); this.slotIndex = m; this.state = this.setServerData(realmsServer); }
public RealmsWorldSlotButton.State getState() { return this.state; }
public RealmsWorldSlotButton.State setServerData(RealmsServer realmsServer) { this.state = new RealmsWorldSlotButton.State(realmsServer, this.slotIndex); this.setTooltipAndNarration(this.state, realmsServer.minigameName); return this.state; }
private void setTooltipAndNarration(RealmsWorldSlotButton.State state, @Nullable String string) { Component component = switch (statex.action) { case SWITCH_SLOT -> statex.minigame ? SWITCH_TO_MINIGAME_SLOT_TOOLTIP : SWITCH_TO_WORLD_SLOT_TOOLTIP; default -> null; }; if (component != null) { this.setTooltip(Tooltip.create(component)); }
MutableComponent mutableComponent = Component.literal(statex.slotName); if (statex.minigame && string != null) { mutableComponent = mutableComponent.append(CommonComponents.SPACE).append(string); }
this.setMessage(mutableComponent); }
static RealmsWorldSlotButton.Action getAction(boolean bl, boolean bl1, boolean bl2) { return bl || bl1 && bl2 ? RealmsWorldSlotButton.Action.NOTHING : RealmsWorldSlotButton.Action.SWITCH_SLOT; }
@Override public boolean isActive() { return this.state.action != RealmsWorldSlotButton.Action.NOTHING && super.isActive(); }
@Override public void renderContents(GuiGraphics guiGraphics, int l, int m, float f) { int i = this.getX(); int j = this.getY(); boolean bl = this.isHoveredOrFocused(); Identifier identifier; if (this.state.minigame) { identifier = RealmsTextureManager.worldTemplate(String.valueOf(this.state.imageId), this.state.image); } else if (this.state.empty) { identifier = EMPTY_SLOT_LOCATION; } else if (this.state.image != null && this.state.imageId != -1L) { identifier = RealmsTextureManager.worldTemplate(String.valueOf(this.state.imageId), this.state.image); } else if (this.slotIndex == 1) { identifier = DEFAULT_WORLD_SLOT_1; } else if (this.slotIndex == 2) { identifier = DEFAULT_WORLD_SLOT_2; } else if (this.slotIndex == 3) { identifier = DEFAULT_WORLD_SLOT_3; } else { identifier = EMPTY_SLOT_LOCATION; }
int k = -1; if (!this.state.activeSlot) { k = ARGB.colorFromFloat(1.0F, 0.56F, 0.56F, 0.56F); }
guiGraphics.blit(RenderPipelines.GUI_TEXTURED, identifier, i + 1, j + 1, 0.0F, 0.0F, this.width - 2, this.height - 2, 74, 74, 74, 74, k); if (bl && this.state.action != RealmsWorldSlotButton.Action.NOTHING) { guiGraphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_FRAME_SPRITE, i, j, this.width, this.height); } else if (this.state.activeSlot) { guiGraphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_FRAME_SPRITE, i, j, this.width, this.height, ARGB.colorFromFloat(1.0F, 0.8F, 0.8F, 0.8F)); } else { guiGraphics.blitSprite(RenderPipelines.GUI_TEXTURED, SLOT_FRAME_SPRITE, i, j, this.width, this.height, ARGB.colorFromFloat(1.0F, 0.56F, 0.56F, 0.56F)); }
if (this.state.hardcore) { guiGraphics.blitSprite(RenderPipelines.GUI_TEXTURED, RealmsMainScreen.HARDCORE_MODE_SPRITE, i + 3, j + 4, 9, 8); }
Font font = Minecraft.getInstance().font; String string = this.state.slotName; if (font.width(string) > 64) { string = font.plainSubstrByWidth(string, 64 - font.width("...")) + "..."; }
guiGraphics.drawCenteredString(font, string, i + this.width / 2, j + this.height - 14, -1); if (this.state.activeSlot) { guiGraphics.drawCenteredString( font, RealmsMainScreen.getVersionComponent(this.state.slotVersion, this.state.compatibility.isCompatible()), i + this.width / 2, j + this.height + 2, -1 ); } }
public static enum Action { NOTHING, SWITCH_SLOT; }
public static class State { final String slotName; final String slotVersion; final RealmsServer.Compatibility compatibility; final long imageId; @Nullable final String image; public final boolean empty; public final boolean minigame; public final RealmsWorldSlotButton.Action action; public final boolean hardcore; public final boolean activeSlot;
public State(RealmsServer realmsServer, int i) { this.minigame = i == 4; if (this.minigame) { this.slotName = RealmsWorldSlotButton.MINIGAME.getString(); this.imageId = (long)realmsServer.minigameId; this.image = realmsServer.minigameImage; this.empty = realmsServer.minigameId == -1; this.slotVersion = ""; this.compatibility = RealmsServer.Compatibility.UNVERIFIABLE; this.hardcore = false; this.activeSlot = realmsServer.isMinigameActive(); } else { RealmsSlot realmsSlot = realmsServer.slots.get(i); this.slotName = realmsSlot.options.getSlotName(i); this.imageId = realmsSlot.options.templateId; this.image = realmsSlot.options.templateImage; this.empty = realmsSlot.options.empty; this.slotVersion = realmsSlot.options.version; this.compatibility = realmsSlot.options.compatibility; this.hardcore = realmsSlot.isHardcore(); this.activeSlot = realmsServer.activeSlot == i && !realmsServer.isMinigameActive(); }
this.action = RealmsWorldSlotButton.getAction(this.activeSlot, this.empty, realmsServer.expired); } }}