Skip to content
This repository was archived by the owner on Apr 18, 2020. It is now read-only.

Sample Code (0.0.9)

권세인 edited this page Nov 23, 2019 · 1 revision

Sample Code

v0.0.9, No action required to launch forge.

Example

Form1.cs in CmlLibSample project
check 162 ~ 213 line. It's same

    // ENTRY POINT
    static void Main(string[] args)
    {
        var p = new Program();
        p.Start("1.7.10-Forge10.13.4.1614-1.7.10"); // start forge

        Console.ReadLine();
    }

    private void Start(string startVersion)
    {
        Minecraft.init(Environment.GetEnvironmentVariable("APPDATA") + "\\.minecraft"); // Initialize

        MProfileInfo[] versions = MProfileInfo.GetProfiles(); // Get MProfileInfo[]
        MProfile profile = MProfile.GetProfile(versions, startVersion)

        DownloadGame(profile);

        MLaunchOption option = new MLaunchOption() // set options
        {
            StartProfile = profile,
            JavaPath = "java.exe", // javapath
            MaximumRamMb = 4096, // maxram
            Session = MSession.GetOfflineSession("tester123") // test session
        };

        MLaunch launch = new MLaunch(option);
        launch.GetProcess().Start(); // launch
    }

    private void DownloadGame(MProfile profile, bool downloadResource = true) // download game files
    {
        MDownloader downloader = new MDownloader(profile);
        downloader.ChangeFile += Downloader_ChangeFile;
        downloader.ChangeProgress += Downloader_ChangeProgress;
        downloader.DownloadAll(downloadResource);
    }

    private void Downloader_ChangeProgress(object sender, System.ComponentModel.ProgressChangedEventArgs e)
    {
        Console.WriteLine(e.ProgressPercentage);
    }

    private void Downloader_ChangeFile(DownloadFileChangedEventArgs e)
    {
        Console.WriteLine("Now Downloading : {0} - {1} ({2}/{3})" , e.FileKind, e.FileName, e.CurrentValue, e.MaxValue);
    }
Clone this wiki locally