思路

  想要尝试在低版本的Forge上使用FG5+是因为Kotlingradle插件要求的gradle版本只有FG5+支持。

  首先说一下为什么我确信可以在低版本上使用FG5+,因为在使用FG2.3的时候构建完毕有一条输出,原文我没有记住,翻译过来就是:“使用FG5+来体验新的生产工具”。

  但是我个人并不会编写gradle,自行编写肯定是不现实的。于是我就想到了一个最简单的办法:把高版本的build.gradle搬过来不就好了?

  但是说起来简单做起来难,中间我遇到了各种各样的问题。具体内容我就不再多说,直接给出最终解决方案。

教程

如果没有特别声明,本文均以项目根目录为基础

升级 Gradle

  首先我们肯定要升级Gradle版本,升级方法很简单,修改:

gradle/wrapper/gradle-wrapper.properties

1
2
3
4
5
6
  distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-?.?-bin.zip
+ distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

  其中,gradle-7.4-bin.zip中间的数字就是我们需要的版本号,读者也可以根据自己的需要选择不同版本,但是注意,FG5+有最低版本要求。

编写 build.gradle

  为了以防万一,读者最好先备份一下自己已有的build.gradle,然后将以下内容CV进去:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
buildscript {
ext.kotlin_version = '1.7.20' // kotli 版本
repositories {
mavenLocal()
maven { url = "https://maven.aliyun.com/repository/public" } // 阿里云镜像
mavenCentral()
// These repositories are only for Gradle plugins, put any other repositories in the repository block further below
maven { url = 'https://maven.minecraftforge.net' }
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath 'org.spongepowered:mixingradle:0.7.+'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'kotlin'
apply plugin: 'org.spongepowered.mixin'

version = '1.0'
group = '' // http://maven.apache.org/guides/mini/guide-naming-conventions.html

sourceCompatibility = targetCompatibility = '1.8'

minecraft {
mappings channel: 'snapshot', version: '20171003-1.12'
runs {
client {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'REGISTRIES'

// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'

// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', 'mi'
}

server {
workingDirectory project.file('run')

property 'forge.logging.markers', 'REGISTRIES'

property 'forge.logging.console.level', 'debug'

// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', 'mi'
}
}
}

repositories {
mavenCentral()
// Put repositories for dependencies here
// ForgeGradle automatically adds the Forge maven and Maven Central for you

// If you have mod jar dependencies in ./libs, you can declare them as a repository like so:
// flatDir {
// dir 'libs'
// }
}

dependencies {
minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2859'
implementation 'org.spongepowered:mixin:0.8.5'
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}

sourceSets.main.resources { srcDir 'src/generated/resources' }

mixin {
// MixinGradle Settings
add sourceSets.main, 'mixins.mi.refmap.json'
config 'mixins.mi.json'
}

// Example for how to get properties into the manifest for reading at runtime.
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE

from {
// 将 mixin 和 kotlin 打包到 jar 中
configurations.runtimeClasspath.findAll {
it.name.contains("mixin") || it.name.contains("kotlin")
}.collect {
zipTree(it)
}
} {
// 排除一些文件
exclude '**/module-info.class',
'LICENSE.txt',
'META-INF/MUMFREY.RSA',
'**/*.kotlin_module'
}
}

compileJava {
options.encoding 'UTF-8'
sourceCompatibility '1.8'
targetCompatibility '1.8'
}

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

  请注意,以上的build.gradle是针对forge:1.12.2-14.23.5.2859编写的,如果你要使用其它forge版本请自行修改相应参数。

  同时这份build.gradle中包含了mixinkotlin,如果有不需要的组件还请自行删除,同时请注意mixin的参数需要自己补充。

修复资源错误

  完成gradle的构建之后,如果启动游戏发现自己模组的所有资源都无法加载,可以使用Windows的软连接来解决问题。

  打开命令提示符进入项目根目录,执行下面的命令:

mklink /J "out/production/classes/assets" "out/production/resources/assets"

  这上面的路径各位根据自己的情况进行调整。

资源

  对于forge:1.12.2-14.23.5.2859我在网上上传了离线包供各位下载,由于阿里云盘不能分享压缩包,有需要的小伙伴可以加Q群(1071299300)在群文件中下载。

鸣谢

  • MCreator讨论群(239746610)内的大佬们
  • 执着
  • ZK