我的世界没有开始

时间:2016-01-07 16:05:36

标签: c# minecraft

我在一个发射器我的世界的项目,但没有使用Java!只有C#。

我有这段代码,但不知道出了什么问题,只是java打开然后关闭。

public void RunMinecraft()
    {
        List<string> j_args = new List<string>();
        List<string> libraries = new List<string>();

        args = "";

        int x = Convert.ToInt32(numericUpDown1.Value);
        j_args.Add("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump");
        j_args.Add("-Xmx" + x + "G");
        j_args.Add("-Djava.library.path=" + Application.StartupPath + "\\data\\natives");
        j_args.Add("net.minecraft.client.main.Main");
        string lib = Application.StartupPath + "\\data\\libraries\\{0}";
        string app = Application.StartupPath;
        string game = Application.StartupPath + "\\data\\game";
        string assets = Application.StartupPath + "\\data\\assets";

        #region LIBRARIES
        libraries.Add(format2(lib, "oshi-core-1.1.jar"));
        libraries.Add(format2(lib, "jna-3.4.0.jar"));
        libraries.Add(format2(lib, "platform-3.4.0.jar"));
        libraries.Add(format2(lib, "icu4j-core-mojang-51.2.jar"));
        libraries.Add(format2(lib, "jopt-simple-4.6.jar"));
        libraries.Add(format2(lib, "codecjorbis-20101023.jar"));
        libraries.Add(format2(lib, "codecwav-20101023.jar"));
        libraries.Add(format2(lib, "libraryjavasound-20101123.jar"));
        libraries.Add(format2(lib, "librarylwjglopenal-20100824.jar"));
        libraries.Add(format2(lib, "soundsystem-20120107.jar"));
        libraries.Add(format2(lib, "netty-all-4.0.23.Final.jar"));
        libraries.Add(format2(lib, "guava-17.0.jar"));
        libraries.Add(format2(lib, "commons-lang3-3.3.2.jar"));
        libraries.Add(format2(lib, "commons-io-2.4.jar"));
        libraries.Add(format2(lib, "commons-codec-1.9.jar"));
        libraries.Add(format2(lib, "jinput-2.0.5.jar"));
        libraries.Add(format2(lib, "jutils-1.0.0.jar"));
        libraries.Add(format2(lib, "gson-2.2.4.jar"));
        libraries.Add(format2(lib, "authlib-1.5.21.jar"));
        libraries.Add(format2(lib, "realms-1.7.48.jar"));
        libraries.Add(format2(lib, "httpcore-4.3.2.jar"));
        libraries.Add(format2(lib, "log4j-api-2.0-beta9.jar"));
        libraries.Add(format2(lib, "log4j-core-2.0-beta9.jar"));
        libraries.Add(format3(lib, "1.8.6.jar"));
        #endregion

        var librariesSTR = "";

        var enum0 = libraries.GetEnumerator();
        while (enum0.MoveNext())
        {
            librariesSTR += enum0.Current;
        }

        j_args.Add("-cp " + librariesSTR);
        j_args.Add("--username " + username.Text);
        j_args.Add("--accessToken " + accesstoken.Text);
        j_args.Add("--userProperties {}");
        j_args.Add("--version 1.8.6");
        j_args.Add("--gameDir " + game);

        var argsSTR = "";
        var enum1 = j_args.GetEnumerator();
        while (enum1.MoveNext())
        {
            argsSTR += enum1.Current + " ";
        }

        ProcessStartInfo info = new ProcessStartInfo();
        info.FileName = @"C:\Program Files\Java\jre7\bin\java.exe";
        info.Arguments = args;

        info.UseShellExecute = false;
        info.RedirectStandardOutput = true;
        info.RedirectStandardError = true;

        Process p = new Process();
        p.StartInfo = info;
        p.OutputDataReceived += P_OutputDataReceived;
        info.CreateNoWindow = true;

        p.Start();
        p.BeginOutputReadLine();

        // Clipboard.SetText(argsSTR);
    }

    private string format3(string a, string b)
    {
        return string.Format(a, b);
    }

    #region format2
    private string format2(string a, string b)
    {
        return string.Format(a, b) + ";";
    }
    #endregion

我使用format2函数使其正确格式化所有库。例如:

libraries.Add("unnamed_lib1.jar"); libraries.Add ("unnamed_lib2.jar");

结果将如下所示:

args = "unnamed_lib1.jar;unnamed_lib2.jar;";

功能格式3(字符串a,字符串b);是完成游戏的JAR文件的事件。 示例:“1.8.9.jar”没有';'最后

  

抱歉拼写错误,因为我说英语不多。我正在使用Google翻译来帮助我处理文本。

  我正在使用1.8.6版本的minecraft开始

1 个答案:

答案 0 :(得分:2)

-cp(类路径)参数放在net.minecraft.client.main.Main之前,否则它们将被视为应用程序(Main类)的参数,而不是javaw可执行文件。< / p>

它会是这样的(我只写了一些你的论点,ommited java.exe和其他东西):

j_args.Add("-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump");
j_args.Add("-Xmx" + x + "G");
j_args.Add("-Djava.library.path=" + Application.StartupPath + "\\data\\natives");
j_args.Add("-cp " + librariesSTR);
j_args.Add("net.minecraft.client.main.Main");
j_args.Add("--username " + username.Text);
j_args.Add("--accessToken " + accesstoken.Text);
j_args.Add("--userProperties {}");
j_args.Add("--version 1.8.6");
j_args.Add("--gameDir " + game);