Skip to content

Commit e1c215a

Browse files
committed
Add support for NeoForge modloader.
1 parent 6a175e1 commit e1c215a

File tree

8 files changed

+308
-6
lines changed

8 files changed

+308
-6
lines changed

installer/src/main/kotlin/gg/essential/installer/launcher/curseforge/CurseForge.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ class CurseForge(
219219
* The real installer modifies this JSON a bit (removes a few fields), but it shouldn't be a problem if we just include the entire one.
220220
*/
221221
private suspend fun getModloaderJson(installInfo: InstallInfo): JsonObject {
222-
var id = "${installInfo.modloader.type.name.lowercase()}-${installInfo.modloaderVersion.numeric}"
223-
if (installInfo.modloader.type == ModloaderType.FABRIC || installInfo.modloader.type == ModloaderType.QUILT) {
224-
id += "-${installInfo.mcVersion}"
222+
val modloaderType = installInfo.modloader.type
223+
val id = "${modloaderType.name.lowercase()}-" + when (modloaderType) {
224+
ModloaderType.FABRIC, ModloaderType.QUILT -> "${installInfo.modloaderVersion.numeric}-${installInfo.mcVersion}"
225+
ModloaderType.NEOFORGE -> installInfo.modloaderVersion.full
226+
else -> installInfo.modloaderVersion.numeric
225227
}
226228
logger.info("Fetching $id from curseforge.")
227229
val url = MetadataManager.installer.urls.curseforgeModloaderInfo.replace("{id}", id)

installer/src/main/kotlin/gg/essential/installer/launcher/vanilla/MinecraftInstallationData.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package gg.essential.installer.launcher.vanilla
2020
import gg.essential.installer.minecraft.MCVersion
2121
import gg.essential.installer.modloader.ModloaderInfo
2222
import gg.essential.installer.modloader.ModloaderType
23+
import gg.essential.installer.modloader.ModloaderVersion
2324
import gg.essential.installer.util.InstantAsIso8601Serializer
2425
import kotlinx.serialization.Serializable
2526
import kotlinx.serialization.UseSerializers
@@ -44,6 +45,10 @@ data class MinecraftInstallationData(
4445
get() = when (ModloaderInfo.fromVersionString(lastVersionId).type) {
4546
ModloaderType.NONE_MODERN -> MCVersion.fromString(lastVersionId)
4647
ModloaderType.FORGE -> MCVersion.fromString(lastVersionId.split('-').first()) // Example: 1.18.2-forge-40.0.12
48+
ModloaderType.NEOFORGE -> {
49+
val numeric = ModloaderVersion.fromVersion(ModloaderType.NEOFORGE, lastVersionId).numeric
50+
MCVersion.fromString("1." + numeric.substring(0..<numeric.lastIndexOf('.')))
51+
} // Example: neoforge-21.5.14-beta
4752
ModloaderType.FABRIC -> MCVersion.fromString(lastVersionId.split('-').last()) // Example: fabric-loader-0.15.3-1.20.4
4853
else -> MCVersion.fromString(lastVersionId, false) // Try parsing non-strictly, to at least get the version hopefully
4954
}

installer/src/main/kotlin/gg/essential/installer/metadata/data/InstallerMetadata.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ data class InstallerMetadata(
3737
val forgeInstaller: String,
3838
val fabric: String,
3939
val fabricFallback: String,
40+
val neoforge: String,
41+
val neoforgeInstaller: String,
4042
val minecraftVersions: String,
4143
val curseforgeModloaderInfo: String,
4244
)

installer/src/main/kotlin/gg/essential/installer/modloader/Modloader.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ abstract class Modloader(val type: ModloaderType) {
9696
}
9797
}
9898

99-
fun getPrismModloaderComponent(installInfo: PrismInstallInfo): MMCPack.Component {
99+
open fun getPrismModloaderComponent(installInfo: PrismInstallInfo): MMCPack.Component {
100100
return MMCPack.Component(
101101
uid = installInfo.modloader.type.prismUID ?: throw IllegalArgumentException("Cannot get prism component for ${installInfo.modloader.type}"),
102102
version = installInfo.modloaderVersion.numeric,

installer/src/main/kotlin/gg/essential/installer/modloader/ModloaderType.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum class ModloaderType(
3131
FABRIC("Fabric", lazy { FabricModloader }, "net.fabricmc.fabric-loader", listOf("net.fabricmc.intermediary")),
3232
FORGE("Forge", lazy { ForgeModloader }, "net.minecraftforge"),
3333
QUILT("Quilt", null, "org.quiltmc.quilt-loader", listOf("net.fabricmc.intermediary")),
34-
NEOFORGE("NeoForge", null, "net.neoforged"),
34+
NEOFORGE("NeoForge", lazy { NeoForgeModloader }, "net.neoforged"),
3535

3636
NONE_SNAPSHOT("Snapshot"), // To allow parsing snapshot versions
3737
NONE_ALPHA("Alpha"), // To allow parsing alpha versions

installer/src/main/kotlin/gg/essential/installer/modloader/ModloaderVersion.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ data class ModloaderVersion(
5050
companion object {
5151
// Note if anyone ever edits this: Order inside the matching group matters (specifically for first one), as we would otherwise not parse x.y.z.w correctly, we would match the x.y.z first
5252
private val FORGE_VERSION_REGEX = Pattern.compile("(?<version>(\\d+\\.\\d+|[02-9]|\\d{2,})\\.\\d+\\.\\d+)")
53+
private val NEOFORGE_VERSION_REGEX = Pattern.compile("(?<version>(\\d+\\.\\d+\\.\\d+))")
5354

5455

5556
fun fromVersion(type: ModloaderType, fullVersion: String, providedNumericVersion: String? = null): ModloaderVersion {
@@ -90,14 +91,23 @@ data class ModloaderVersion(
9091
x.y.z, where x must not be 1. This effectively matches anything that looks like a version, but is not a minecraft version.
9192
Let's hope Minecraft doesn't update to 2.0...
9293
*/
93-
ModloaderType.FORGE, ModloaderType.NEOFORGE -> {
94+
ModloaderType.FORGE -> {
9495
val matcher = FORGE_VERSION_REGEX.matcher(fullVersion)
9596
if (matcher.find()) {
9697
matcher.group("version")
9798
} else {
9899
""
99100
}
100101
}
102+
// Neoforge doesn't have multiple numeric versions, making this easy
103+
ModloaderType.NEOFORGE -> {
104+
val matcher = NEOFORGE_VERSION_REGEX.matcher(fullVersion)
105+
if (matcher.find()) {
106+
matcher.group("version")
107+
} else {
108+
""
109+
}
110+
}
101111

102112
else -> ""
103113
}

0 commit comments

Comments
 (0)