summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2023-12-10 19:38:18 +0100
committerLinnea Gräf <nea@nea.moe>2023-12-10 19:38:18 +0100
commitc8c3959ff81de9052c4383540756687dbd2b5a84 (patch)
tree30b1dbe25f758a5a2bad6c52979d99fa197a0372
parentcffdbe65b993a9ba81c30e4345e1a22f3cabbff2 (diff)
downloadarchenemy-c8c3959ff81de9052c4383540756687dbd2b5a84.tar.gz
archenemy-c8c3959ff81de9052c4383540756687dbd2b5a84.tar.bz2
archenemy-c8c3959ff81de9052c4383540756687dbd2b5a84.zip
Add yarn support
-rw-r--r--archenemyexample/build.gradle.kts47
-rw-r--r--archenemyexample/src/fabricMain/kotlin/doStuff.kt4
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt4
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappedRepositoryProvider.kt3
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappingDependency.kt1
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/YarnMappingDependency.kt75
6 files changed, 121 insertions, 13 deletions
diff --git a/archenemyexample/build.gradle.kts b/archenemyexample/build.gradle.kts
index 6ed1dbe..946264e 100644
--- a/archenemyexample/build.gradle.kts
+++ b/archenemyexample/build.gradle.kts
@@ -7,8 +7,16 @@ plugins {
repositories {
mavenCentral()
+ maven("https://maven.fabricmc.net")
}
+val minecraft = mojang.minecraft("1.20.2", MCSide.CLIENT) as ModuleDependency
+val officialMappings = mojang.officialMappings(
+ "1.20.2", MCSide.CLIENT
+)
+val yarnMappings = mojang.yarnMappings(dependencies.create("net.fabricmc:yarn:1.20.2+build.4:v2"))
+val intermediaryMappings = mojang.yarnMappings(dependencies.create("net.fabricmc:intermediary:1.20.2:v2"))
+val whateverAttribute = Attribute.of("whatever", String::class.java)
kotlin {
val allJvm by sourceSets.creating {
this.dependencies {
@@ -16,23 +24,42 @@ kotlin {
}
jvm("forge") {
+ attributes.attribute(whateverAttribute, "forge")
compilations.named("main").get().run {
defaultSourceSet.dependsOn(allJvm)
this.dependencies {
- val mappedMinecraft = mojang.mapJar(
- mojang.minecraft("1.20.2", MCSide.CLIENT) as ModuleDependency,
- mojang.officialMappings("1.20.2", MCSide.CLIENT),
+ implementation(
+ mojang.mapJar(
+ minecraft,
+ officialMappings,
+ "official",
+ "named"
+ )
+ )
+ }
+ }
+ }
+ jvm("fabric") {
+ attributes.attribute(whateverAttribute, "fabric")
+ compilations.named("main").get().run {
+ defaultSourceSet.dependsOn(allJvm)
+ this.dependencies {
+ val thingy = mojang.mapJar(
+ minecraft,
+ intermediaryMappings,
"official",
- "named"
+ "intermediary"
+ )
+ implementation(
+ mojang.mapJar(
+ thingy as ModuleDependency,
+ yarnMappings,
+ "intermediary",
+ "named"
+ )
)
- implementation(mappedMinecraft)
}
}
}
-// jvm("fabric") {
-// compilations.named("main").get().run {
-// defaultSourceSet.dependsOn(allJvm)
-// }
-// }
}
diff --git a/archenemyexample/src/fabricMain/kotlin/doStuff.kt b/archenemyexample/src/fabricMain/kotlin/doStuff.kt
index 659bc2b..d88a17e 100644
--- a/archenemyexample/src/fabricMain/kotlin/doStuff.kt
+++ b/archenemyexample/src/fabricMain/kotlin/doStuff.kt
@@ -1,3 +1,5 @@
-actual fun doStuff(args: Int) {
+import net.minecraft.client.MinecraftClient
+actual fun doStuff(args: Int) {
+ val client = MinecraftClient.getInstance()
} \ No newline at end of file
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt
index b80fe89..db667ae 100644
--- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt
@@ -32,6 +32,10 @@ abstract class ArchenemyMojangExtension(val project: Project) {
private val mappedRepositoryProvider = MappedRepositoryProvider(this)
+ fun yarnMappings(dependency: Dependency): MappingDependency {
+ dependency as ModuleDependency
+ return YarnMappingDependency(this, dependency)
+ }
fun officialMappings(version: String, side: MCSide): MappingDependency {
_registerMinecraftProvider
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappedRepositoryProvider.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappedRepositoryProvider.kt
index ed158b5..1e87b54 100644
--- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappedRepositoryProvider.kt
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappedRepositoryProvider.kt
@@ -39,7 +39,8 @@ class MappedRepositoryProvider(
fun getDependencyCoordiante(coordinates: MappedCoordinates): String {
providers[coordinates.transformerHash] = coordinates
- return "archenemy.remapped.${coordinates.transformerHash}.${coordinates.mappings.title()}-${coordinates.to}.${coordinates.dependency.group}:${coordinates.dependency.name}:${coordinates.dependency.version}"
+ //-${coordinates.to}.${coordinates.dependency.group}
+ return "archenemy.remapped.${coordinates.transformerHash}.${coordinates.mappings.title()}:${coordinates.dependency.name}:${coordinates.dependency.version}"
}
fun getDependencyCoordiante(
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappingDependency.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappingDependency.kt
index 76f109c..292db4f 100644
--- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappingDependency.kt
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/MappingDependency.kt
@@ -1,6 +1,5 @@
package moe.nea.archenemy.mojang
-import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.provider.Provider
import java.io.File
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/YarnMappingDependency.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/YarnMappingDependency.kt
new file mode 100644
index 0000000..46b428e
--- /dev/null
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/YarnMappingDependency.kt
@@ -0,0 +1,75 @@
+package moe.nea.archenemy.mojang
+
+import moe.nea.archenemy.util.update
+import moe.nea.archenemy.util.updateField
+import net.fabricmc.tinyremapper.OutputConsumerPath
+import net.fabricmc.tinyremapper.TinyRemapper
+import net.fabricmc.tinyremapper.TinyUtils
+import org.gradle.api.artifacts.Dependency
+import org.gradle.api.artifacts.ModuleDependency
+import org.gradle.api.provider.Provider
+import java.io.BufferedReader
+import java.io.File
+import java.io.StringReader
+import java.security.MessageDigest
+import java.util.zip.ZipFile
+
+class YarnMappingDependency(
+ val extension: ArchenemyMojangExtension,
+ val dependency: ModuleDependency
+) : MappingDependency,
+ Provider<Dependency> by extension.project.provider({ dependency }) {
+ var tinySource: String? = null
+
+ init {
+ val artifact = dependency.artifacts.single()
+ require(artifact.classifier == "v2")
+ require(artifact.extension == "jar")
+ }
+
+ override fun updateHash(digest: MessageDigest) {
+ digest.update("yarn")
+ digest.updateField("group", dependency.group ?: "null")
+ digest.updateField("name", dependency.name)
+ digest.updateField("version", dependency.version ?: "null")
+ digest.updateField("classifier", dependency.artifacts.single().classifier ?: "")
+ digest.updateField("extension", dependency.artifacts.single().extension ?: "")
+ }
+
+ override fun title(): String {
+ return "yarn-${dependency.group?.replace(".", "-")}-${dependency.name}-${dependency.version?.replace(".", "-")}"
+ }
+
+ override fun resolveMappingsOnce(extension: ArchenemyMojangExtension) {
+ if (tinySource != null) return
+ val v2Jar = extension.project.configurations.detachedConfiguration(get()).resolve().single()
+ ZipFile(v2Jar).use { zip ->
+ val ze = zip.getEntry("mappings/mappings.tiny")
+ zip.getInputStream(ze).use { inp ->
+ tinySource = inp.reader().readText()
+ }
+ }
+ }
+
+ override fun applyMapping(
+ sourceFile: File,
+ targetFile: File,
+ sourceNameSpace: String,
+ targetNameSpace: String
+ ) {
+ val remapper = TinyRemapper.newRemapper()
+ .withMappings(
+ TinyUtils.createTinyMappingProvider(
+ BufferedReader(StringReader(tinySource ?: error("Mappings have never been resolved"))),
+ sourceNameSpace,
+ targetNameSpace,
+ )
+ )
+ .build()
+ OutputConsumerPath.Builder(targetFile.toPath()).build().use { output ->
+ remapper.readInputs(sourceFile.toPath())
+ remapper.apply(output)
+ }
+ remapper.finish()
+ }
+} \ No newline at end of file