1- import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
1+ @file:Suppress(" UnstableApiUsage" , " PropertyName" )
2+
23import cc.polyfrost.gradle.util.noServerRunConfigs
4+ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
35
4- // Adds support for kotlin, and adds the Polyfrost Gradle Toolkit which we use to prepare the environment.
6+ // Adds support for kotlin, and adds the Polyfrost Gradle Toolkit
7+ // which we use to prepare the environment.
58plugins {
69 kotlin(" jvm" )
710 id(" cc.polyfrost.multi-version" )
@@ -36,6 +39,7 @@ version = mod_version
3639// Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username.
3740// e.g. com.github.<your username> or com.<your domain>
3841group = " cc.polyfrost"
42+
3943// Sets the name of the output jar (the one you put in your mods folder and send to other people)
4044// It outputs all versions of the mod into the `build` directory.
4145base {
@@ -44,25 +48,29 @@ base {
4448
4549// Configures the Polyfrost Loom, our plugin fork to easily set up the programming environment.
4650loom {
47- // Removes the server configs from IntelliJ IDEA, since we aren't developing a server mod.
51+ // Removes the server configs from IntelliJ IDEA, leaving only client runs.
52+ // If you're developing a server-side mod, you can remove this line.
4853 noServerRunConfigs()
54+
4955 // Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.cc)
5056 if (project.platform.isLegacyForge) {
5157 launchConfigs.named(" client" ) {
5258 arg(" --tweakClass" , " cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" )
59+
60+ // This is enabled so OneConfig can read our Mixins and automatically apply them.
5361 property(
5462 " mixin.debug.export" ,
5563 " true"
56- ) // This is enabled so OneConfig can read our Mixins and automatically apply them.
64+ )
5765 }
5866 }
59- // Configures the mixins if we are building for forge. (Useful for when we are dealing with cross-platform projects.
67+ // Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects.
6068 if (project.platform.isForge) {
6169 forge {
6270 mixinConfig(" mixins.${mod_id} .json" )
6371 }
6472 }
65- // Configures the name of the mixin "refmap" using an experimental loom api. You can ignore this warning.
73+ // Configures the name of the mixin "refmap" using an experimental loom api.
6674 mixin.defaultRefmapName.set(" mixins.${mod_id} .refmap.json" )
6775}
6876
@@ -78,14 +86,15 @@ sourceSets {
7886 }
7987}
8088
81- // Adds the Polyfrost maven repository so we can get the libraries necessary to develop the mod.
89+ // Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod.
8290repositories {
8391 maven(" https://repo.polyfrost.cc/releases" )
8492}
8593
8694// Configures the libraries/dependencies for your mod.
8795dependencies {
88- modCompileOnly(" cc.polyfrost:oneconfig-$platform :0.2.0-alpha+" ) // Adds the OneConfig library, so we can develop with it.
96+ // Adds the OneConfig library, so we can develop with it.
97+ modCompileOnly(" cc.polyfrost:oneconfig-$platform :0.2.0-alpha+" )
8998
9099 // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
91100 if (platform.isLegacyForge) {
@@ -94,48 +103,52 @@ dependencies {
94103 }
95104}
96105
97- // Processes the `src/resources/mcmod.info or fabric.mod.json` and replaces the mod id, name and version with the ones in `gradle.properties`
98- tasks.processResources {
99- inputs.property(" id" , mod_id)
100- inputs.property(" name" , mod_name)
101- val java = if (project.platform.mcMinor >= 18 ) {
102- 17 // If we are playing on version 1.18, set the java version to 17
103- } else {
104- // Else if we are playing on version 1.17, use java 16.
105- if (project.platform.mcMinor == 17 ) 16 else 8 // For all previous versions, java version 8 is okay.
106- }
107- val compatLevel = " JAVA_${java} "
108- inputs.property(" java" , java)
109- inputs.property(" java_level" , compatLevel)
110- inputs.property(" version" , mod_version)
111- inputs.property(" mcVersionStr" , project.platform.mcVersionStr)
112- filesMatching(listOf (" mcmod.info" , " mixins.${mod_id} .json" , " mods.toml" )) {
113- expand(
114- mapOf (
115- " id" to mod_id,
116- " name" to mod_name,
117- " java" to java,
118- " java_level" to compatLevel,
119- " version" to mod_version,
120- " mcVersionStr" to project.platform.mcVersionStr
106+ tasks {
107+ // Processes the `src/resources/mcmod.info or fabric.mod.json` and replaces
108+ // the mod id, name and version with the ones in `gradle.properties`
109+ processResources {
110+ inputs.property(" id" , mod_id)
111+ inputs.property(" name" , mod_name)
112+ val java = if (project.platform.mcMinor >= 18 ) {
113+ 17 // If we are playing on version 1.18, set the java version to 17
114+ } else {
115+ // Else if we are playing on version 1.17, use java 16.
116+ if (project.platform.mcMinor == 17 )
117+ 16
118+ else
119+ 8 // For all previous versions, we **need** java 8 (for Forge support).
120+ }
121+ val compatLevel = " JAVA_${java} "
122+ inputs.property(" java" , java)
123+ inputs.property(" java_level" , compatLevel)
124+ inputs.property(" version" , mod_version)
125+ inputs.property(" mcVersionStr" , project.platform.mcVersionStr)
126+ filesMatching(listOf (" mcmod.info" , " mixins.${mod_id} .json" , " mods.toml" )) {
127+ expand(
128+ mapOf (
129+ " id" to mod_id,
130+ " name" to mod_name,
131+ " java" to java,
132+ " java_level" to compatLevel,
133+ " version" to mod_version,
134+ " mcVersionStr" to project.platform.mcVersionStr
135+ )
121136 )
122- )
123- }
124- filesMatching( " fabric.mod.json " ) {
125- expand (
126- mapOf (
127- " id " to mod_id ,
128- " name " to mod_name ,
129- " java " to java ,
130- " java_level " to compatLevel ,
131- " version " to mod_version,
132- " mcVersionStr " to project.platform.mcVersionStr.substringBeforeLast( " . " ) + " .x "
137+ }
138+ filesMatching( " fabric.mod.json " ) {
139+ expand(
140+ mapOf (
141+ " id " to mod_id,
142+ " name " to mod_name ,
143+ " java " to java ,
144+ " java_level " to compatLevel ,
145+ " version " to mod_version ,
146+ " mcVersionStr " to project.platform.mcVersionStr.substringBeforeLast( " . " ) + " .x "
147+ )
133148 )
134- )
149+ }
135150 }
136- }
137151
138- tasks {
139152 // Configures the resources to include if we are building for forge or fabric.
140153 withType(Jar ::class .java) {
141154 if (project.platform.isFabric) {
@@ -149,27 +162,29 @@ tasks {
149162 }
150163 }
151164 }
152- // Configures our shadow/shade configuration, so we can include the OneConfig launch wrapper with our mod.
165+
166+ // Configures our shadow/shade configuration, so we can
167+ // include some dependencies within our mod jar file.
153168 named<ShadowJar >(" shadowJar" ) {
154169 archiveClassifier.set(" dev" ) // TODO: machete gets confused by the `dev` prefix.
155170 configurations = listOf (shade)
156171 duplicatesStrategy = DuplicatesStrategy .EXCLUDE
157172 }
173+
158174 remapJar {
159175 input.set(shadowJar.get().archiveFile)
160176 archiveClassifier.set(" " )
161177 }
162- // Sets the jar manifest attributes.
178+
163179 jar {
164- manifest {
165- attributes(
166- mapOf (
167- " ModSide" to " CLIENT" , // We aren't developing a server-side mod, so this is fine.
168- " ForceLoadAsMod" to true , // We want to load this jar as a mod, so we force Forge to do so.
169- " TweakOrder" to " 0" , // Makes sure that the OneConfig launch wrapper is loaded as soon as possible.
170- " MixinConfigs" to " mixin.${mod_id} .json" , // We want to use our mixin configuration, so we specify it here.
171- " TweakClass" to " cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper.
172- )
180+ // Sets the jar manifest attributes.
181+ if (platform.isLegacyForge) {
182+ manifest.attributes + = mapOf (
183+ " ModSide" to " CLIENT" , // We aren't developing a server-side mod, so this is fine.
184+ " ForceLoadAsMod" to true , // We want to load this jar as a mod, so we force Forge to do so.
185+ " TweakOrder" to " 0" , // Makes sure that the OneConfig launch wrapper is loaded as soon as possible.
186+ " MixinConfigs" to " mixin.${mod_id} .json" , // We want to use our mixin configuration, so we specify it here.
187+ " TweakClass" to " cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper.
173188 )
174189 }
175190 dependsOn(shadowJar)
0 commit comments