add simpler integration with gradle version catalogues

This commit is contained in:
moehreag 2024-05-28 19:17:08 +02:00
parent b90330917c
commit 3f4c38d821

View file

@ -9,6 +9,7 @@ import org.ecorous.esnesnon.nonsense_remapper.parser.ProguardParser
import org.ecorous.esnesnon.nonsense_remapper.provider.MojmapProvider import org.ecorous.esnesnon.nonsense_remapper.provider.MojmapProvider
import org.ecorous.esnesnon.nonsense_remapper.provider.ParchmentProvider import org.ecorous.esnesnon.nonsense_remapper.provider.ParchmentProvider
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.provider.Provider
import kotlin.io.path.notExists import kotlin.io.path.notExists
fun Project.minecraft( fun Project.minecraft(
@ -17,7 +18,8 @@ fun Project.minecraft(
): Project { // return self to allow for chaining ): Project { // return self to allow for chaining
if (VersionChecker.validateVersion(version)) { if (VersionChecker.validateVersion(version)) {
println("Setting up Minecraft...") println("Setting up Minecraft...")
val parchment = parchmentVersion?: kotlin.runCatching { ParchmentProvider.findForMinecraftVersion(version) }.getOrDefault("") val parchment = parchmentVersion ?: kotlin.runCatching { ParchmentProvider.findForMinecraftVersion(version) }
.getOrDefault("")
PhytotelmaPlugin.minecraftVersion = version PhytotelmaPlugin.minecraftVersion = version
PhytotelmaPlugin.parchmentVersion = parchment PhytotelmaPlugin.parchmentVersion = parchment
println("Valid version! $version") println("Valid version! $version")
@ -28,15 +30,24 @@ fun Project.minecraft(
val applyAW = AccessWidener.needsUpdate(this) val applyAW = AccessWidener.needsUpdate(this)
if (remappedJar.notExists() || applyAW) { if (remappedJar.notExists() || applyAW) {
println("Remapping the game...") println("Remapping the game...")
val data = kotlin.runCatching { ProguardParser.read(MojmapProvider.get(version, clientJar.resolveSibling("client-$version.txt")).orElseThrow()).reverse() }.getOrNull() val data = kotlin.runCatching {
val paramMappings = if (parchment.isNotEmpty()) kotlin.runCatching { ParchmentProvider.getParchment( ProguardParser.read(
version, parchment, MojmapProvider.get(
PhytotelmaPlugin.nonsenseCacheDir.resolve("org/parchmentmc/parchment/$version/$parchment")) version,
clientJar.resolveSibling("client-$version.txt")
).orElseThrow()
).reverse()
}.getOrNull()
val paramMappings = if (parchment.isNotEmpty()) kotlin.runCatching {
ParchmentProvider.getParchment(
version, parchment,
PhytotelmaPlugin.nonsenseCacheDir.resolve("org/parchmentmc/parchment/$version/$parchment")
)
}.getOrNull() else { }.getOrNull() else {
println("Parameter mappings will not be present as no parchment version was found. It may be possible to declare it manually.") println("Parameter mappings will not be present as no parchment version was found. It may be possible to declare it manually.")
null null
} }
if (paramMappings == null && parchment.isNotEmpty()){ if (paramMappings == null && parchment.isNotEmpty()) {
println("Parameter mappings will not be present as the version $parchmentVersion for minecraft version $version could not be found") println("Parameter mappings will not be present as the version $parchmentVersion for minecraft version $version could not be found")
} }
if (data != null) { if (data != null) {
@ -46,7 +57,7 @@ fun Project.minecraft(
} }
} }
println("Adding dependencies...") println("Adding dependencies...")
dependencies.add("implementation","net.minecrell:terminalconsoleappender:1.2.0") dependencies.add("implementation", "net.minecrell:terminalconsoleappender:1.2.0")
VersionChecker.getDependencies(version) { VersionChecker.getDependencies(version) {
dependencies.add("implementation", it) dependencies.add("implementation", it)
} }
@ -70,6 +81,17 @@ fun Project.minecraft(
return this return this
} }
fun Project.loader(version: String){ fun Project.minecraft(
version: Provider<String>,
parchmentVersion: Provider<String> = provider { null }
): Project {
return minecraft(version.get(), parchmentVersion.orNull)
}
fun Project.loader(version: String) {
dependencies.add("implementation", "org.ecorous.esnesnon:frogloader:$version") dependencies.add("implementation", "org.ecorous.esnesnon:frogloader:$version")
} }
fun Project.loader(version: Provider<String>) {
return loader(version.get())
}