Skip to content

Commit

Permalink
Make ForgeModDetectionRule more comprehensive
Browse files Browse the repository at this point in the history
  • Loading branch information
MsRandom committed Feb 15, 2025
1 parent 0fe679a commit b9e35a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ org.gradle.configuration-cache=true
# org.gradle.unsafe.isolated-projects=true

group=net.msrandom
version=0.5.9
version=0.5.10
kotlin.code.style=official
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,32 @@ import net.msrandom.minecraftcodev.forge.MinecraftCodevForgePlugin.Companion.FOR
import net.msrandom.minecraftcodev.forge.MinecraftCodevForgePlugin.Companion.NEOFORGE_MODS_TOML
import net.msrandom.minecraftcodev.remapper.ModDetectionRule
import java.nio.file.FileSystem
import java.util.jar.JarFile
import java.util.jar.Manifest
import kotlin.io.path.exists
import kotlin.io.path.inputStream
import kotlin.io.path.notExists

class ForgeModDetectionRule : ModDetectionRule {
override fun invoke(fileSystem: FileSystem) =
fileSystem.getPath("META-INF", FORGE_MODS_TOML).exists() ||
fileSystem.getPath("META-INF", NEOFORGE_MODS_TOML).exists() ||
fileSystem.getPath("mcmod.info").exists()
override fun invoke(fileSystem: FileSystem): Boolean {
val hasMetadata = fileSystem.getPath("META-INF", FORGE_MODS_TOML).exists() ||
fileSystem.getPath("META-INF", NEOFORGE_MODS_TOML).exists() ||
fileSystem.getPath("mcmod.info").exists()

if (hasMetadata) {
return true
}

val manifestPath = fileSystem.getPath(JarFile.MANIFEST_NAME)

if (manifestPath.notExists()) {
return false
}

val manifest = manifestPath.inputStream().use(::Manifest)

return manifest.mainAttributes.keys.any {
"fml" in it.toString().lowercase() || "forge" in it.toString().lowercase()
}
}
}

0 comments on commit b9e35a1

Please sign in to comment.