Use the proper interface

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2021-10-28 14:18:33 +08:00
parent 5c190d4d12
commit e28cc289a3

View File

@@ -58,25 +58,33 @@ open class ArchitectPluginExtension(val project: Project) {
} }
private val loom: LoomInterface by lazy { private val loom: LoomInterface by lazy {
try { useIfFound(
Class.forName("net.fabricmc.loom.api.MixinExtensionAPI") "net.fabricmc.loom.util.ZipUtils",
return@lazy Class.forName("dev.architectury.plugin.loom.LoomInterface010") "dev.architectury.plugin.loom.LoomInterface010" // >0.10.0.188
.getDeclaredConstructor(Project::class.java) ) ?: useIfFound(
.newInstance(project) as LoomInterface "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) { } catch (ignored: ClassNotFoundException) {
try { null
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
}
} }
} }
fun use(interfaceName: String): LoomInterface {
return Class.forName(interfaceName)
.getDeclaredConstructor(Project::class.java)
.newInstance(project) as LoomInterface
}
init { init {
project.afterEvaluate { project.afterEvaluate {
if (transforms.isNotEmpty()) { if (transforms.isNotEmpty()) {