Skip to content

Commit

Permalink
new features and improvements
Browse files Browse the repository at this point in the history
force Process output encoding
add support for new 1.20+ commands, see [Link](https://minecraft.wiki/w/Quick_Play)
  • Loading branch information
laolarou726 committed Nov 17, 2024
1 parent c1e4d15 commit 47cd3e9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 6 additions & 0 deletions ProjBobcat/ProjBobcat/Class/Model/LaunchSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public class GameArguments
public required GcType GcType { get; init; }
public IReadOnlyList<string>? AdditionalJvmArguments { get; set; }
public ServerSettings? ServerSettings { get; set; }

/// <summary>
/// Join world name (Starting from 1.20, single player only)
/// </summary>
public string? JoinWorldName { get; set; }

public string? AdvanceArguments { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using ProjBobcat.Class.Model;
using ProjBobcat.Class.Model.Auth;
using ProjBobcat.Class.Model.JsonContexts;
using ProjBobcat.Class.Model.Version;
using ProjBobcat.Exceptions;
using ProjBobcat.Interface;

Expand Down Expand Up @@ -375,16 +376,34 @@ public IEnumerable<string> ParseAdditionalArguments()

var serverSettings = this.LaunchSettings.GameArguments.ServerSettings ??
this.LaunchSettings.FallBackGameArguments?.ServerSettings;
var joinWorldName = LaunchSettings.GameArguments.JoinWorldName ??
LaunchSettings.FallBackGameArguments?.JoinWorldName;

// Starting from 1.20, we need to use the new command line arguments
var newFormatVersionLimit = new ComparableVersion("1.20");
var gameVersion = new ComparableVersion(VersionInfo.GameBaseVersion);
var shouldUseNewCommand = gameVersion >= newFormatVersionLimit;

if (serverSettings != null && !serverSettings.IsDefault())
{
if (string.IsNullOrEmpty(serverSettings.Address)) yield break;

yield return "--server";
yield return serverSettings.Address;
if (shouldUseNewCommand)
{
yield return $"--quickPlayMultiplayer \"{serverSettings.Address}:{serverSettings.Port}\"";
}
else
{
yield return "--server";
yield return serverSettings.Address;

yield return "--port";
yield return serverSettings.Port.ToString();
yield return "--port";
yield return serverSettings.Port.ToString();
}
}
else if (!string.IsNullOrEmpty(joinWorldName) && shouldUseNewCommand)
{
yield return $"--quickPlaySingleplayer \"{joinWorldName}\"";
}

if (!string.IsNullOrEmpty(this.LaunchSettings.GameArguments.AdvanceArguments))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Win32;
using Windows.Win32.Foundation;
Expand Down Expand Up @@ -280,7 +281,9 @@ public override async Task<LaunchResult> LaunchTaskAsync(LaunchSettings settings
UseShellExecute = false,
WorkingDirectory = rootPath,
RedirectStandardError = true,
RedirectStandardOutput = true
RedirectStandardOutput = true,
StandardOutputEncoding = Encoding.UTF8,
StandardErrorEncoding = Encoding.UTF8
};

#region log4j 缓解措施
Expand Down

0 comments on commit 47cd3e9

Please sign in to comment.