Simplify code and improved mod compatibility

This commit is contained in:
FlorianMichael 2024-03-22 10:51:10 +01:00
parent 945a77a713
commit 6e56ba6eec
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 8 additions and 8 deletions

View File

@ -148,17 +148,17 @@ public class ClientsideFixes {
/**
* Replaces the default port when parsing a server address if the default port should be replaced
*
* @param info The server info
* @param address The original address of the server
* @param version The protocol version
* @return The server address with the replaced default port
*/
public static ServerAddress replaceDefaultPort(final ServerInfo info, final ProtocolVersion version) {
public static ServerAddress replaceDefaultPort(final String address, final ProtocolVersion version) {
// If the default port for this entry should be replaced, check if the address already contains a port
// We can't just replace vanilla's default port because a bedrock server might be running on the same port
if (BedrockSettings.global().replaceDefaultPort.getValue() && Objects.equals(version, BedrockProtocolVersion.bedrockLatest) && !info.address.contains(":")) {
return ServerAddress.parse(info.address + ":" + 19132);
if (BedrockSettings.global().replaceDefaultPort.getValue() && Objects.equals(version, BedrockProtocolVersion.bedrockLatest) && !address.contains(":")) {
return ServerAddress.parse(address + ":" + 19132);
} else {
return ServerAddress.parse(info.address);
return ServerAddress.parse(address);
}
}

View File

@ -60,10 +60,10 @@ public abstract class MixinMultiplayerScreen extends Screen {
private ServerAddress replaceDefaultPort(String address, @Local(argsOnly = true) ServerInfo entry) {
if (((IServerInfo) entry).viaFabricPlus$passedDirectConnectScreen()) {
// If the user has already passed the direct connect screen, we use the target version
return ClientsideFixes.replaceDefaultPort(entry, ProtocolTranslator.getTargetVersion());
return ClientsideFixes.replaceDefaultPort(address, ProtocolTranslator.getTargetVersion());
} else {
// Otherwise the forced version is used
return ClientsideFixes.replaceDefaultPort(entry, ((IServerInfo) entry).viaFabricPlus$forcedVersion());
return ClientsideFixes.replaceDefaultPort(address, ((IServerInfo) entry).viaFabricPlus$forcedVersion());
}
}

View File

@ -41,7 +41,7 @@ public abstract class MixinMultiplayerServerListPinger {
@Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ServerAddress;parse(Ljava/lang/String;)Lnet/minecraft/client/network/ServerAddress;"))
private ServerAddress replaceDefaultPort(String address, @Local(argsOnly = true) ServerInfo entry) {
// Replace port when pinging the server and the forced version is set
return ClientsideFixes.replaceDefaultPort(entry, ((IServerInfo) entry).viaFabricPlus$forcedVersion());
return ClientsideFixes.replaceDefaultPort(address, ((IServerInfo) entry).viaFabricPlus$forcedVersion());
}
@Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/util/profiler/PerformanceLog;)Lnet/minecraft/network/ClientConnection;"))