1515 * along with this program. If not, see <https://www.gnu.org/licenses/>.
1616 */
1717
18+ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
1819import dev.dediamondpro.buildsource.Platform
1920import dev.dediamondpro.buildsource.VersionDefinition
2021import dev.dediamondpro.buildsource.VersionRange
22+ import net.fabricmc.loom.task.RemapJarTask
2123
2224plugins {
2325 alias(libs.plugins.kotlin)
@@ -68,7 +70,8 @@ val shade: Configuration by configurations.creating {
6870}
6971
7072val shadeModImplementation: Configuration by configurations.creating {
71- configurations.modImplementation.get().extendsFrom(this )
73+ val parent = if (mcPlatform.isObfuscated) " modImplementation" else " implementation"
74+ configurations.getByName(parent).extendsFrom(this )
7275}
7376
7477// Version definitions
@@ -144,22 +147,19 @@ val kotlinForForgeVersion = VersionDefinition(
144147 " 1.21.5" to " 5.7.0" ,
145148 " 1.21.8" to " 5.9.0" ,
146149)
147- val universalMcVersion = VersionDefinition (
150+ val universalVersion = VersionDefinition (
148151 " 1.21.1" to " 1.21" ,
149152 " 1.21.8" to " 1.21.7" ,
150153 " 1.21.10" to " 1.21.9" ,
151154 default = mcPlatform.versionString
152- )
153- val universalVersion = VersionDefinition (
154- default = " ${universalMcVersion.get(mcPlatform)} -${mcPlatform.loaderString} :466"
155- )
155+ ).let { VersionDefinition (default = " ${it.get(mcPlatform)} -${mcPlatform.loaderString} :466" ) }
156156
157157dependencies {
158158 minecraft(" com.mojang:minecraft:${mcVersion.get(mcPlatform)} " )
159159
160- if (mcPlatform.major == 1 ) {
160+ if (mcPlatform.isObfuscated ) {
161161 @Suppress(" UnstableApiUsage" )
162- mappings( loom.layered {
162+ add( " mappings " , loom.layered {
163163 officialMojangMappings()
164164 parchmentVersion.getOrNull(mcPlatform)?.let {
165165 parchment(" org.parchmentmc.data:parchment-$it @zip" )
@@ -168,18 +168,16 @@ dependencies {
168168 }
169169
170170 if (mcPlatform.isFabric) {
171- modImplementation( " net.fabricmc:fabric-loader:0.17.3 " )
172-
173- modImplementation( " net.fabricmc:fabric-language-kotlin:${libs.versions.fabric.language.kotlin.get()} " )
174- modImplementation( " net.fabricmc.fabric-api:fabric-api:${fabricApiVersion.get(mcPlatform)} " )
175- modImplementation( " com.terraformersmc:modmenu:${modMenuVersion.get(mcPlatform)} " )
171+ val modImpl = if (mcPlatform.isObfuscated) " modImplementation " else " implementation "
172+ add(modImpl, " net.fabricmc:fabric-loader:0.17.3 " )
173+ add(modImpl, " net.fabricmc:fabric-language-kotlin:${libs.versions.fabric.language.kotlin.get()} " )
174+ add(modImpl, " net.fabricmc.fabric-api:fabric-api:${fabricApiVersion.get(mcPlatform)} " )
175+ add(modImpl, " com.terraformersmc:modmenu:${modMenuVersion.get(mcPlatform)} " )
176176 } else if (mcPlatform.isNeoForge) {
177177 " neoForge" (" net.neoforged:neoforge:${neoForgeVersion.get(mcPlatform)} " )
178-
179178 implementation(" thedarkcolour:kotlinforforge-neoforge:${kotlinForForgeVersion.get(mcPlatform)} " )
180179 } else if (mcPlatform.isForge) {
181180 " forge" (" net.minecraftforge:forge:${forgeVersion.get(mcPlatform)} " )
182-
183181 implementation(" thedarkcolour:kotlinforforge:${kotlinForForgeVersion.get(mcPlatform)} " )
184182 }
185183
@@ -197,22 +195,19 @@ dependencies {
197195 }
198196}
199197
200- val accesWidener = if (mcPlatform.version >= 1_21_09 ) {
201- " 1.21.9.resourcify"
202- } else if (mcPlatform.minor == 21 ) {
203- " 1.21.resourcify"
204- } else {
205- " 1.20.resourcify"
198+ val accessWidener = when {
199+ mcPlatform.version >= 26_00_00 -> " 26.1.resourcify"
200+ mcPlatform.version >= 1_21_09 -> " 1.21.9.resourcify"
201+ mcPlatform.minor == 21 -> " 1.21.resourcify"
202+ else -> " 1.20.resourcify"
206203}
207-
208- val mixinPath = if (mcPlatform.version >= 1_21_11 ) {
209- " mixins.resourcify-1.21.11.json"
210- } else {
211- " mixins.resourcify.json"
204+ val mixinPath = when {
205+ mcPlatform.version >= 1_21_11 -> " mixins.resourcify-1.21.11.json"
206+ else -> " mixins.resourcify.json"
212207}
213208
214209loom {
215- accessWidenerPath = rootProject.file(" src/main/resources/$accesWidener .accesswidener" )
210+ accessWidenerPath = rootProject.file(" src/main/resources/$accessWidener .accesswidener" )
216211
217212 if (mcPlatform.isForge) forge {
218213 convertAccessWideners.set(true )
@@ -232,9 +227,19 @@ base.archivesName.set(
232227 } -${mcPlatform.loaderString} )-$mod_version "
233228)
234229
230+ val outputJar = if (mcPlatform.isObfuscated) {
231+ tasks.named<RemapJarTask >(" remapJar" ).flatMap { it.archiveFile }
232+ } else {
233+ tasks.named<ShadowJar >(" shadowJar" ).flatMap { it.archiveFile }
234+ }
235+
235236publishMods {
236- file.set(tasks.remapJar.get().archiveFile)
237- displayName.set(" [${compatibleMcVersion.get(mcPlatform).getName()} -${mcPlatform.loaderString} ] $mod_name $mod_version " )
237+ file.set(outputJar)
238+ displayName.set(
239+ " [${
240+ compatibleMcVersion.get(mcPlatform).getName()
241+ } -${mcPlatform.loaderString} ] $mod_name $mod_version "
242+ )
238243 version.set(mod_version)
239244 changelog.set(rootProject.file(" changelog.md" ).readText())
240245 type.set(STABLE )
@@ -276,8 +281,8 @@ publishMods {
276281}
277282
278283tasks {
279- named< com.github.jengelman.gradle.plugins.shadow.tasks. ShadowJar > (" shadowJar" ) {
280- archiveClassifier.set(" dev" )
284+ named<ShadowJar >(" shadowJar" ) {
285+ archiveClassifier.set(if (mcPlatform.isObfuscated) " dev" else " " )
281286 configurations = listOf (shade, shadeModImplementation)
282287 duplicatesStrategy = DuplicatesStrategy .EXCLUDE
283288
@@ -288,16 +293,20 @@ tasks {
288293 relocate(" org.commonmark" , " dev.dediamondpro.resourcify.libs.commonmark" )
289294 relocate(" org.ccil.cowan.tagsoup" , " dev.dediamondpro.resourcify.libs.tagsoup" )
290295 }
291- remapJar {
292- input.set(shadowJar.get().archiveFile)
293- finalizedBy(" copyJar" )
294- if (mcPlatform.isNeoForge) {
295- atAccessWideners.add(" $accesWidener .accesswidener" )
296+ if (mcPlatform.isObfuscated) {
297+ named<RemapJarTask >(" remapJar" ) {
298+ input.set(named<ShadowJar >(" shadowJar" ).flatMap { it.archiveFile })
299+ finalizedBy(" copyJar" )
300+ if (mcPlatform.isNeoForge) {
301+ atAccessWideners.add(" $accessWidener .accesswidener" )
302+ }
296303 }
304+ } else {
305+ named(" shadowJar" ) { finalizedBy(" copyJar" ) }
297306 }
298307 register<Copy >(" copyJar" ) {
299308 File (" ${project.rootDir} /jars" ).mkdir()
300- from(remapJar.get().archiveFile )
309+ from(outputJar )
301310 into(" ${project.rootDir} /jars" )
302311 }
303312 clean { delete(" ${project.rootDir} /jars" ) }
@@ -306,7 +315,7 @@ tasks {
306315 " id" to mod_id,
307316 " name" to mod_name,
308317 " version" to mod_version,
309- " aw" to accesWidener ,
318+ " aw" to accessWidener ,
310319 " mixinPath" to mixinPath,
311320 " mcVersion" to compatibleMcVersion.get(mcPlatform).getLoaderRange(mcPlatform),
312321 " minNeoForgeVersion" to minimumNeoForgeVersion.get(mcPlatform)
0 commit comments