From 5f57cb26fdb2122e4ecb51c4c207691c2c6b2d45 Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Thu, 7 Nov 2024 03:47:43 -0600 Subject: [PATCH 1/6] Initial Loom port --- build.gradle.kts | 6 +- version.gradle.kts | 327 +++++++++++++++++---------------------------- 2 files changed, 126 insertions(+), 207 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d116bf2..3b97ccc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("io.github.gaming32.gradle.preprocess-root") version "0.4.4" - id("xyz.wagyourtail.unimined") version "1.3.9" apply false + id("dev.architectury.loom") version "1.7.414" apply false } repositories { @@ -37,3 +37,7 @@ preprocess { fabric11904.link(fabric11902) fabric11902.link(forge11902) } + +subprojects { + extra["loom.platform"] = name.substringAfter('-') +} diff --git a/version.gradle.kts b/version.gradle.kts index 4dd4cf7..2ba5bfe 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -1,29 +1,14 @@ import com.replaymod.gradle.preprocess.PreprocessTask -import groovy.lang.GroovyObjectSupport -import org.jetbrains.kotlin.daemon.common.toHexString -import xyz.wagyourtail.unimined.api.mapping.task.ExportMappingsTask -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask -import xyz.wagyourtail.unimined.internal.mapping.MappingsProvider -import xyz.wagyourtail.unimined.internal.mapping.task.ExportMappingsTaskImpl -import xyz.wagyourtail.unimined.internal.minecraft.resolver.MinecraftDownloader -import xyz.wagyourtail.unimined.util.capitalized -import xyz.wagyourtail.unimined.util.sourceSets -import java.net.NetworkInterface -import java.nio.file.Path -import java.util.UUID plugins { java `maven-publish` id("io.github.gaming32.gradle.preprocess") - id("xyz.wagyourtail.unimined") + id("dev.architectury.loom") id("com.modrinth.minotaur") version "2.8.7" - id("xyz.wagyourtail.jvmdowngrader") version "1.1.2-SNAPSHOT" + id("xyz.wagyourtail.jvmdowngrader") version "1.1.2" } -fun Any.setGroovyProperty(name: String, value: Any) = withGroovyBuilder { metaClass }.setProperty(this, name, value) -fun Any.getGroovyProperty(name: String): Any = withGroovyBuilder { metaClass }.getProperty(this, name)!! - group = "io.github.gaming32" val modVersion = project.properties["mod.version"] as String @@ -65,20 +50,93 @@ tasks.compileJava { options.compilerArgs.add("-Xlint:all") } -unimined.minecraft { - version(mcVersionString) - if ((mcVersion != 1_20_01 || !isForge) && mcVersion < 1_20_05) { - side("client") - } +//unimined.minecraft { +// val mcJavaVersion = (minecraftData as MinecraftDownloader).metadata.javaVersion +// +// if (mcJavaVersion < java.sourceCompatibility) { +// println("Classes need downgrading to Java $mcJavaVersion") +// +// tasks.downgradeJar { +// downgradeTo = mcJavaVersion +// } +// tasks.shadeDowngradedApi { +// downgradeTo = mcJavaVersion +// shadePath = { "io/github/gaming32/worldhost" } +// } +// +// defaultRemapJar = false +// remap(tasks.shadeDowngradedApi.get(), "remapJar") +// tasks.assemble.get().dependsOn("remapJar") +// } + +// runs { +// config("client") { +// javaVersion = JavaVersion.VERSION_21 +// } +// +// val usernameSuffix = NetworkInterface.getNetworkInterfaces() +// .nextElement() +// .hardwareAddress +// .toHexString() +// .substring(0, 10) +// for (name in listOf("host", "joiner")) { +// val runName = "test${name.capitalized()}" +// val user = name.uppercase() +// val provider = (minecraftData as MinecraftDownloader).provider +// provider.provideRunClientTask(runName, file("run/$runName")) +// config(runName) { +// description = "Test $user" +// val username = "$user$usernameSuffix" +// properties["auth_player_name"] = { username } +// properties["auth_uuid"] = { UUID.nameUUIDFromBytes("OfflinePlayer:$username".encodeToByteArray()).toString() } +// jvmArgs( +// "-Dworld-host-testing.enabled=true", +// "-Dworld-host-testing.user=$user", +// "-Ddevauth.enabled=false" +// ) +// javaVersion = JavaVersion.VERSION_21 +// } +// } +// } +//} - mappings { - intermediary() - if (mcVersion <= 1_19_00) { - searge() +repositories { + maven("https://maven.quiltmc.org/repository/release/") + maven("https://maven.terraformersmc.com/releases") + maven("https://maven.isxander.dev/releases") + maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1") + maven("https://repo.viaversion.com") + maven("https://maven.wagyourtail.xyz/snapshots") + maven("https://maven.maxhenkel.de/repository/public") + maven("https://api.modrinth.com/maven") { + content { + includeGroup("maven.modrinth") } - mojmap { - dependsOn("intermediary") - onlyExistingSrc() + } + maven("https://jitpack.io") +} + +println("loaderName: $loaderName") +println("mcVersion: $mcVersion") + +//val forgeJarJar: Configuration by configurations.creating { +// isTransitive = false +//} + +//val modCompileOnly: Configuration by configurations.creating { +// configurations.getByName("compileOnly").extendsFrom(this) +//} + +//val modRuntimeOnly: Configuration by configurations.creating { +// configurations.getByName("runtimeOnly").extendsFrom(this) +//} + +dependencies { + minecraft("com.mojang:minecraft:$mcVersionString") + @Suppress("UnstableApiUsage") + mappings(loom.layered { + officialMojangMappings { + nameSyntheticMembers = true } when { mcVersion >= 1_21_00 -> "1.21:2024.07.28" @@ -95,171 +153,28 @@ unimined.minecraft { mcVersion >= 1_16_00 -> "1.16.5:2022.03.06" else -> null }?.let { - parchment(it.substringBefore(":"), it.substringAfter(":")) + parchment("org.parchmentmc.data:parchment-$it@zip") } - - devFallbackNamespace("official") - } + }) when { - isFabric -> fabric { - loader("0.16.7") - } - isForge -> minecraftForge { - loader(when(mcVersion) { + isFabric -> modImplementation("net.fabricmc:fabric-loader:0.16.7") + isForge -> + when (mcVersion) { 1_20_01 -> "47.1.3" 1_19_04 -> "45.1.0" 1_19_02 -> "43.2.0" else -> throw IllegalStateException("Unknown Forge version for $mcVersionString") - }) - mixinConfig("world-host.mixins.json") - } - isNeoForge -> neoForge { - loader(when (mcVersion) { - 1_21_03 -> "2-beta" - 1_21_01 -> "1" - 1_20_06 -> "115" - 1_20_04 -> "167" + }.let { "forge"("net.minecraftforge:forge:$mcVersionString-$it") } + isNeoForge -> + when (mcVersion) { + 1_21_03 -> "21.3.2-beta" + 1_21_01 -> "21.1.1" + 1_20_06 -> "20.6.115" + 1_20_04 -> "20.4.167" else -> throw IllegalStateException("Unknown NeoForge version for $mcVersionString") - }) - minecraftRemapper.config { - ignoreConflicts(true) - } - } - else -> throw IllegalStateException() - } - - val mcJavaVersion = (minecraftData as MinecraftDownloader).metadata.javaVersion - - if (mcJavaVersion < java.sourceCompatibility) { - println("Classes need downgrading to Java $mcJavaVersion") - - tasks.downgradeJar { - downgradeTo = mcJavaVersion - } - tasks.shadeDowngradedApi { - downgradeTo = mcJavaVersion - shadePath = { "io/github/gaming32/worldhost" } - } - - defaultRemapJar = false - remap(tasks.shadeDowngradedApi.get(), "remapJar") - tasks.assemble.get().dependsOn("remapJar") - } - - runs { - config("client") { - javaVersion = JavaVersion.VERSION_21 - } - - val usernameSuffix = NetworkInterface.getNetworkInterfaces() - .nextElement() - .hardwareAddress - .toHexString() - .substring(0, 10) - for (name in listOf("host", "joiner")) { - val runName = "test${name.capitalized()}" - val user = name.uppercase() - val provider = (minecraftData as MinecraftDownloader).provider - provider.provideRunClientTask(runName, file("run/$runName")) - config(runName) { - description = "Test $user" - val username = "$user$usernameSuffix" - properties["auth_player_name"] = { username } - properties["auth_uuid"] = { UUID.nameUUIDFromBytes("OfflinePlayer:$username".encodeToByteArray()).toString() } - jvmArgs( - "-Dworld-host-testing.enabled=true", - "-Dworld-host-testing.user=$user", - "-Ddevauth.enabled=false" - ) - javaVersion = JavaVersion.VERSION_21 - } - } - } -} -val minecraft = unimined.minecrafts[sourceSets.main.get()] - -// jank hax to pretend to be arch-loom -class LoomGradleExtension : GroovyObjectSupport() { - var mappingConfiguration: Any? = null -} - -val loom = LoomGradleExtension() -extensions.add("loom", loom) -val mappingsConfig = object { - var tinyMappings: Path? = null - var tinyMappingsWithSrg: Path? = null -} -loom.setGroovyProperty("mappingConfiguration", mappingsConfig) -val mappings = minecraft!!.mappings as MappingsProvider -val tinyMappings: File = file("${projectDir}/build/tmp/tinyMappings.tiny").also { file -> - val export = ExportMappingsTaskImpl.ExportImpl(mappings).apply { - location = file - type = ExportMappingsTask.MappingExportTypes.TINY_V2 - setSourceNamespace("official") - setTargetNamespaces(listOf("intermediary", "mojmap")) - renameNs[mappings.getNamespace("mojmap")] = "named" - } - export.validate() - export.exportFunc(mappings.mappingTree) -} -mappingsConfig.setGroovyProperty("tinyMappings", tinyMappings.toPath()) -if (isForge) { - val tinyMappingsWithSrg: File = file("${projectDir}/build/tmp/tinyMappingsWithSrg.tiny").also { file -> - val export = ExportMappingsTaskImpl.ExportImpl(mappings).apply { - location = file - type = ExportMappingsTask.MappingExportTypes.TINY_V2 - setSourceNamespace("official") - setTargetNamespaces(listOf("intermediary", "searge", "mojmap")) - renameNs[mappings.getNamespace("mojmap")] = "named" - renameNs[mappings.getNamespace("searge")] = "srg" - } - export.validate() - export.exportFunc(mappings.mappingTree) - } - mappingsConfig.setGroovyProperty("tinyMappingsWithSrg", tinyMappingsWithSrg.toPath()) -} - -repositories { - maven("https://maven.quiltmc.org/repository/release/") - maven("https://maven.terraformersmc.com/releases") - maven("https://maven.isxander.dev/releases") - maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1") - maven("https://repo.viaversion.com") - maven("https://maven.wagyourtail.xyz/snapshots") - maven("https://maven.maxhenkel.de/repository/public") - maven("https://api.modrinth.com/maven") { - content { - includeGroup("maven.modrinth") - } + }.let { "neoForge"("net.neoforged:neoforge:$it") } } - maven("https://jitpack.io") -} - -println("loaderName: $loaderName") -println("mcVersion: $mcVersion") - -val forgeJarJar: Configuration by configurations.creating { - isTransitive = false -} - -val modCompileOnly: Configuration by configurations.creating { - configurations.getByName("compileOnly").extendsFrom(this) -} - -val modRuntimeOnly: Configuration by configurations.creating { - configurations.getByName("runtimeOnly").extendsFrom(this) -} - -minecraft!!.apply { - mods.remap(modCompileOnly) - mods.remap(modRuntimeOnly) -} - -dependencies { - val include = configurations["include"] - val modImplementation = configurations["modImplementation"] - val minecraftLibraries = configurations["minecraftLibraries"] include(implementation("org.quiltmc.parsers:json:0.3.0")!!) include(implementation("org.semver4j:semver4j:5.3.0")!!) @@ -300,7 +215,7 @@ dependencies { 1_19_02 -> "0.77.0+1.19.2" else -> null }?.let { fapiVersion -> - val resourceLoader = fabricApi.fabricModule("fabric-resource-loader-v0", fapiVersion) + val resourceLoader = fabricApi.module("fabric-resource-loader-v0", fapiVersion) include(modImplementation(resourceLoader)!!) for (module in listOf( @@ -308,7 +223,7 @@ dependencies { "fabric-key-binding-api-v1", "fabric-lifecycle-events-v1" )) { - modRuntimeOnly(fabricApi.fabricModule(module, fapiVersion)) + modRuntimeOnly(fabricApi.module(module, fapiVersion)) } } } @@ -478,25 +393,25 @@ tasks.jar { archiveClassifier = "dev" } -tasks.withType { - if (isForgeLike && !forgeJarJar.isEmpty) { - forgeJarJar.files.forEach { from(zipTree(it)) } - } - manifest { - when { - isForge -> { - attributes["MixinConfigs"] = "world-host.mixins.json" - } - isFabric -> { - attributes["Fabric-Loom-Mixin-Remap-Type"] = "static" - } - } - } - from("$rootDir/LICENSE") - mixinRemap { - disableRefmap() - } -} +//tasks.withType { +// if (isForgeLike && !forgeJarJar.isEmpty) { +// forgeJarJar.files.forEach { from(zipTree(it)) } +// } +// manifest { +// when { +// isForge -> { +// attributes["MixinConfigs"] = "world-host.mixins.json" +// } +// isFabric -> { +// attributes["Fabric-Loom-Mixin-Remap-Type"] = "static" +// } +// } +// } +// from("$rootDir/LICENSE") +// mixinRemap { +// disableRefmap() +// } +//} publishing { publications { From 0c329ef9251b0d0965b617300f9dce1961a396cf Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Thu, 7 Nov 2024 04:29:39 -0600 Subject: [PATCH 2/6] Attempt to re-add downgrading --- version.gradle.kts | 47 ++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/version.gradle.kts b/version.gradle.kts index 2ba5bfe..4f657eb 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -9,6 +9,12 @@ plugins { id("xyz.wagyourtail.jvmdowngrader") version "1.1.2" } +buildscript { + dependencies { + classpath("org.apache.commons:commons-compress:1.26.1") + } +} + group = "io.github.gaming32" val modVersion = project.properties["mod.version"] as String @@ -50,24 +56,29 @@ tasks.compileJava { options.compilerArgs.add("-Xlint:all") } -//unimined.minecraft { -// val mcJavaVersion = (minecraftData as MinecraftDownloader).metadata.javaVersion -// -// if (mcJavaVersion < java.sourceCompatibility) { -// println("Classes need downgrading to Java $mcJavaVersion") -// -// tasks.downgradeJar { -// downgradeTo = mcJavaVersion -// } -// tasks.shadeDowngradedApi { -// downgradeTo = mcJavaVersion -// shadePath = { "io/github/gaming32/worldhost" } -// } -// -// defaultRemapJar = false -// remap(tasks.shadeDowngradedApi.get(), "remapJar") -// tasks.assemble.get().dependsOn("remapJar") -// } +val targetJava = when { + mcVersion >= 1_20_06 -> JavaVersion.VERSION_21 + mcVersion >= 1_18_00 -> JavaVersion.VERSION_17 + mcVersion >= 1_17_00 -> JavaVersion.VERSION_16 + else -> JavaVersion.VERSION_1_8 +} +if (targetJava < java.sourceCompatibility) { + println("Classes need downgrading to Java $targetJava") + + tasks.downgradeJar { + downgradeTo = targetJava + } + + tasks.shadeDowngradedApi { + downgradeTo = targetJava + shadePath = { "io/github/gaming32/worldhost" } + } + + tasks.remapJar { + dependsOn(tasks.shadeDowngradedApi) + inputFile = tasks.shadeDowngradedApi.get().inputFile + } +} // runs { // config("client") { From e3ec28df2d64adc0eb5e14f78064dbb896f386b7 Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Thu, 7 Nov 2024 08:27:28 -0600 Subject: [PATCH 3/6] Make downgrading work --- build.gradle.kts | 2 ++ version.gradle.kts | 12 +++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3b97ccc..a7d264e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,8 @@ plugins { id("io.github.gaming32.gradle.preprocess-root") version "0.4.4" id("dev.architectury.loom") version "1.7.414" apply false + id("com.modrinth.minotaur") version "2.8.7" apply false + id("xyz.wagyourtail.jvmdowngrader") version "1.1.2" apply false } repositories { diff --git a/version.gradle.kts b/version.gradle.kts index 4f657eb..3b46c95 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -5,14 +5,8 @@ plugins { `maven-publish` id("io.github.gaming32.gradle.preprocess") id("dev.architectury.loom") - id("com.modrinth.minotaur") version "2.8.7" - id("xyz.wagyourtail.jvmdowngrader") version "1.1.2" -} - -buildscript { - dependencies { - classpath("org.apache.commons:commons-compress:1.26.1") - } + id("com.modrinth.minotaur") + id("xyz.wagyourtail.jvmdowngrader") } group = "io.github.gaming32" @@ -76,7 +70,7 @@ if (targetJava < java.sourceCompatibility) { tasks.remapJar { dependsOn(tasks.shadeDowngradedApi) - inputFile = tasks.shadeDowngradedApi.get().inputFile + inputFile = tasks.shadeDowngradedApi.get().archiveFile } } From 7d8a15066bb3fa60c9ed76429613c07dcfaf3b42 Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Thu, 7 Nov 2024 08:59:24 -0600 Subject: [PATCH 4/6] Embed license --- version.gradle.kts | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/version.gradle.kts b/version.gradle.kts index 3b46c95..9cbd2b4 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -124,18 +124,6 @@ repositories { println("loaderName: $loaderName") println("mcVersion: $mcVersion") -//val forgeJarJar: Configuration by configurations.creating { -// isTransitive = false -//} - -//val modCompileOnly: Configuration by configurations.creating { -// configurations.getByName("compileOnly").extendsFrom(this) -//} - -//val modRuntimeOnly: Configuration by configurations.creating { -// configurations.getByName("runtimeOnly").extendsFrom(this) -//} - dependencies { minecraft("com.mojang:minecraft:$mcVersionString") @Suppress("UnstableApiUsage") @@ -396,28 +384,9 @@ tasks.processResources { tasks.jar { archiveClassifier = "dev" + from("$rootDir/LICENSE") } -//tasks.withType { -// if (isForgeLike && !forgeJarJar.isEmpty) { -// forgeJarJar.files.forEach { from(zipTree(it)) } -// } -// manifest { -// when { -// isForge -> { -// attributes["MixinConfigs"] = "world-host.mixins.json" -// } -// isFabric -> { -// attributes["Fabric-Loom-Mixin-Remap-Type"] = "static" -// } -// } -// } -// from("$rootDir/LICENSE") -// mixinRemap { -// disableRefmap() -// } -//} - publishing { publications { create("maven") { From 76a509e8e16ee8ee9a5099f3ac6173c009d23400 Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Thu, 7 Nov 2024 09:27:16 -0600 Subject: [PATCH 5/6] Recreate test configs --- version.gradle.kts | 70 ++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/version.gradle.kts b/version.gradle.kts index 9cbd2b4..e09d3c1 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -1,4 +1,7 @@ import com.replaymod.gradle.preprocess.PreprocessTask +import org.jetbrains.kotlin.daemon.common.toHexString +import java.net.NetworkInterface +import java.util.* plugins { java @@ -74,36 +77,43 @@ if (targetJava < java.sourceCompatibility) { } } -// runs { -// config("client") { -// javaVersion = JavaVersion.VERSION_21 -// } -// -// val usernameSuffix = NetworkInterface.getNetworkInterfaces() -// .nextElement() -// .hardwareAddress -// .toHexString() -// .substring(0, 10) -// for (name in listOf("host", "joiner")) { -// val runName = "test${name.capitalized()}" -// val user = name.uppercase() -// val provider = (minecraftData as MinecraftDownloader).provider -// provider.provideRunClientTask(runName, file("run/$runName")) -// config(runName) { -// description = "Test $user" -// val username = "$user$usernameSuffix" -// properties["auth_player_name"] = { username } -// properties["auth_uuid"] = { UUID.nameUUIDFromBytes("OfflinePlayer:$username".encodeToByteArray()).toString() } -// jvmArgs( -// "-Dworld-host-testing.enabled=true", -// "-Dworld-host-testing.user=$user", -// "-Ddevauth.enabled=false" -// ) -// javaVersion = JavaVersion.VERSION_21 -// } -// } -// } -//} +loom { + runs { + getByName("client") { + ideConfigGenerated(true) + runDir = "run/client" + } + remove(getByName("server")) + + val usernameSuffix = NetworkInterface.getNetworkInterfaces() + .nextElement() + .hardwareAddress + .toHexString() + .substring(0, 10) + for (name in listOf("Host", "Joiner")) { + val runName = "test$name" + val user = name.uppercase() + register(runName) { + inherit(getByName("client")) + ideConfigGenerated(false) + + configName = "Test $user" + runDir = "run/$runName" + + val username = "$user$usernameSuffix" + programArgs( + "--username", username, + "--uuid", UUID.nameUUIDFromBytes("OfflinePlayer:$username".encodeToByteArray()).toString() + ) + vmArgs( + "-Dworld-host-testing.enabled=true", + "-Dworld-host-testing.user=$user", + "-Ddevauth.enabled=false" + ) + } + } + } +} repositories { maven("https://maven.quiltmc.org/repository/release/") From 365bcc6abc48797611174d0faefdd9ad641d9338 Mon Sep 17 00:00:00 2001 From: Josiah Glosson Date: Thu, 7 Nov 2024 09:35:44 -0600 Subject: [PATCH 6/6] Switch to static mixin remapper --- version.gradle.kts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/version.gradle.kts b/version.gradle.kts index e09d3c1..cde8e10 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -78,6 +78,11 @@ if (targetJava < java.sourceCompatibility) { } loom { + @Suppress("UnstableApiUsage") + mixin { + useLegacyMixinAp = false + } + runs { getByName("client") { ideConfigGenerated(true)