Skip to content

Commit

Permalink
build: properly convert semver to maven version range for forge/neoforge
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Oct 11, 2024
1 parent f9e884d commit b79a385
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
49 changes: 40 additions & 9 deletions client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,52 @@ tasks {
data class VersionInfo(
val neoForgeVersion: String,
val forgeVersion: String,
val mcVersions: List<String>
val mcVersions: String
) {

// "${mcVersions}" -> "[1.20,1.20.1]"
val forgeMcVersions
get() =
if (mcVersions[0].startsWith(">=")) {
"[${mcVersions[0].substringAfter(">=")},)"
val forgeMcVersions: String
get() {
val split = mcVersions.split(" ")

fun versionBounds(version: String): Triple<String, String, String>? =
when {
version.startsWith(">=") -> Triple(
"[", version.substringAfter(">="), ",)"
)
version.startsWith(">") -> Triple(
"(", version.substringAfter(">"), ",)"
)
version.startsWith("<=") -> Triple(
"(,", version.substringAfter("<="), "]"
)
version.startsWith("<") -> Triple(
"(,", version.substringAfter("<"), ")"
)
else -> null
}

if (split.size == 1) {
val version = split.first()
val bounds = versionBounds(version)

return if (bounds == null) {
"[$version]"
} else {
"${bounds.first}${bounds.second}${bounds.third}"
}
} else if (split.size == 2) {
val bounds = split.map { versionBounds(it)!! }
val first = bounds[0]
val second = bounds[1]

return "${first.first}${first.second},${second.second}${second.third}"
} else {
"[${mcVersions.joinToString(",")}]"
throw IllegalStateException("Invalid version")
}
}

// ["${mcVersions}"] -> ["1.20", "1.20.1"]
val fabricMcVersions
get() = mcVersions.joinToString("\", \"")
get() = mcVersions
}

fun readVersionInfo(): VersionInfo = Toml()
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"depends": {
"fabric": "*",
"fabricloader": "*",
"minecraft": ["${mcVersions}"]
"minecraft": "${mcVersions}"
}
}
20 changes: 10 additions & 10 deletions client/versions.toml
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
[12102]
mcVersions = [">1.21.1"]
mcVersions = ">1.21.1"

[12100]
mcVersions = [">=1.21 <=1.21.1"]
mcVersions = ">=1.21.0 <=1.21.1"
forgeVersion = "[51,)"
neoForgeVersion = "[20,)"

[12004]
forgeVersion = "[49,)"
mcVersions = [">=1.20.2 <=1.20.4"]
mcVersions = ">=1.20.2 <=1.20.4"

[12001]
forgeVersion = "[46,)"
mcVersions = [">=1.20 <=1.20.1"]
mcVersions = ">=1.20.0 <=1.20.1"

[11904]
forgeVersion = "[45,)"
mcVersions = ["1.19.4"]
mcVersions = "1.19.4"

[11903]
forgeVersion = "[44,)"
mcVersions = ["1.19.3"]
mcVersions = "1.19.3"

[11902]
forgeVersion = "[41,)"
mcVersions = [">=1.19 <1.19.3"]
mcVersions = ">=1.19 <1.19.3"

[11802]
forgeVersion = "[40,)"
mcVersions = ["1.18.2"]
mcVersions = "1.18.2"

[11701]
forgeVersion = "[37,)"
mcVersions = ["1.17.1"]
mcVersions = "1.17.1"

[11605]
forgeVersion = "[32,)"
mcVersions = ["1.16.5"]
mcVersions = "1.16.5"

0 comments on commit b79a385

Please sign in to comment.