diff options
author | Linnea Gräf <nea@nea.moe> | 2024-06-19 00:08:30 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-06-19 00:08:30 +0200 |
commit | 4d778b97ee33485af5236ad6bdfdd2949fd69cc2 (patch) | |
tree | 749fb202c133036d954a8fdbcfdea25750721cb2 | |
parent | a453cc833f52cf1ccd52288edb73c6f0fbc0c7cc (diff) | |
download | archenemy-4d778b97ee33485af5236ad6bdfdd2949fd69cc2.tar.gz archenemy-4d778b97ee33485af5236ad6bdfdd2949fd69cc2.tar.bz2 archenemy-4d778b97ee33485af5236ad6bdfdd2949fd69cc2.zip |
fix stuff for pauline
22 files changed, 345 insertions, 85 deletions
@@ -3,3 +3,4 @@ # Ignore Gradle build output directory build +.idea
\ No newline at end of file diff --git a/archenemyexample/build.gradle.kts b/archenemyexample/build.gradle.kts index 7ae9646..ca4313a 100644 --- a/archenemyexample/build.gradle.kts +++ b/archenemyexample/build.gradle.kts @@ -1,75 +1,100 @@ import moe.nea.archenemy.MCSide plugins { - kotlin("multiplatform") version "1.9.10" + kotlin("multiplatform") version "1.9.22" id("moe.nea.archenemy.mojang") } repositories { mavenCentral() maven("https://maven.fabricmc.net") + maven("https://repo.nea.moe/releases") + mavenLocal() } -val minecraftClient = mojang.minecraft("1.20.2", MCSide.CLIENT) as ModuleDependency -val minecraftServer = 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.intermediaryMappings("1.20.2") +kotlin.jvmToolchain(8) val whateverAttribute = Attribute.of("whatever", String::class.java) -kotlin { - val allJvm by sourceSets.creating { - this.dependencies { - } +val allJvm by kotlin.sourceSets.creating { + this.dependencies { } - jvm("forge") { - attributes.attribute(whateverAttribute, "forge") - compilations.named("main").get().run { - defaultSourceSet.dependsOn(allJvm) - this.dependencies { - implementation( - mojang.mapJar( - minecraftClient, - officialMappings, - "official", - "named" - ) - ) - } +} +val forge = kotlin.jvm("forge") { + attributes.attribute(whateverAttribute, "forge") + compilations.named("main").get().run { + defaultSourceSet.dependsOn(allJvm) + this.dependencies { + val mcpMappings = mojang.yarnMappings(dependencies.create("moe.nea.mcp:mcp-yarn:1.8.9:v2")) + val minecraftClient = mojang.minecraft("1.8.9", MCSide.CLIENT) + val mappedClient = mojang.mapJar(minecraftClient, mcpMappings, "official", "named") + implementation(mappedClient) + implementation("net.minecraft:launchwrapper:1.12") + mojang.libraries("1.8.9").forEach(::implementation) } } - jvm("fabric") { - attributes.attribute(whateverAttribute, "fabric") - compilations.named("main").get().run { - defaultSourceSet.dependsOn(allJvm) - this.dependencies { - val intermediaryClient = mojang.mapJar( - minecraftClient, - intermediaryMappings, - "official", - "intermediary" - ) - val intermediaryServer = mojang.mapJar( - minecraftServer, - intermediaryMappings, - "official", - "intermediary" - ) - val thingy = mojang.mergeJar( - intermediaryClient, intermediaryServer - ) - implementation( - mojang.mapJar( - thingy as ModuleDependency, - yarnMappings, - "intermediary", - "named" - ) +} +val mainForge = forge.compilations.getByName("main") +val fabric = kotlin.jvm("fabric") { + attributes.attribute(whateverAttribute, "fabric") + compilations.named("main").get().run { + defaultSourceSet.dependsOn(allJvm) + this.dependencies { + val minecraftClient = mojang.minecraft("1.20.2", MCSide.CLIENT) + val minecraftServer = mojang.minecraft("1.20.2", MCSide.SERVER) + val intermediaryMappings = mojang.intermediaryMappings("1.20.2") + val yarnMappings = mojang.yarnMappings(dependencies.create("net.fabricmc:yarn:1.20.2+build.4:v2")) + val intermediaryClient = mojang.mapJar( + minecraftClient, + intermediaryMappings, + "official", + "intermediary" + ) + val intermediaryServer = mojang.mapJar( + minecraftServer, + intermediaryMappings, + "official", + "intermediary" + ) + val thingy = mojang.mergeJar( + intermediaryClient, intermediaryServer + ) + implementation( + mojang.mapJar( + thingy, + yarnMappings, + "intermediary", + "named" ) - } + ) } } } +tasks.create("runForge189", JavaExec::class) { + description = "Run Forge 1.8.9" + group = ApplicationPlugin.APPLICATION_GROUP + mainClass.set("net.minecraft.launchwrapper.Launch") + val downloadTask = archenemyShared.getDownloadAssetsTask("1.8.9") + dependsOn(downloadTask) + classpath(mainForge.runtimeDependencyFiles, tasks.getByName("forgeJar")) + javaLauncher.set(javaToolchains.launcherFor { + this.languageVersion.set(JavaLanguageVersion.of(8)) + }) + val runFolder = project.file("run") + runFolder.mkdirs() + workingDir(runFolder) + doFirst { + args( + "--assetDir", + downloadTask.getAssetDir().absolutePath, + "--assetIndex", + downloadTask.getAssetIndex(), + "--accessToken", + "undefined", + "--gameDir", + runFolder.absolutePath, + "--tweakClass", + "moe.nea.aee.forge.Tweaker" + ) + } +} diff --git a/archenemyexample/gradle.properties b/archenemyexample/gradle.properties new file mode 100644 index 0000000..fd5048b --- /dev/null +++ b/archenemyexample/gradle.properties @@ -0,0 +1 @@ +kotlin.mpp.applyDefaultHierarchyTemplate=false diff --git a/archenemyexample/gradle/wrapper/gradle-wrapper.properties b/archenemyexample/gradle/wrapper/gradle-wrapper.properties index a595206..0d18421 100644 --- a/archenemyexample/gradle/wrapper/gradle-wrapper.properties +++ b/archenemyexample/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/archenemyexample/run/logs/2023-12-20-1.log.gz b/archenemyexample/run/logs/2023-12-20-1.log.gz Binary files differnew file mode 100644 index 0000000..1794cf3 --- /dev/null +++ b/archenemyexample/run/logs/2023-12-20-1.log.gz diff --git a/archenemyexample/run/logs/latest.log b/archenemyexample/run/logs/latest.log new file mode 100644 index 0000000..585e475 --- /dev/null +++ b/archenemyexample/run/logs/latest.log @@ -0,0 +1,24 @@ +[16:58:57] [main/INFO]: Loading tweak class name moe.nea.aee.forge.Tweaker +[16:58:57] [main/INFO]: Using primary tweak class name moe.nea.aee.forge.Tweaker +[16:58:57] [main/INFO]: Calling tweak class moe.nea.aee.forge.Tweaker +[16:58:57] [main/INFO]: Launching wrapped minecraft {net.minecraft.client.main.Main} +[16:58:57] [main/ERROR]: Unable to launch +java.lang.reflect.InvocationTargetException + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_302] + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_302] + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_302] + at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_302] + at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] + at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] +Caused by: java.lang.UnsatisfiedLinkError: no lwjgl64 in java.library.path + at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) ~[?:1.8.0_302] + at java.lang.Runtime.loadLibrary0(Runtime.java:871) ~[?:1.8.0_302] + at java.lang.System.loadLibrary(System.java:1124) ~[?:1.8.0_302] + at org.lwjgl.Sys$1.run(Sys.java:72) ~[lwjgl-2.9.4-nightly-20150209.jar:?] + at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_302] + at org.lwjgl.Sys.doLoadLibrary(Sys.java:66) ~[lwjgl-2.9.4-nightly-20150209.jar:?] + at org.lwjgl.Sys.loadLibrary(Sys.java:87) ~[lwjgl-2.9.4-nightly-20150209.jar:?] + at org.lwjgl.Sys.<clinit>(Sys.java:117) ~[lwjgl-2.9.4-nightly-20150209.jar:?] + at net.minecraft.client.Minecraft.getSystemTime(SourceFile:2539) ~[Minecraft.class:?] + at net.minecraft.client.main.Main.main(SourceFile:41) ~[Main.class:?] + ... 6 more diff --git a/archenemyexample/settings.gradle.kts b/archenemyexample/settings.gradle.kts index b538163..b50251b 100644 --- a/archenemyexample/settings.gradle.kts +++ b/archenemyexample/settings.gradle.kts @@ -5,5 +5,7 @@ pluginManagement { gradlePluginPortal() maven("https://maven.fabricmc.net") maven("https://maven.neoforged.net/releases") + maven("https://repo.nea.moe/releases") + mavenLocal() } }
\ No newline at end of file diff --git a/archenemyexample/src/allJvm/kotlin/moe/nea/test/TestClass.kt b/archenemyexample/src/allJvm/kotlin/moe/nea/test/TestClass.kt new file mode 100644 index 0000000..9d72fcc --- /dev/null +++ b/archenemyexample/src/allJvm/kotlin/moe/nea/test/TestClass.kt @@ -0,0 +1,5 @@ +package moe.nea.test + +expect object TestClass { + fun printTitle() +}
\ No newline at end of file diff --git a/archenemyexample/src/allJvm/kotlin/test.kt b/archenemyexample/src/allJvm/kotlin/test.kt deleted file mode 100644 index 87010a6..0000000 --- a/archenemyexample/src/allJvm/kotlin/test.kt +++ /dev/null @@ -1,9 +0,0 @@ -expect fun doStuff(args: Int) - -fun callDoStuff() { - doStuff(1) -} - - - - diff --git a/archenemyexample/src/fabricMain/kotlin/doStuff.kt b/archenemyexample/src/fabricMain/kotlin/doStuff.kt deleted file mode 100644 index fc163c2..0000000 --- a/archenemyexample/src/fabricMain/kotlin/doStuff.kt +++ /dev/null @@ -1,7 +0,0 @@ -import net.minecraft.client.MinecraftClient -import net.minecraft.server.dedicated.DedicatedServer - -actual fun doStuff(args: Int) { - val client = MinecraftClient.getInstance() - val dedicated: DedicatedServer = TODO() -}
\ No newline at end of file diff --git a/archenemyexample/src/fabricMain/kotlin/moe/nea/test/TestClass.fabric.kt b/archenemyexample/src/fabricMain/kotlin/moe/nea/test/TestClass.fabric.kt new file mode 100644 index 0000000..210bbc7 --- /dev/null +++ b/archenemyexample/src/fabricMain/kotlin/moe/nea/test/TestClass.fabric.kt @@ -0,0 +1,9 @@ +package moe.nea.test + +import net.minecraft.client.MinecraftClient + +actual object TestClass { + actual fun printTitle() { + println(MinecraftClient.getInstance().currentScreen?.toString() ?: "no screen") + } +}
\ No newline at end of file diff --git a/archenemyexample/src/fabricMain/kotlin/test.kt b/archenemyexample/src/fabricMain/kotlin/test.kt deleted file mode 100644 index e69de29..0000000 --- a/archenemyexample/src/fabricMain/kotlin/test.kt +++ /dev/null diff --git a/archenemyexample/src/forgeMain/kotlin/doStuff.kt b/archenemyexample/src/forgeMain/kotlin/doStuff.kt deleted file mode 100644 index d370de8..0000000 --- a/archenemyexample/src/forgeMain/kotlin/doStuff.kt +++ /dev/null @@ -1,5 +0,0 @@ -import net.minecraft.client.Minecraft - -actual fun doStuff(args: Int) { - val client = Minecraft.getInstance() -}
\ No newline at end of file diff --git a/archenemyexample/src/forgeMain/kotlin/moe/nea/aee/forge/Main.kt b/archenemyexample/src/forgeMain/kotlin/moe/nea/aee/forge/Main.kt new file mode 100644 index 0000000..141949e --- /dev/null +++ b/archenemyexample/src/forgeMain/kotlin/moe/nea/aee/forge/Main.kt @@ -0,0 +1,21 @@ +package moe.nea.aee.forge + +import net.minecraft.launchwrapper.ITweaker +import net.minecraft.launchwrapper.LaunchClassLoader +import java.io.File + +class Tweaker : ITweaker { + override fun acceptOptions(args: MutableList<String>?, gameDir: File?, assetsDir: File?, profile: String?) { + } + + override fun injectIntoClassLoader(classLoader: LaunchClassLoader) { + } + + override fun getLaunchTarget(): String { + return "net.minecraft.client.main.Main" + } + + override fun getLaunchArguments(): Array<String> { + return arrayOf() + } +} diff --git a/archenemyexample/src/forgeMain/kotlin/moe/nea/test/TestClass.forge.kt b/archenemyexample/src/forgeMain/kotlin/moe/nea/test/TestClass.forge.kt new file mode 100644 index 0000000..74e76b7 --- /dev/null +++ b/archenemyexample/src/forgeMain/kotlin/moe/nea/test/TestClass.forge.kt @@ -0,0 +1,9 @@ +package moe.nea.test + +import net.minecraft.client.Minecraft + +actual object TestClass { + actual fun printTitle() { + println(Minecraft.getMinecraft().currentScreen?.toString() ?: "no screen") + } +}
\ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a595206..0d18421 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 35f1832..64f3df3 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -1,17 +1,18 @@ plugins { `java-gradle-plugin` - kotlin("jvm") version "1.8.0" - kotlin("plugin.serialization") version "1.8.0" + kotlin("jvm") version "1.9.22" + kotlin("plugin.serialization") version "1.9.22" } repositories { mavenCentral() maven("https://maven.neoforged.net/releases") maven("https://maven.fabricmc.net") + maven("https://repo.nea.moe/releases") } dependencies { - implementation("net.neoforged:artifactural:3.0.17") + implementation("net.neoforged:artifactural:4.0.0") implementation(platform("org.jetbrains.kotlin:kotlin-bom")) implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2") 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 e1a8bfe..d27f948 100644 --- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt @@ -47,7 +47,7 @@ abstract class ArchenemyMojangExtension(val project: Project) { fun officialMappings(version: String, side: MCSide): MappingDependency { _registerMinecraftProvider val dependency by lazy { - project.dependencies.create( + realize( sharedExtension.minecraftProvider.getMappingsDependencyCoordinate( MinecraftProvider.MinecraftCoordinate( version, @@ -56,7 +56,14 @@ abstract class ArchenemyMojangExtension(val project: Project) { ) ) } - return OfficialMappingDependency(side, version, project.providers.provider { dependency }) + return OfficialMappingDependency(side, version, project.providers.provider { dependency }).also { it.get() } + } + + fun libraries(version: String): List<String> { + return sharedExtension.getDownloadVersionMetadataTask(version) + .getVersionMetadataNow().libraries + .map { it.name } + .filter { !it.contains("twitch-platform") && !it.contains("twitch-external-platform") } } fun intermediaryMappings(version: String): MappingDependency { @@ -70,7 +77,7 @@ abstract class ArchenemyMojangExtension(val project: Project) { base as ModuleDependency overlay as ModuleDependency _registerMinecraftProvider - return project.dependencies.create( + return realize( mergedRepositoryProvider.getCoordinate( MergedRepositoryProvider.Coordinate(base, overlay) ) @@ -85,7 +92,7 @@ abstract class ArchenemyMojangExtension(val project: Project) { ): Dependency { dependency as ModuleDependency _registerMinecraftProvider - return project.dependencies.create( + return realize( mappedRepositoryProvider.getDependencyCoordiante( MappedRepositoryProvider.MappedCoordinates( dependency, mappings, sourceNamespace, destinationNamespace @@ -96,7 +103,7 @@ abstract class ArchenemyMojangExtension(val project: Project) { fun minecraft(version: String, side: MCSide): Dependency { _registerMinecraftProvider - return project.dependencies.create( + return realize( sharedExtension.minecraftProvider.getDependencyCoordinate( MinecraftProvider.MinecraftCoordinate( version, @@ -106,6 +113,15 @@ abstract class ArchenemyMojangExtension(val project: Project) { ) } + fun realize(dependency: String): Dependency { + return realize(project.dependencies.create(dependency)) + } + + fun realize(dependency: Dependency): Dependency { + project.configurations.detachedConfiguration(dependency).resolve() + return dependency + } + fun getLocalCacheDirectory(): File { return sharedExtension.getLocalCacheDirectory().resolve("projectspecific") .resolve(if (project == project.rootProject) "__root" else project.path.replace(":", "_")) diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt index 950446d..1e5239b 100644 --- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemySharedExtension.kt @@ -16,5 +16,27 @@ abstract class ArchenemySharedExtension(val rootProject: Project) { return rootProject.tasks.getByName("downloadMinecraftVersionManifest") as DownloadMinecraftVersionManifest } + fun getDownloadVersionMetadataTask(version: String): DownloadVersionMetadata { + val taskName = "downloadMinecraftVersionMetadata$version" + val task = rootProject.tasks.findByName(taskName) + if (task != null) { + return task as DownloadVersionMetadata + } + return rootProject.tasks.create(taskName, DownloadVersionMetadata::class.java, version) + } + + fun getDownloadAssetsTask(version: String): DownloadAssets { + val taskName = "downloadMinecraftAssets$version" + val task = rootProject.tasks.findByName(taskName) + if (task != null) { + return task as DownloadAssets + } + return rootProject.tasks.create(taskName, DownloadAssets::class.java, version) + } + + fun getGlobalCacheDirectory(): File { + return rootProject.gradle.gradleUserHomeDir.resolve("caches/archenemy") + } + val minecraftProvider = MinecraftProvider(this) }
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadAssets.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadAssets.kt new file mode 100644 index 0000000..335ac30 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadAssets.kt @@ -0,0 +1,74 @@ +package moe.nea.archenemy.mojang + +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream +import moe.nea.archenemy.util.DownloadUtils +import moe.nea.archenemy.util.sharedExtension +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.TaskAction +import java.net.URL +import javax.inject.Inject + +abstract class DownloadAssets @Inject constructor( + @get:Input + val version: String +) : DefaultTask() { + + + init { + dependsOn(project.sharedExtension.getDownloadVersionMetadataTask(version)) + } + + @Serializable + data class AssetIndexList( + val objects: Map<String, AssetIndexFile> + ) + + @Serializable + data class AssetIndexFile( + val hash: String, + val size: Long, + ) + + @Internal + fun getAssetDir() = + project.sharedExtension + .getGlobalCacheDirectory() + .resolve("assets") + + @Internal + fun getAssetIndex() = + project.sharedExtension + .getDownloadVersionMetadataTask(version) + .getVersionMetadataNow() + .assetIndex + + @TaskAction + fun execute() { + val manifest = + project.sharedExtension + .getDownloadVersionMetadataTask(version) + .getVersionMetadata() + val indexFile = getAssetDir() + .resolve("indexes") + .resolve(manifest.assetIndex.id + ".json") + DownloadUtils.downloadFile(URL(manifest.assetIndex.url), manifest.assetIndex.sha1, indexFile) + val assetIndexList: AssetIndexList = indexFile.inputStream().use(Json::decodeFromStream) + for ((path, entry) in assetIndexList.objects) { + downloadAsset(entry) + } + } + + private fun downloadAsset(entry: AssetIndexFile) { + val prefix = entry.hash.substring(0, 2) + val file = getAssetDir().resolve("objects").resolve(prefix).resolve(entry.hash) + DownloadUtils.downloadFile( + URL("https://resources.download.minecraft.net/$prefix/${entry.hash}"), + entry.hash, + file + ) + } +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadVersionMetadata.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadVersionMetadata.kt new file mode 100644 index 0000000..6c900c3 --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/DownloadVersionMetadata.kt @@ -0,0 +1,64 @@ +package moe.nea.archenemy.mojang + +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream +import moe.nea.archenemy.util.DownloadUtils +import org.gradle.api.DefaultTask +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction +import java.net.URL +import javax.inject.Inject + +abstract class DownloadVersionMetadata @Inject constructor( + @get:Input + val version: String, +) : DefaultTask() { + @get:OutputFile + abstract val file: RegularFileProperty + + + init { + file.convention(project.layout.buildDirectory.file("version-metadata/$version")).finalizeValue() + dependsOn( + project.extensions.getByType(ArchenemySharedExtension::class.java) + .getDownloadMinecraftVersionManifestTask() + ) + } + + companion object { + private val json = Json { ignoreUnknownKeys = true } + } + + @TaskAction + fun downloadVersion() { + val manifest = + project.extensions.getByType(ArchenemySharedExtension::class.java).getDownloadMinecraftVersionManifestTask() + .getManifestNow() + val versionManifestUrl = manifest.versions.find { it.id == version }!!.url + val parts = versionManifestUrl.split("/") + val hash = if (parts.size == 7 && parts[5].length == 40) { + parts[5] + } else { + error("uhhh hash not found") + } + DownloadUtils.downloadFile( + URL(versionManifestUrl), + hash, + file.get().asFile + ) + } + + @Internal + fun getVersionMetadata(): MojangVersionMetadata { + return file.get().asFile.inputStream().use(json::decodeFromStream) + } + + @Internal + fun getVersionMetadataNow(): MojangVersionMetadata { + project.objects.fileCollection().from(file).files + return getVersionMetadata() + } +}
\ No newline at end of file diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/util/ext.kt b/plugin/src/main/kotlin/moe/nea/archenemy/util/ext.kt new file mode 100644 index 0000000..ca0f93f --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/util/ext.kt @@ -0,0 +1,7 @@ +package moe.nea.archenemy.util + +import moe.nea.archenemy.mojang.ArchenemySharedExtension +import org.gradle.api.Project + +val Project.sharedExtension + get() = project.extensions.getByType(ArchenemySharedExtension::class.java)
\ No newline at end of file |