summaryrefslogtreecommitdiff
path: root/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-06-19 03:37:52 +0200
committerLinnea Gräf <nea@nea.moe>2024-06-19 03:37:52 +0200
commit4b077b1a9c9a262cf730796f3876a86d6fa1064b (patch)
treea660180847b995d607949bc4e950876efdbc7cde /plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt
parent4d778b97ee33485af5236ad6bdfdd2949fd69cc2 (diff)
downloadarchenemy-4b077b1a9c9a262cf730796f3876a86d6fa1064b.tar.gz
archenemy-4b077b1a9c9a262cf730796f3876a86d6fa1064b.tar.bz2
archenemy-4b077b1a9c9a262cf730796f3876a86d6fa1064b.zip
Add more code to make the client run workHEADmaster
Diffstat (limited to 'plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt')
-rw-r--r--plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt248
1 files changed, 131 insertions, 117 deletions
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 d27f948..8c009e0 100644
--- a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt
+++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ArchenemyMojangExtension.kt
@@ -9,122 +9,136 @@ import java.io.File
import java.net.URI
abstract class ArchenemyMojangExtension(val project: Project) {
- val sharedExtension = project.rootProject.extensions.getByType(ArchenemySharedExtension::class.java)
-
- private val _registerMinecraftProvider by lazy {
- GradleRepositoryAdapter.add(
- project.repositories,
- "Minecraft Provider",
- sharedExtension.getLocalCacheDirectory().resolve("minecraft-provider"),
- sharedExtension.minecraftProvider
- )
- GradleRepositoryAdapter.add(
- project.repositories,
- "Minecraft Mapped Provider",
- getLocalCacheDirectory().resolve("minecraft-mapped-provider"),
- mappedRepositoryProvider
- )
- GradleRepositoryAdapter.add(
- project.repositories,
- "Minecraft Merged Provider",
- getLocalCacheDirectory().resolve("minecraft-merged-provider"),
- mergedRepositoryProvider
- )
- project.repositories.maven {
- it.name = "Minecraft Libraries"
- it.url = URI("https://libraries.minecraft.net/")
- }
- }
-
- private val mappedRepositoryProvider = MappedRepositoryProvider(this)
- private val mergedRepositoryProvider = MergedRepositoryProvider(this)
-
- fun yarnMappings(dependency: Dependency): MappingDependency {
- dependency as ModuleDependency
- return YarnMappingDependency(this, dependency)
- }
-
- fun officialMappings(version: String, side: MCSide): MappingDependency {
- _registerMinecraftProvider
- val dependency by lazy {
- realize(
- sharedExtension.minecraftProvider.getMappingsDependencyCoordinate(
- MinecraftProvider.MinecraftCoordinate(
- version,
- side
- )
- )
- )
- }
- 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 {
- return yarnMappings(project.dependencies.create("net.fabricmc:intermediary:$version:v2"))
- }
-
- fun mergeJar(
- base: Dependency,
- overlay: Dependency,
- ): Dependency {
- base as ModuleDependency
- overlay as ModuleDependency
- _registerMinecraftProvider
- return realize(
- mergedRepositoryProvider.getCoordinate(
- MergedRepositoryProvider.Coordinate(base, overlay)
- )
- )
- }
-
- fun mapJar(
- dependency: Dependency,
- mappings: MappingDependency,
- sourceNamespace: String,
- destinationNamespace: String
- ): Dependency {
- dependency as ModuleDependency
- _registerMinecraftProvider
- return realize(
- mappedRepositoryProvider.getDependencyCoordiante(
- MappedRepositoryProvider.MappedCoordinates(
- dependency, mappings, sourceNamespace, destinationNamespace
- )
- )
- )
- }
-
- fun minecraft(version: String, side: MCSide): Dependency {
- _registerMinecraftProvider
- return realize(
- sharedExtension.minecraftProvider.getDependencyCoordinate(
- MinecraftProvider.MinecraftCoordinate(
- version,
- side,
- )
- )
- )
- }
-
- 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(":", "_"))
- }
+ val sharedExtension = project.rootProject.extensions.getByType(ArchenemySharedExtension::class.java)
+
+ private val _registerMinecraftProvider by lazy {
+ GradleRepositoryAdapter.add(
+ project.repositories,
+ "Minecraft Provider",
+ sharedExtension.getLocalCacheDirectory().resolve("minecraft-provider"),
+ sharedExtension.minecraftProvider
+ )
+ GradleRepositoryAdapter.add(
+ project.repositories,
+ "Minecraft Mapped Provider",
+ getLocalCacheDirectory().resolve("minecraft-mapped-provider"),
+ mappedRepositoryProvider
+ )
+ GradleRepositoryAdapter.add(
+ project.repositories,
+ "Minecraft Merged Provider",
+ getLocalCacheDirectory().resolve("minecraft-merged-provider"),
+ mergedRepositoryProvider
+ )
+ project.repositories.maven {
+ it.name = "Minecraft Libraries"
+ it.url = URI("https://libraries.minecraft.net/")
+ }
+ }
+
+ private val mappedRepositoryProvider = MappedRepositoryProvider(this)
+ private val mergedRepositoryProvider = MergedRepositoryProvider(this)
+
+ fun yarnMappings(dependency: Dependency): MappingDependency {
+ dependency as ModuleDependency
+ return YarnMappingDependency(this, dependency)
+ }
+
+ fun officialMappings(version: String, side: MCSide): MappingDependency {
+ _registerMinecraftProvider
+ val dependency by lazy {
+ realize(
+ sharedExtension.minecraftProvider.getMappingsDependencyCoordinate(
+ MinecraftProvider.MinecraftCoordinate(
+ version,
+ side
+ )
+ )
+ )
+ }
+ return OfficialMappingDependency(side, version, project.providers.provider { dependency }).also { it.get() }
+ }
+
+ fun natives(version: String): ExtractNativesTask {
+ val taskName = "extractNatives$version"
+ var extractNativesTask = project.tasks.findByName(taskName)
+ if (extractNativesTask != null) return extractNativesTask as ExtractNativesTask
+
+ extractNativesTask = project.tasks.create(taskName, ExtractNativesTask::class.java) {
+ it.natives.set(sharedExtension.getDownloadVersionMetadataTask(version)
+ .getVersionMetadataNow().getFilteredLibraries())
+ it.nativeDirectory.set(getLocalCacheDirectory().resolve("extractedNatives/$version"))
+ }
+ return extractNativesTask
+ }
+
+ fun libraries(version: String): List<String> {
+ return sharedExtension.getDownloadVersionMetadataTask(version)
+ .getVersionMetadataNow().getFilteredLibraries()
+ .map {
+ it.getArtifactCoordinate()
+ }
+ }
+
+ fun intermediaryMappings(version: String): MappingDependency {
+ return yarnMappings(project.dependencies.create("net.fabricmc:intermediary:$version:v2"))
+ }
+
+ fun mergeJar(
+ base: Dependency,
+ overlay: Dependency,
+ ): Dependency {
+ base as ModuleDependency
+ overlay as ModuleDependency
+ _registerMinecraftProvider
+ return realize(
+ mergedRepositoryProvider.getCoordinate(
+ MergedRepositoryProvider.Coordinate(base, overlay)
+ )
+ )
+ }
+
+ fun mapJar(
+ dependency: Dependency,
+ mappings: MappingDependency,
+ sourceNamespace: String,
+ destinationNamespace: String
+ ): Dependency {
+ dependency as ModuleDependency
+ _registerMinecraftProvider
+ return realize(
+ mappedRepositoryProvider.getDependencyCoordiante(
+ MappedRepositoryProvider.MappedCoordinates(
+ dependency, mappings, sourceNamespace, destinationNamespace
+ )
+ )
+ )
+ }
+
+ fun minecraft(version: String, side: MCSide): Dependency {
+ _registerMinecraftProvider
+ return realize(
+ sharedExtension.minecraftProvider.getDependencyCoordinate(
+ MinecraftProvider.MinecraftCoordinate(
+ version,
+ side,
+ )
+ )
+ )
+ }
+
+ 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(":", "_"))
+ }
} \ No newline at end of file