Add support for reading mods.toml file from 1.13+ forge mods.

This commit is contained in:
Daniel Scalzi
2020-01-19 11:59:11 -05:00
parent 4d342b7b0a
commit 1ff02edc71
15 changed files with 334 additions and 135 deletions

View File

@@ -0,0 +1,5 @@
export interface VersionSegmented {
isForVersion(version: string): boolean
}

View File

@@ -0,0 +1,46 @@
import { ForgeModStructure113 } from '../model/struct/model/module/forgemod/forgemod113.struct'
import { ForgeModStructure17 } from '../model/struct/model/module/forgemod/forgemod17.struct'
import { Forge113Adapter } from '../resolver/forge/adapter/forge113.resolver'
import { Forge17Adapter } from '../resolver/forge/adapter/forge17.resolver'
export class VersionSegmentedRegistry {
public static readonly FORGE_ADAPTER_IMPL = [
Forge17Adapter,
Forge113Adapter
]
public static readonly FORGEMOD_STRUCT_IML = [
ForgeModStructure17,
ForgeModStructure113
]
public static getForgeResolver(
minecraftVersion: string,
forgeVersion: string,
absoluteRoot: string,
relativeRoot: string,
baseURL: string) {
for (const impl of VersionSegmentedRegistry.FORGE_ADAPTER_IMPL) {
if (impl.isForVersion(minecraftVersion)) {
return new impl(absoluteRoot, relativeRoot, baseURL, minecraftVersion, forgeVersion)
}
}
throw new Error(`No forge resolver found for Minecraft ${minecraftVersion}!`)
}
public static getForgeModStruct(
minecraftVersion: string,
absoluteRoot: string,
relativeRoot: string,
baseUrl: string
) {
for (const impl of VersionSegmentedRegistry.FORGEMOD_STRUCT_IML) {
if (impl.isForVersion(minecraftVersion)) {
return new impl(absoluteRoot, relativeRoot, baseUrl)
}
}
throw new Error(`No forge mod structure found for Minecraft ${minecraftVersion}!`)
}
}

View File

@@ -20,4 +20,12 @@ export class VersionUtil {
throw new Error(`${version} is not a valid minecraft version!`)
}
public static isVersionAcceptable(version: string, acceptable: number[]): boolean {
const versionComponents = VersionUtil.getMinecraftVersionComponents(version)
if (versionComponents != null && versionComponents.major === 1) {
return acceptable.find((element) => versionComponents.minor === element) != null
}
return false
}
}