Skip to content

Commit

Permalink
Add PlayerPlatform#joinServer
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Dec 28, 2024
1 parent d300e7e commit ff1a97a
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/utils/api/utils.api
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public abstract interface class org/polyfrost/oneconfig/api/platform/v1/PlayerPl
public abstract fun getPlayerName ()Ljava/lang/String;
public abstract fun getServerBrand ()Ljava/lang/String;
public abstract fun inMultiplayer ()Z
public abstract fun joinServer (Lorg/polyfrost/oneconfig/api/platform/v1/PlayerPlatform$Server;)V
}

public class org/polyfrost/oneconfig/api/platform/v1/PlayerPlatform$Server {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

package org.polyfrost.oneconfig.api.platform.v1;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface PlayerPlatform {
Expand All @@ -45,6 +46,8 @@ public interface PlayerPlatform {
@Nullable
Server getCurrentServer();

void joinServer(@NotNull Server server);

class Server {
public final String ip, name;

Expand Down
2 changes: 1 addition & 1 deletion versions/mappings/fabric-1.17.1-1.16.5.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
com.mojang.blaze3d.platform.GlStateManager _glFramebufferTexture2D() framebufferTexture2D()
com.mojang.blaze3d.platform.GlStateManager _texImage2D() texImage2D()
com.mojang.blaze3d.platform.GlStateManager _texImage2D() texImage2D()
3 changes: 3 additions & 0 deletions versions/mappings/forge-1.16.5-1.12.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ net.minecraft.profiler.IProfiler net.minecraft.profiler.Profiler

net.minecraft.util.text.ITextComponent getUnformattedComponentText() getUnformattedText()

net.minecraft.client.gui.screen.MultiplayerScreen net.minecraft.client.gui.GuiMultiplayer
net.minecraft.client.gui.screen.ConnectingScreen net.minecraft.client.multiplayer.GuiConnecting

net.minecraftforge.client.event.ClientPlayerNetworkEvent getNetworkManager() getManager()
net.minecraftforge.client.event.ClientPlayerNetworkEvent net.minecraftforge.fml.common.network.FMLNetworkEvent
net.minecraftforge.client.event.ClientPlayerNetworkEvent$LoggedInEvent net.minecraftforge.fml.common.network.FMLNetworkEvent$ClientConnectedToServerEvent
Expand Down
3 changes: 3 additions & 0 deletions versions/mappings/forge-1.17.1-1.16.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ net.minecraft.client.Minecraft missTime leftClickCounter

net.minecraft.client.sounds.SoundEngine net.minecraft.client.audio.SoundEngine

net.minecraft.client.gui.screens.ConnectScreen net.minecraft.client.gui.screen.ConnectingScreen
net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen net.minecraft.client.gui.screen.MultiplayerScreen

net.minecraft.ChatFormatting net.minecraft.util.text.TextFormatting
net.minecraft.ChatFormatting stripFormatting() getTextWithoutFormattingCodes()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@

package org.polyfrost.oneconfig.api.platform.v1.internal;

//#if MC >= 1.17.1
//#if FORGE
//$$ import net.minecraft.client.multiplayer.resolver.ServerAddress;
//#else
//$$ import net.minecraft.client.network.ServerAddress;
//#endif
//#endif

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiMultiplayer;
import net.minecraft.client.multiplayer.GuiConnecting;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.util.Session;
import org.jetbrains.annotations.NotNull;
import org.polyfrost.oneconfig.api.platform.v1.Platform;
import org.polyfrost.oneconfig.api.platform.v1.PlayerPlatform;

public class PlayerPlatformImpl implements PlayerPlatform {
Expand Down Expand Up @@ -72,4 +84,46 @@ public Server getCurrentServer() {
old = d;
return cache = new Server(d.serverIP, d.serverName);
}

public void joinServer(@NotNull Server server) {
ServerData data = new ServerData(
server.name,
server.ip,
//#if MC >= 1.20.4
//#if FORGE
//$$ ServerData.Type.OTHER
//#else
//$$ ServerInfo.ServerType.OTHER
//#endif
//#else
false
//#endif
);

//#if MC >= 1.17.1
//$$ ServerAddress address = ServerAddress
//#if FORGE
//$$ .parseString(server.ip);
//#else
//$$ .parse(server.ip);
//#endif
//#if FORGE
//$$ ConnectScreen.startConnecting(
//$$ new JoinMultiplayerScreen(Platform.screen().current()),
//$$ Minecraft.getInstance(),
//#else
//$$ ConnectScreen.connect(
//$$ new MultiplayerScreen(Platform.screen().current()),
//$$ MinecraftClient.getInstance(),
//#endif
//$$ address,
//$$ data
//#if MC >= 1.20.4
//$$ , false
//#endif
//$$ );
//#else
Platform.screen().display(new GuiConnecting(new GuiMultiplayer(Platform.screen().current()), Minecraft.getMinecraft(), data));
//#endif
}
}

0 comments on commit ff1a97a

Please sign in to comment.