From e28cc289a3f242a10df11ab9aee9a0e7e2964c42 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 28 Oct 2021 14:18:33 +0800 Subject: [PATCH] Use the proper interface Signed-off-by: shedaniel --- .../plugin/ArchitecturyPluginExtension.kt | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/dev/architectury/plugin/ArchitecturyPluginExtension.kt b/src/main/kotlin/dev/architectury/plugin/ArchitecturyPluginExtension.kt index 427acdb..82c2970 100644 --- a/src/main/kotlin/dev/architectury/plugin/ArchitecturyPluginExtension.kt +++ b/src/main/kotlin/dev/architectury/plugin/ArchitecturyPluginExtension.kt @@ -58,25 +58,33 @@ open class ArchitectPluginExtension(val project: Project) { } private val loom: LoomInterface by lazy { - try { - Class.forName("net.fabricmc.loom.api.MixinExtensionAPI") - return@lazy Class.forName("dev.architectury.plugin.loom.LoomInterface010") - .getDeclaredConstructor(Project::class.java) - .newInstance(project) as LoomInterface + useIfFound( + "net.fabricmc.loom.util.ZipUtils", + "dev.architectury.plugin.loom.LoomInterface010" // >0.10.0.188 + ) ?: useIfFound( + "net.fabricmc.loom.api.MixinExtensionAPI", + "dev.architectury.plugin.loom.LoomInterface010Legacy" // 0.10.0 + ) ?: useIfFound( + "net.fabricmc.loom.api.LoomGradleExtensionAPI", + "dev.architectury.plugin.loom.LoomInterface09" // 0.9.0 + ) ?: use("dev.architectury.plugin.loom.LoomInterface06") // 0.6.0 + } + + fun useIfFound(className: String, interfaceName: String): LoomInterface? { + return try { + Class.forName(className) + use(interfaceName) } catch (ignored: ClassNotFoundException) { - try { - Class.forName("net.fabricmc.loom.api.LoomGradleExtensionAPI") - return@lazy Class.forName("dev.architectury.plugin.loom.LoomInterface09") - .getDeclaredConstructor(Project::class.java) - .newInstance(project) as LoomInterface - } catch (ignored: ClassNotFoundException) { - return@lazy Class.forName("dev.architectury.plugin.loom.LoomInterface06") - .getDeclaredConstructor(Project::class.java) - .newInstance(project) as LoomInterface - } + null } } + fun use(interfaceName: String): LoomInterface { + return Class.forName(interfaceName) + .getDeclaredConstructor(Project::class.java) + .newInstance(project) as LoomInterface + } + init { project.afterEvaluate { if (transforms.isNotEmpty()) {