|
| 1 | +# NeoForgeInstaller |
| 2 | + |
| 3 | +NeoForgeInstaller provides functionality to download and install NeoForge versions for Minecraft. |
| 4 | + |
| 5 | +## Initializing the Installer |
| 6 | + |
| 7 | +```csharp |
| 8 | +var path = new MinecraftPath(); |
| 9 | +var launcher = new MinecraftLauncher(path); |
| 10 | +var neoForgeInstaller = new NeoForgeInstaller(launcher); |
| 11 | +``` |
| 12 | + |
| 13 | +Optionally, you can configure the HttpClient used to access the NeoForge website by using `new NeoForgeInstaller(launcher, new HttpClient())`. |
| 14 | + |
| 15 | +## Listing Available Versions |
| 16 | + |
| 17 | +```csharp |
| 18 | +var versions = await neoForgeInstaller.GetForgeVersions("1.21.10"); |
| 19 | +foreach (var version in versions) |
| 20 | +{ |
| 21 | + Console.WriteLine(); |
| 22 | + Console.WriteLine("MinecraftVersion: " + version.MinecraftVersion); |
| 23 | + Console.WriteLine("VersionName: " + version.VersionName); |
| 24 | + |
| 25 | + var installerFile = version.GetInstallerFile(); |
| 26 | + if (installerFile != null) |
| 27 | + { |
| 28 | + Console.WriteLine("DirectUrl: " + installerFile.DirectUrl); |
| 29 | + } |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +This retrieves all available NeoForge versions that can be installed for the specified Minecraft version. |
| 34 | + |
| 35 | +## Installation |
| 36 | + |
| 37 | +### Installing the Best Version |
| 38 | + |
| 39 | +```csharp |
| 40 | +var installedVersionName = await neoForgeInstaller.Install("1.21.10", new NeoForgeInstallOptions()); |
| 41 | +``` |
| 42 | + |
| 43 | +This finds and installs the most appropriate NeoForge version available for Minecraft 1.21.10. |
| 44 | + |
| 45 | +The appropriate version is selected using the following priority rules: |
| 46 | + |
| 47 | +1. First version with the 'Recommended Version' flag |
| 48 | +2. First version with the 'Latest Version' flag |
| 49 | +3. The topmost version in the version list |
| 50 | + |
| 51 | +### Installing a Specific Version |
| 52 | + |
| 53 | +```csharp |
| 54 | +var installedVersionName = await neoForgeInstaller.Install("1.21.10", "21.10.56-beta", new NeoForgeInstallOptions()); |
| 55 | +``` |
| 56 | + |
| 57 | +This installs NeoForge version 21.10.56-beta for Minecraft 1.21.10. |
| 58 | + |
| 59 | +### Installing the Latest Version |
| 60 | + |
| 61 | +```csharp |
| 62 | +var versions = await neoForgeInstaller.GetForgeVersions("1.21.10"); |
| 63 | +var latestVersion = versions.First(); |
| 64 | +var installedVersionName = await neoForgeInstaller.Install(latestVersion, new NeoForgeInstallOptions()); |
| 65 | +``` |
| 66 | + |
| 67 | +This finds and installs the latest NeoForge version available for Minecraft 1.21.10. |
| 68 | + |
| 69 | +## Installation Options |
| 70 | + |
| 71 | +To use features like installation progress display and cancellation, configure the appropriate values in `NeoForgeInstallOptions`. |
| 72 | + |
| 73 | +```csharp |
| 74 | +var installOptions = new NeoForgeInstallOptions |
| 75 | +{ |
| 76 | + FileProgress = new Progress<InstallerProgressChangedEventArgs>(e => |
| 77 | + Console.WriteLine($"[{e.EventType}][{e.ProgressedTasks}/{e.TotalTasks}] {e.Name}")), |
| 78 | + ByteProgress = new Progress<ByteProgress>(e => |
| 79 | + Console.WriteLine(e.ToRatio() * 100 + "%")), |
| 80 | + InstallerOutput = new Progress<string>(e => |
| 81 | + Console.WriteLine(e)), |
| 82 | + CancellationToken = CancellationToken.None, |
| 83 | + |
| 84 | + JavaPath = "java.exe", |
| 85 | + SkipIfAlreadyInstalled = true, |
| 86 | +}; |
| 87 | +var installedVersionName = await neoForgeInstaller.Install("1.21.10", installOptions); |
| 88 | +``` |
| 89 | + |
| 90 | +- **FileProgress** and **ByteProgress**: Report file download progress. See [Event Handling](../cmllib.core/getting-started/Handling-Events.md) for more details. |
| 91 | +- **InstallerOutput**: Reports logs output from the installer's console. |
| 92 | +- **CancellationToken**: Allows you to cancel the installation process. |
| 93 | +- **JavaPath**: Sets the path to the Java runtime used to execute the installer. The default value is `null`, which automatically determines the Java runtime path. |
| 94 | +- **SkipIfAlreadyInstalled**: When set to `true`, skips installation if the target version is already installed. The default value is `true`. |
| 95 | + |
| 96 | +## Important Note About Complete Installation |
| 97 | + |
| 98 | +`neoForgeInstaller.Install` does not fully install the NeoForge version. The version still needs additional files such as sound assets, Java runtime, and vanilla version files. Therefore, you should always call `launcher.InstallAsync` before launching the game. |
| 99 | + |
| 100 | +```csharp |
| 101 | +// Install NeoForge |
| 102 | +var versionName = await neoForgeInstaller.Install("1.21.10", new NeoForgeInstallOptions()); |
| 103 | + |
| 104 | +// Install remaining dependencies (sound assets, Java runtime, vanilla version) |
| 105 | +await launcher.InstallAsync(versionName); |
| 106 | + |
| 107 | +// Launch the game |
| 108 | +var process = await launcher.BuildProcessAsync(versionName, new MLaunchOption |
| 109 | +{ |
| 110 | + MaximumRamMb = 1024, |
| 111 | + Session = MSession.CreateOfflineSession("GamerVII"), |
| 112 | +}); |
| 113 | +process.Start(); |
| 114 | +``` |
0 commit comments