trurwsuieghfdskg

This commit is contained in:
2025-06-08 00:02:04 +09:00
commit 56c8ad5bc2
14172 changed files with 1139672 additions and 0 deletions

View File

@@ -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 p_120653_, Component p_120654_, Component p_120655_) {
super(p_120654_);
this.parent = p_120653_;
this.reason = p_120655_;
}
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 p_282959_, int p_120658_, int p_120659_, float p_120660_) {
this.renderBackground(p_282959_);
p_282959_.drawCenteredString(this.font, this.title, this.width / 2, this.height / 2 - this.textHeight / 2 - 9 * 2, 11184810);
this.message.renderCentered(p_282959_, this.width / 2, this.height / 2 - this.textHeight / 2);
super.render(p_282959_, p_120658_, p_120659_, p_120660_);
}
}

View File

@@ -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 p_120693_) {
this.onlineScreen = p_120693_;
}
public void connect(final RealmsServer p_175032_, ServerAddress p_175033_) {
final Minecraft minecraft = Minecraft.getInstance();
minecraft.setConnectedToRealms(true);
minecraft.prepareForMultiplayer();
minecraft.getNarrator().sayNow(Component.translatable("mco.connect.success"));
final String s = p_175033_.getHost();
final int i = p_175033_.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, p_175032_.toServerData(s), RealmsConnect.this.onlineScreen, false, (Duration)null, (p_120726_) -> {
});
if (p_175032_.worldType == RealmsServer.WorldType.MINIGAME) {
clienthandshakepacketlistenerimpl.setMinigameName(p_175032_.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(p_175032_));
minecraft.quickPlayLog().setWorldData(QuickPlayLog.Type.REALMS, String.valueOf(p_175032_.id), p_175032_.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();
}
}
}
}

View File

@@ -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 p_120736_, int p_120737_, int p_120738_, int p_120739_) {
this.text = p_120736_;
this.x = p_120737_;
this.y = p_120738_;
this.color = p_120739_;
}
public void render(GuiGraphics p_281597_, int p_282874_, int p_281694_, float p_282363_) {
p_281597_.drawCenteredString(Minecraft.getInstance().font, this.text, this.x, this.y, this.color);
}
public Component getText() {
return this.text;
}
}

View File

@@ -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 p_120745_, int p_120746_, int p_120747_, int p_120748_, int p_120749_) {
super(Minecraft.getInstance(), p_120745_, p_120746_, p_120747_, p_120748_, p_120749_);
}
public void setSelectedItem(int p_120768_) {
if (p_120768_ == -1) {
this.setSelected((E)null);
} else if (super.getItemCount() != 0) {
this.setSelected(this.getEntry(p_120768_));
}
}
public void selectItem(int p_120750_) {
this.setSelectedItem(p_120750_);
}
public void itemClicked(int p_120751_, int p_120752_, double p_120753_, double p_120754_, int p_120755_, int p_275741_) {
}
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> p_120759_) {
super.replaceEntries(p_120759_);
}
public int getItemCount() {
return super.getItemCount();
}
public int getRowTop(int p_120766_) {
return super.getRowTop(p_120766_);
}
public int getRowLeft() {
return super.getRowLeft();
}
public int addEntry(E p_120757_) {
return super.addEntry(p_120757_);
}
public void clear() {
this.clearEntries();
}
}

View File

@@ -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 p_175072_) {
super(p_175072_);
}
protected static int row(int p_120775_) {
return 40 + p_120775_ * 13;
}
protected RealmsLabel addLabel(RealmsLabel p_175074_) {
this.labels.add(p_175074_);
return this.addRenderableOnly(p_175074_);
}
public Component createLabelNarration() {
return CommonComponents.joinLines(this.labels.stream().map(RealmsLabel::getText).collect(Collectors.toList()));
}
}

View File

@@ -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 p_120788_) {
this.permitsPerSecond = 1000.0F / (float)p_120788_.toMillis();
}
public void narrate(GameNarrator p_240528_, Component p_240604_) {
RepeatedNarrator.Params repeatednarrator$params = this.params.updateAndGet((p_175080_) -> {
return p_175080_ != null && p_240604_.equals(p_175080_.narration) ? p_175080_ : new RepeatedNarrator.Params(p_240604_, RateLimiter.create((double)this.permitsPerSecond));
});
if (repeatednarrator$params.rateLimiter.tryAcquire(1)) {
p_240528_.sayNow(p_240604_);
}
}
@OnlyIn(Dist.CLIENT)
static class Params {
final Component narration;
final RateLimiter rateLimiter;
Params(Component p_175082_, RateLimiter p_175083_) {
this.narration = p_175082_;
this.rateLimiter = p_175083_;
}
}
}

View File

@@ -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;