= 创作分享 =
编程开发
在苹果芯片设备上开发 Forge 模组时启动报错的修复方案 ...
北斗余晖

在苹果芯片设备上开发 Forge 模组时启动报错的修复方案

北斗余晖 于 2022-9-25 19:04 ( 1年前 ) [复制链接] [显示全部楼层] [打印]
若你不使用搭载苹果芯片(macOS,ARM架构)的设备开发Forge模组,则不需要阅读本文。
背景:
当你使用基于ARM Native的JDK运行MC时,会出现以下报错:
  1. [LWJGL] Platform/architecture mismatch detected for module: org.lwjgl
  2.   JVM platform:
  3.     macOS aarch64 17.0.1
  4.     OpenJDK 64-Bit Server VM v17.0.1+12-39 by Oracle Corporation
  5.   Platform available on classpath:
  6.     macos/x64
  7. ---
  8. Exception in thread "Render thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
  9. ---
  10. Caused by: java.lang.reflect.InvocationTargetException
  11. ---
  12. Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.mojang.blaze3d.systems.RenderSystem
复制代码
修复方法:
①在下列两条代码中任选其一复制到工作区build.gradle的最后一行:
  1. apply from: "https://moddingtutorials.org/applesilicon.gradle"
复制代码
  1. apply from: "https://gitee.com/nova-committee/AppleSiliconGradleFix/blob/main/applesilicon.gradle"
复制代码
②确保build.gradle同目录下有gradle.properties文件,且定义mc_version=你正在开发的mc版本;
以开发Forge1.18.2为例:
  1. mc_version=1.18.2
复制代码
③重新运行runClient。第一次运行会出现同样的报错,这很正常,运行第二次时应该就能顺利启动了。
如果你在开发1.16.5/1.17.1,还需要额外执行以下步骤:
Forge1.16.5:使用不低于36.2.30版本的MDK
Forge1.17.1:你需要额外添加一个客户端侧mixin
  1. @Mixin(Window.class)
  2. public class M1Fix {
  3.     @Inject(at = @At("HEAD"), method = "setIcon", cancellable = true)
  4.     private void glfwSetWindowIcon(InputStream intbuffer1, InputStream intbuffer2, CallbackInfo ci) {
  5.         if (isAppleSlilicon()) ci.cancel();
  6.     }
  7.     @Inject(at = @At("HEAD"), method = "checkGlfwError", cancellable = true)
  8.     private static void checkGlfwError(BiConsumer<Integer, String> j, CallbackInfo ci) {
  9.         if (isAppleSlilicon()) ci.cancel();
  10.     }
  11.     private static boolean isAppleSlilicon() {
  12.         return System.getProperty("os.arch").equals("aarch64") && System.getProperty("os.name").equals("Mac OS X");
  13. }
  14. }
复制代码

如果你不知道如何使用Mixins,请看以下教程:
xfl03的Mixins中文教程


发表于 2022-9-25 19:04:08 | 显示全部楼层 |阅读模式

回复 | 举报

该帖共收到 0 条回复!
百科目前不允许匿名发帖哦~ 请先 [ 登陆 ][ 注册 ] 吧~

本版积分规则

发新帖
  • 回复
  • 点评
  • 评分

[ MC百科(mcmod.cn) 除另有声明,所有开放公共编辑的内容均使用 BY-NC-SA 3.0 协议 ]

Minecraft百科CC协议
快速回复 返回顶部 返回列表