11import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22import cc.polyfrost.gradle.util.noServerRunConfigs
33
4+ // Adds support for kotlin, and adds the Polyfrost Gradle Toolkit which we use to prepare the environment.
45plugins {
56 kotlin(" jvm" )
67 id(" cc.polyfrost.multi-version" )
@@ -13,72 +14,95 @@ plugins {
1314 java
1415}
1516
17+ // Gets the mod name, version and id from the `gradle.properties` file.
1618val mod_name: String by project
1719val mod_version: String by project
1820val mod_id: String by project
1921
22+ // Sets up the variables for when we preprocess to other Minecraft versions.
2023preprocess {
2124 vars.put(" MODERN" , if (project.platform.mcMinor >= 16 ) 1 else 0 )
2225}
2326
27+ // Replaces the variables in `ExampleMod.java` to the ones specified in `gradle.properties`.
2428blossom {
2529 replaceToken(" @VER@" , mod_version)
2630 replaceToken(" @NAME@" , mod_name)
2731 replaceToken(" @ID@" , mod_id)
2832}
2933
34+ // Sets the mod version to the one specified in `gradle.properties`. Make sure to change this following semver!
3035version = mod_version
36+ // Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username.
37+ // e.g. com.github.<your username> or com.<your domain>
3138group = " cc.polyfrost"
39+ // Sets the name of the output jar (the one you put in your mods folder and send to other people)
40+ // It outputs all versions of the mod into the `build` directory.
3241base {
3342 archivesName.set(" $mod_id -$platform " )
3443}
3544
45+ // Configures the Polyfrost Loom, our plugin fork to easily set up the programming environment.
3646loom {
47+ // Removes the server configs from IntelliJ IDEA, since we aren't developing a server mod.
3748 noServerRunConfigs()
49+ // Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.cc)
3850 if (project.platform.isLegacyForge) {
3951 launchConfigs.named(" client" ) {
4052 arg(" --tweakClass" , " cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" )
41- property(" mixin.debug.export" , " true" )
53+ property(
54+ " mixin.debug.export" ,
55+ " true"
56+ ) // This is enabled so OneConfig can read our Mixins and automatically apply them.
4257 }
4358 }
59+ // Configures the mixins if we are building for forge. (Useful for when we are dealing with cross-platform projects.
4460 if (project.platform.isForge) {
4561 forge {
4662 mixinConfig(" mixins.${mod_id} .json" )
4763 }
4864 }
65+ // Configures the name of the mixin "refmap" using an experimental loom api. You can ignore this warning.
4966 mixin.defaultRefmapName.set(" mixins.${mod_id} .refmap.json" )
5067}
5168
69+ // Creates the shade/shadow configuration, so we can include libraries inside our mod, rather than having to add them separately.
5270val shade: Configuration by configurations.creating {
5371 configurations.implementation.get().extendsFrom(this )
5472}
5573
74+ // Configures the output directory for when building from the `src/resources` directory.
5675sourceSets {
5776 main {
5877 output.setResourcesDir(java.classesDirectory)
5978 }
6079}
6180
81+ // Adds the Polyfrost maven repository so we can get the libraries necessary to develop the mod.
6282repositories {
6383 maven(" https://repo.polyfrost.cc/releases" )
6484}
6585
86+ // Configures the libraries/dependencies for your mod.
6687dependencies {
67- modCompileOnly(" cc.polyfrost:oneconfig-$platform :0.2.0-alpha+" )
88+ modCompileOnly(" cc.polyfrost:oneconfig-$platform :0.2.0-alpha+" ) // Adds the OneConfig library, so we can develop with it.
6889
90+ // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
6991 if (platform.isLegacyForge) {
7092 compileOnly(" org.spongepowered:mixin:0.7.11-SNAPSHOT" )
7193 shade(" cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+" )
7294 }
7395}
7496
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`
7598tasks.processResources {
7699 inputs.property(" id" , mod_id)
77100 inputs.property(" name" , mod_name)
78101 val java = if (project.platform.mcMinor >= 18 ) {
79- 17
102+ 17 // If we are playing on version 1.18, set the java version to 17
80103 } else {
81- if (project.platform.mcMinor == 17 ) 16 else 8
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.
82106 }
83107 val compatLevel = " JAVA_${java} "
84108 inputs.property(" java" , java)
@@ -112,6 +136,7 @@ tasks.processResources {
112136}
113137
114138tasks {
139+ // Configures the resources to include if we are building for forge or fabric.
115140 withType(Jar ::class .java) {
116141 if (project.platform.isFabric) {
117142 exclude(" mcmod.info" , " mods.toml" )
@@ -124,24 +149,26 @@ tasks {
124149 }
125150 }
126151 }
152+ // Configures our shadow/shade configuration, so we can include the OneConfig launch wrapper with our mod.
127153 named<ShadowJar >(" shadowJar" ) {
128- archiveClassifier.set(" dev" )
154+ archiveClassifier.set(" dev" ) // TODO: machete gets confused by the `dev` prefix.
129155 configurations = listOf (shade)
130156 duplicatesStrategy = DuplicatesStrategy .EXCLUDE
131157 }
132158 remapJar {
133159 input.set(shadowJar.get().archiveFile)
134160 archiveClassifier.set(" " )
135161 }
162+ // Sets the jar manifest attributes.
136163 jar {
137164 manifest {
138165 attributes(
139166 mapOf (
140- " ModSide" to " CLIENT" ,
141- " ForceLoadAsMod" to true ,
142- " TweakOrder" to " 0" ,
143- " MixinConfigs" to " mixin.${mod_id} .json" ,
144- " TweakClass" to " cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker"
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.
145172 )
146173 )
147174 }
0 commit comments