gpt4 book ai didi

java - 使用 Java 在 Mac 上启动 Minecraft

转载 作者:太空宇宙 更新时间:2023-11-04 07:49:39 26 4
gpt4 key购买 nike

我正在尝试制作一个java程序,它将使用我想要的任何用户名以离线模式启动minecraft,这样我就可以拥有像Notch和deadmau5这样的用户名,并且我正在使用此代码在mac和windows上启动它(当前在mac上测试):

public void startMacMinecraft(String username) throws IOException,
InterruptedException {
System.out.println(defaultDirectory());

String sysUser = System.getProperty("user.name");
String commandString = "java -cp "
+ defaultDirectory()
+ "/minecraft/bin/minecraft.jar:"
+ defaultDirectory()
+ "/minecraft/bin/lwjgl.jar:"
+ defaultDirectory()
+ "/minecraft/bin/lwjgl_util.jar:"
+ defaultDirectory()
+ "/minecraft/bin/jinput.jar: -Djava.library.path="
+ defaultDirectory()
+ "/minecraft/bin/natives -Xmx1024M -Xms512M net.minecraft.client.Minecraft '"
+ username + "'";
CommandLine command = CommandLine.parse(commandString);
DefaultExecutor executor = new DefaultExecutor();
int exitValue = executor.execute(command);
System.out.println(exitValue);

System.out.println("\nTry Two:\n");
String javaExe = System.getProperty("java.home") + "/bin/java";

}

public void startWinMinecraft(String username) throws IOException,
InterruptedException {
String sysUser = System.getProperty("user.name");
String commandString = "Java -Xms512m -Xmx1024m -cp \"%APPDATA%\\.minecraft\\bin\\*\" -Djava.library.path=\"%APPDATA%\\.minecraft\\bin\\natives net.minecraft.client.Minecraft \""
+ username + "\"";
CommandLine command = CommandLine.parse(commandString);
DefaultExecutor executor = new DefaultExecutor();
int exitValue = executor.execute(command);
System.out.println(exitValue);

}

private static String defaultDirectory() {
String OS = System.getProperty("os.name").toUpperCase();
if (OS.contains("WIN"))
return System.getenv("APPDATA");
else if (OS.contains("MAC"))
return System.getProperty("user.home") + "/Library/Application "
+ "Support";
else if (OS.contains("NUX"))
return System.getProperty("user.home");
return System.getProperty("user.dir");
}

我正在尝试改编这个applescript,我之前运行过它并从https://gaming.stackexchange.com/questions/46608/how-can-i-run-minecraft-in-offline-mode-on-os-x-and-still-have-my-name获得,我将粘贴在这里:

property user_name : "Player"

display dialog "Enter A User Name" default answer "" buttons {"Cancel", "Continue"} default button 2
set the user_name to text returned of the result

set UsrApp to (path to current user folder)
set UsrApp_unx to POSIX path of UsrApp

set MineScript to "java -cp " & UsrApp_unx & "Library/Application\\ Support/minecraft/bin/minecraft.jar:" & UsrApp_unx & "Library/Application\\ Support/minecraft/bin/lwjgl.jar:" & UsrApp_unx & "Library/Application\\ Support/minecraft/bin/lwjgl_util.jar:" & UsrApp_unx & "Library/Application\\ Support/minecraft/bin/jinput.jar: -Djava.library.path=" & UsrApp_unx & "Library/Application\\ Support/minecraft/bin/natives -Xmx1024M -Xms512M net.minecraft.client.Minecraft '" & user_name & "'"

do shell script MineScript

当我运行 applescript 时,它工作得很好,但是当我运行我的改编版本时,它给了我一个类未找到错误:

    Logging in as: Player
/Users/Connor/Library/Application Support
Exception in thread "main" java.lang.NoClassDefFoundError: Support/minecraft/bin/minecraft/jar:/Users/Connor/Library/Application
Caused by: java.lang.ClassNotFoundException: Support.minecraft.bin.minecraft.jar:.Users.Connor.Library.Application
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
at info.connorbp.GUIApp.LoginPanel.startMacMinecraft(LoginPanel.java:137)
at info.connorbp.GUIApp.LoginPanel$1.actionPerformed(LoginPanel.java:82)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6375)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6140)
at java.awt.Container.processEvent(Container.java:2083)
at java.awt.Component.dispatchEventImpl(Component.java:4737)
at java.awt.Container.dispatchEventImpl(Container.java:2141)
at java.awt.Component.dispatchEvent(Component.java:4565)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4280)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
at java.awt.Container.dispatchEventImpl(Container.java:2127)
at java.awt.Window.dispatchEventImpl(Window.java:2482)
at java.awt.Component.dispatchEvent(Component.java:4565)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:684)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:643)
at java.awt.EventQueue$1.run(EventQueue.java:641)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:657)
at java.awt.EventQueue$2.run(EventQueue.java:655)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:654)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

有谁知道我做错了什么或如何解决它?

编辑:

更奇怪的是,我进入了 applescript 区域的事件区域,找到了 applescript 正在运行的确切命令:

java -cp /Users/Connor/Library/Application\\ Support/minecraft/bin/minecraft.jar:/Users/Connor/Library/Application\\ Support/minecraft/bin/lwjgl.jar:/Users/Connor/Library/Application\\ Support/minecraft/bin/lwjgl_util.jar:/Users/Connor/Library/Application\\ Support/minecraft/bin/jinput.jar: -Djava.library.path=/Users/Connor/Library/Application\\ Support/minecraft/bin/natives -Xmx1024M -Xms512M net.minecraft.client.Minecraft 'username'

即使尝试运行直接来自 applescript 的脚本,我也会收到另一个 java.lang.NoClassDefFoundError 错误,即使我直接从正在运行的 applescript 获取命令。

最佳答案

在默认启动器中,您提供的任何用户名都会用于离线模式,因此编写单独的启动器是没有意义的。

无论如何,反编译启动器应该能让我们很好地了解如何启动游戏。

代码较多,建议自行反编译。对于 Mac,JD-GUI 做得还不错。对于 Windows,我不能推荐反编译器,但这就是 google 的用途:)

获得启动器源代码后,请查看 net.minecraft.LauncherFrame 中的 public void login(String userName, String password)。同样相关的是 net.minecraft.Launcher。

通读本文应该会让您对如何启动 Minecraft 有一个很好的了解。

关于java - 使用 Java 在 Mac 上启动 Minecraft,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14698089/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com