Initial Commit

This commit is contained in:
richard committed 2026-11-13 22:25:04 +01:00
1 parent 377b32db6e
commit 2d9a5eecba
14134 files changed
+1160982

No files matched your search

@@ -0,0 +1,51 @@
package net.minecraft.realms;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.MultiLineLabel;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class DisconnectedRealmsScreen extends RealmsScreen {
private final Component reason;
private MultiLineLabel message = MultiLineLabel.EMPTY;
private final Screen parent;
private int textHeight;
public DisconnectedRealmsScreen(Screen pParent, Component pTitle, Component pReason) {
super(pTitle);
this.parent = pParent;
this.reason = pReason;
}
public void init() {
Minecraft minecraft = Minecraft.getInstance();
minecraft.setConnectedToRealms(false);
minecraft.getDownloadedPackSource().clearServerPack();
this.message = MultiLineLabel.create(this.font, this.reason, this.width - 50);
this.textHeight = this.message.getLineCount() * 9;
this.addRenderableWidget(Button.builder(CommonComponents.GUI_BACK, (p_120663_) -> {
minecraft.setScreen(this.parent);
}).bounds(this.width / 2 - 100, this.height / 2 + this.textHeight / 2 + 9, 200, 20).build());
}
public Component getNarrationMessage() {
return Component.empty().append(this.title).append(": ").append(this.reason);
}
public void onClose() {
Minecraft.getInstance().setScreen(this.parent);
}
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
this.renderBackground(pGuiGraphics);
pGuiGraphics.drawCenteredString(this.font, this.title, this.width / 2, this.height / 2 - this.textHeight / 2 - 9 * 2, 11184810);
this.message.renderCentered(pGuiGraphics, this.width / 2, this.height / 2 - this.textHeight / 2);
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
}
}
@@ -0,0 +1,123 @@
package net.minecraft.realms;
import com.mojang.logging.LogUtils;
import com.mojang.realmsclient.dto.RealmsServer;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl;
import net.minecraft.client.multiplayer.chat.report.ReportEnvironment;
import net.minecraft.client.multiplayer.resolver.ServerAddress;
import net.minecraft.client.quickplay.QuickPlayLog;
import net.minecraft.network.Connection;
import net.minecraft.network.ConnectionProtocol;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
import net.minecraft.network.protocol.login.ServerboundHelloPacket;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.slf4j.Logger;
@OnlyIn(Dist.CLIENT)
public class RealmsConnect {
static final Logger LOGGER = LogUtils.getLogger();
final Screen onlineScreen;
volatile boolean aborted;
@Nullable
Connection connection;
public RealmsConnect(Screen pOnlineScreen) {
this.onlineScreen = pOnlineScreen;
}
public void connect(final RealmsServer pServer, ServerAddress pAddress) {
final Minecraft minecraft = Minecraft.getInstance();
minecraft.setConnectedToRealms(true);
minecraft.prepareForMultiplayer();
minecraft.getNarrator().sayNow(Component.translatable("mco.connect.success"));
final String s = pAddress.getHost();
final int i = pAddress.getPort();
(new Thread("Realms-connect-task") {
public void run() {
InetSocketAddress inetsocketaddress = null;
try {
inetsocketaddress = new InetSocketAddress(s, i);
if (RealmsConnect.this.aborted) {
return;
}
RealmsConnect.this.connection = Connection.connectToServer(inetsocketaddress, minecraft.options.useNativeTransport());
if (RealmsConnect.this.aborted) {
return;
}
ClientHandshakePacketListenerImpl clienthandshakepacketlistenerimpl = new ClientHandshakePacketListenerImpl(RealmsConnect.this.connection, minecraft, pServer.toServerData(s), RealmsConnect.this.onlineScreen, false, (Duration)null, (p_120726_) -> {
});
if (pServer.worldType == RealmsServer.WorldType.MINIGAME) {
clienthandshakepacketlistenerimpl.setMinigameName(pServer.minigameName);
}
RealmsConnect.this.connection.setListener(clienthandshakepacketlistenerimpl);
if (RealmsConnect.this.aborted) {
return;
}
RealmsConnect.this.connection.send(new ClientIntentionPacket(s, i, ConnectionProtocol.LOGIN));
if (RealmsConnect.this.aborted) {
return;
}
String s3 = minecraft.getUser().getName();
UUID uuid = minecraft.getUser().getProfileId();
RealmsConnect.this.connection.send(new ServerboundHelloPacket(s3, Optional.ofNullable(uuid)));
minecraft.updateReportEnvironment(ReportEnvironment.realm(pServer));
minecraft.quickPlayLog().setWorldData(QuickPlayLog.Type.REALMS, String.valueOf(pServer.id), pServer.name);
} catch (Exception exception) {
minecraft.getDownloadedPackSource().clearServerPack();
if (RealmsConnect.this.aborted) {
return;
}
RealmsConnect.LOGGER.error("Couldn't connect to world", (Throwable)exception);
String s1 = exception.toString();
if (inetsocketaddress != null) {
String s2 = inetsocketaddress + ":" + i;
s1 = s1.replaceAll(s2, "");
}
DisconnectedRealmsScreen disconnectedrealmsscreen = new DisconnectedRealmsScreen(RealmsConnect.this.onlineScreen, CommonComponents.CONNECT_FAILED, Component.translatable("disconnect.genericReason", s1));
minecraft.execute(() -> {
minecraft.setScreen(disconnectedrealmsscreen);
});
}
}
}).start();
}
public void abort() {
this.aborted = true;
if (this.connection != null && this.connection.isConnected()) {
this.connection.disconnect(Component.translatable("disconnect.genericReason"));
this.connection.handleDisconnection();
}
}
public void tick() {
if (this.connection != null) {
if (this.connection.isConnected()) {
this.connection.tick();
} else {
this.connection.handleDisconnection();
}
}
}
}
@@ -0,0 +1,31 @@
package net.minecraft.realms;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Renderable;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class RealmsLabel implements Renderable {
private final Component text;
private final int x;
private final int y;
private final int color;
public RealmsLabel(Component pText, int pX, int pY, int pColor) {
this.text = pText;
this.x = pX;
this.y = pY;
this.color = pColor;
}
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
pGuiGraphics.drawCenteredString(Minecraft.getInstance().font, this.text, this.x, this.y, this.color);
}
public Component getText() {
return this.text;
}
}
@@ -0,0 +1,66 @@
package net.minecraft.realms;
import java.util.Collection;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.ObjectSelectionList;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public abstract class RealmsObjectSelectionList<E extends ObjectSelectionList.Entry<E>> extends ObjectSelectionList<E> {
protected RealmsObjectSelectionList(int pWidth, int pHeight, int pY0, int pY1, int pItemHeight) {
super(Minecraft.getInstance(), pWidth, pHeight, pY0, pY1, pItemHeight);
}
public void setSelectedItem(int pIndex) {
if (pIndex == -1) {
this.setSelected((E)null);
} else if (super.getItemCount() != 0) {
this.setSelected(this.getEntry(pIndex));
}
}
public void selectItem(int pIndex) {
this.setSelectedItem(pIndex);
}
public void itemClicked(int p_120751_, int pIndex, double pMouseX, double pMouseY, int p_120755_, int pButton) {
}
public int getMaxPosition() {
return 0;
}
public int getScrollbarPosition() {
return this.getRowLeft() + this.getRowWidth();
}
public int getRowWidth() {
return (int)((double)this.width * 0.6D);
}
public void replaceEntries(Collection<E> pEntries) {
super.replaceEntries(pEntries);
}
public int getItemCount() {
return super.getItemCount();
}
public int getRowTop(int pIndex) {
return super.getRowTop(pIndex);
}
public int getRowLeft() {
return super.getRowLeft();
}
public int addEntry(E pEntry) {
return super.addEntry(pEntry);
}
public void clear() {
this.clearEntries();
}
}
@@ -0,0 +1,53 @@
package net.minecraft.realms;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.stream.Collectors;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public abstract class RealmsScreen extends Screen {
protected static final int TITLE_HEIGHT = 17;
protected static final int COMPONENT_HEIGHT = 20;
protected static final int EXPIRATION_NOTIFICATION_DAYS = 7;
protected static final long SIZE_LIMIT = 5368709120L;
public static final int COLOR_WHITE = 16777215;
public static final int COLOR_GRAY = 10526880;
protected static final int COLOR_DARK_GRAY = 5000268;
protected static final int COLOR_MEDIUM_GRAY = 7105644;
protected static final int COLOR_GREEN = 8388479;
protected static final int COLOR_DARK_GREEN = 6077788;
protected static final int COLOR_RED = 16711680;
protected static final int COLOR_RED_FADE = 15553363;
protected static final int COLOR_BLACK = -1073741824;
protected static final int COLOR_YELLOW = 13413468;
protected static final int COLOR_BRIGHT_YELLOW = -256;
protected static final int COLOR_LINK = 3368635;
protected static final int COLOR_LINK_HOVER = 7107012;
protected static final int COLOR_INFO = 8226750;
protected static final int COLOR_BUTTON_YELLOW = 16777120;
protected static final String UPDATE_BREAKS_ADVENTURE_URL = "https://www.minecraft.net/realms/adventure-maps-in-1-9";
protected static final int SKIN_FACE_SIZE = 8;
private final List<RealmsLabel> labels = Lists.newArrayList();
public RealmsScreen(Component pTitle) {
super(pTitle);
}
protected static int row(int pPosition) {
return 40 + pPosition * 13;
}
protected RealmsLabel addLabel(RealmsLabel pLabel) {
this.labels.add(pLabel);
return this.addRenderableOnly(pLabel);
}
public Component createLabelNarration() {
return CommonComponents.joinLines(this.labels.stream().map(RealmsLabel::getText).collect(Collectors.toList()));
}
}
@@ -0,0 +1,40 @@
package net.minecraft.realms;
import com.google.common.util.concurrent.RateLimiter;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicReference;
import net.minecraft.client.GameNarrator;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class RepeatedNarrator {
private final float permitsPerSecond;
private final AtomicReference<RepeatedNarrator.Params> params = new AtomicReference<>();
public RepeatedNarrator(Duration pDuration) {
this.permitsPerSecond = 1000.0F / (float)pDuration.toMillis();
}
public void narrate(GameNarrator pNarrator, Component pNarration) {
RepeatedNarrator.Params repeatednarrator$params = this.params.updateAndGet((p_175080_) -> {
return p_175080_ != null && pNarration.equals(p_175080_.narration) ? p_175080_ : new RepeatedNarrator.Params(pNarration, RateLimiter.create((double)this.permitsPerSecond));
});
if (repeatednarrator$params.rateLimiter.tryAcquire(1)) {
pNarrator.sayNow(pNarration);
}
}
@OnlyIn(Dist.CLIENT)
static class Params {
final Component narration;
final RateLimiter rateLimiter;
Params(Component pNarration, RateLimiter pRateLimiter) {
this.narration = pNarration;
this.rateLimiter = pRateLimiter;
}
}
}
@@ -0,0 +1,11 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@FieldsAreNonnullByDefault
@OnlyIn(Dist.CLIENT)
package net.minecraft.realms;
import javax.annotation.ParametersAreNonnullByDefault;
import net.minecraft.FieldsAreNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;