1
+ @file:Suppress(" UnstableApiUsage" , " PropertyName" )
2
+
3
+ import org.polyfrost.gradle.util.noServerRunConfigs
1
4
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2
- import cc.polyfrost.gradle.util.noServerRunConfigs
3
- import cc.polyfrost.gradle.util.setJvmDefault
4
5
6
+ // Adds support for kotlin, and adds the Polyfrost Gradle Toolkit
7
+ // which we use to prepare the environment.
5
8
plugins {
6
9
kotlin(" jvm" )
7
- id(" cc .polyfrost.multi-version" )
8
- id(" cc .polyfrost.defaults.repo" )
9
- id(" cc .polyfrost.defaults.java" )
10
- id(" cc .polyfrost.defaults.loom" )
10
+ id(" org .polyfrost.multi-version" )
11
+ id(" org .polyfrost.defaults.repo" )
12
+ id(" org .polyfrost.defaults.java" )
13
+ id(" org .polyfrost.defaults.loom" )
11
14
id(" com.github.johnrengelman.shadow" )
12
- id(" net.kyori.blossom" ) version " 1.3.0 "
15
+ id(" net.kyori.blossom" ) version " 1.3.1 "
13
16
id(" signing" )
14
17
java
15
18
}
16
19
20
+ // Gets the mod name, version and id from the `gradle.properties` file.
17
21
val mod_name: String by project
18
22
val mod_version: String by project
19
23
val mod_id: String by project
24
+ val mod_archives_name: String by project
20
25
26
+ // Sets up the variables for when we preprocess to other Minecraft versions.
21
27
preprocess {
22
28
vars.put(" MODERN" , if (project.platform.mcMinor >= 16 ) 1 else 0 )
23
29
}
24
30
31
+ // Replaces the variables in `ExampleMod.java` to the ones specified in `gradle.properties`.
25
32
blossom {
26
33
replaceToken(" @VER@" , mod_version)
27
34
replaceToken(" @NAME@" , mod_name)
28
35
replaceToken(" @ID@" , mod_id)
29
36
}
30
37
38
+ // Sets the mod version to the one specified in `gradle.properties`. Make sure to change this following semver!
31
39
version = mod_version
40
+ // Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username.
41
+ // e.g. com.github.<your username> or com.<your domain>
32
42
group = " dev.isxander"
43
+
44
+ // Sets the name of the output jar (the one you put in your mods folder and send to other people)
45
+ // It outputs all versions of the mod into the `build` directory.
33
46
base {
34
- archivesName.set(" $mod_name -$platform " )
47
+ archivesName.set(" $mod_archives_name -$platform " )
35
48
}
49
+
50
+ // Configures the Polyfrost Loom, our plugin fork to easily set up the programming environment.
36
51
loom {
52
+ // Removes the server configs from IntelliJ IDEA, leaving only client runs.
53
+ // If you're developing a server-side mod, you can remove this line.
37
54
noServerRunConfigs()
55
+
56
+ // Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org)
38
57
if (project.platform.isLegacyForge) {
39
- launchConfigs.named(" client" ) {
40
- arg(" --tweakClass" , " cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" )
58
+ runConfigs {
59
+ " client" {
60
+ programArgs(" --tweakClass" , " cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" )
61
+ property(" mixin.debug.export" , " true" )
62
+ }
41
63
}
42
64
}
43
65
}
44
- tasks.compileKotlin.setJvmDefault(if (platform.mcVersion >= 11400 ) " all" else " all-compatibility" )
45
66
67
+ // Creates the shade/shadow configuration, so we can include libraries inside our mod, rather than having to add them separately.
46
68
val shade: Configuration by configurations.creating {
47
69
configurations.implementation.get().extendsFrom(this )
48
70
}
49
71
72
+ // Configures the output directory for when building from the `src/resources` directory.
50
73
sourceSets {
51
74
main {
52
75
output.setResourcesDir(java.classesDirectory)
53
76
}
54
77
}
55
78
79
+ // Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod.
56
80
repositories {
57
- maven(" https://repo.polyfrost.cc /releases" )
81
+ maven(" https://repo.polyfrost.org /releases" )
58
82
}
59
83
84
+ // Configures the libraries/dependencies for your mod.
60
85
dependencies {
86
+ // Adds the OneConfig library, so we can develop with it.
87
+ modCompileOnly(" cc.polyfrost:oneconfig-$platform :0.2.1-alpha+" )
88
+
89
+ modRuntimeOnly(" me.djtheredstoner:DevAuth-${if (platform.isFabric) " fabric" else if (platform.isLegacyForge) " forge-legacy" else " forge-latest" } :1.1.2" )
90
+
91
+ // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
61
92
if (platform.isLegacyForge) {
62
- runtimeOnly( " me.djtheredstoner:DevAuth-forge-legacy :1.1.0 " )
93
+ shade( " cc.polyfrost:oneconfig-wrapper-launchwrapper :1.0.0-beta+ " )
63
94
}
64
- compileOnly(" cc.polyfrost:oneconfig-1.8.9-forge:0.2.0-alpha+" )
65
- shade(" cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+" )
66
95
}
67
96
68
- tasks.processResources {
69
- inputs.property(" id" , mod_id)
70
- inputs.property(" name" , mod_name)
71
- val java = if (project.platform.mcMinor >= 18 ) {
72
- 17
73
- } else {
74
- if (project.platform.mcMinor == 17 ) 16 else 8
75
- }
76
- val compatLevel = " JAVA_${java} "
77
- inputs.property(" java" , java)
78
- inputs.property(" java_level" , compatLevel)
79
- inputs.property(" version" , mod_version)
80
- inputs.property(" mcVersionStr" , project.platform.mcVersionStr)
81
- filesMatching(listOf (" mcmod.info" , " mixins.${mod_id} .json" , " mods.toml" )) {
82
- expand(
83
- mapOf (
84
- " id" to mod_id,
85
- " name" to mod_name,
86
- " java" to java,
87
- " java_level" to compatLevel,
88
- " version" to mod_version,
89
- " mcVersionStr" to project.platform.mcVersionStr
97
+ tasks {
98
+ // Processes the `src/resources/mcmod.info or fabric.mod.json` and replaces
99
+ // the mod id, name and version with the ones in `gradle.properties`
100
+ processResources {
101
+ inputs.property(" id" , mod_id)
102
+ inputs.property(" name" , mod_name)
103
+ val java = if (project.platform.mcMinor >= 18 ) {
104
+ 17 // If we are playing on version 1.18, set the java version to 17
105
+ } else {
106
+ // Else if we are playing on version 1.17, use java 16.
107
+ if (project.platform.mcMinor == 17 )
108
+ 16
109
+ else
110
+ 8 // For all previous versions, we **need** java 8 (for Forge support).
111
+ }
112
+ val compatLevel = " JAVA_${java} "
113
+ inputs.property(" java" , java)
114
+ inputs.property(" java_level" , compatLevel)
115
+ inputs.property(" version" , mod_version)
116
+ inputs.property(" mcVersionStr" , project.platform.mcVersionStr)
117
+ filesMatching(listOf (" mcmod.info" , " mixins.${mod_id} .json" , " mods.toml" )) {
118
+ expand(
119
+ mapOf (
120
+ " id" to mod_id,
121
+ " name" to mod_name,
122
+ " java" to java,
123
+ " java_level" to compatLevel,
124
+ " version" to mod_version,
125
+ " mcVersionStr" to project.platform.mcVersionStr
126
+ )
90
127
)
91
- )
92
- }
93
- filesMatching( " fabric.mod.json " ) {
94
- expand (
95
- mapOf (
96
- " id " to mod_id ,
97
- " name " to mod_name ,
98
- " java " to java ,
99
- " java_level " to compatLevel ,
100
- " version " to mod_version,
101
- " mcVersionStr " to project.platform.mcVersionStr.substringBeforeLast( " . " ) + " .x "
128
+ }
129
+ filesMatching( " fabric.mod.json " ) {
130
+ expand(
131
+ mapOf (
132
+ " id " to mod_id,
133
+ " name " to mod_name ,
134
+ " java " to java ,
135
+ " java_level " to compatLevel ,
136
+ " version " to mod_version ,
137
+ " mcVersionStr " to project.platform.mcVersionStr.substringBeforeLast( " . " ) + " .x "
138
+ )
102
139
)
103
- )
140
+ }
104
141
}
105
- }
106
142
107
- tasks {
143
+ // Configures the resources to include if we are building for forge or fabric.
108
144
withType(Jar ::class .java) {
109
145
if (project.platform.isFabric) {
110
146
exclude(" mcmod.info" , " mods.toml" )
@@ -117,24 +153,28 @@ tasks {
117
153
}
118
154
}
119
155
}
156
+
157
+ // Configures our shadow/shade configuration, so we can
158
+ // include some dependencies within our mod jar file.
120
159
named<ShadowJar >(" shadowJar" ) {
121
- archiveClassifier.set(" dev" )
160
+ archiveClassifier.set(" dev" ) // TODO: machete gets confused by the `dev` prefix.
122
161
configurations = listOf (shade)
123
162
duplicatesStrategy = DuplicatesStrategy .EXCLUDE
124
163
}
164
+
125
165
remapJar {
126
- input .set(shadowJar.get().archiveFile)
166
+ inputFile .set(shadowJar.get().archiveFile)
127
167
archiveClassifier.set(" " )
128
168
}
169
+
129
170
jar {
130
- manifest {
131
- attributes(
132
- mapOf (
133
- " ModSide" to " CLIENT" ,
134
- " ForceLoadAsMod" to true ,
135
- " TweakOrder" to " 0" ,
136
- " TweakClass" to " cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker"
137
- )
171
+ // Sets the jar manifest attributes.
172
+ if (platform.isLegacyForge) {
173
+ manifest.attributes + = mapOf (
174
+ " ModSide" to " CLIENT" , // We aren't developing a server-side mod, so this is fine.
175
+ " ForceLoadAsMod" to true , // We want to load this jar as a mod, so we force Forge to do so.
176
+ " TweakOrder" to " 0" , // Makes sure that the OneConfig launch wrapper is loaded as soon as possible.
177
+ " TweakClass" to " cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper.
138
178
)
139
179
}
140
180
dependsOn(shadowJar)
0 commit comments