Versions
1. The Versions Client
The VersionsClient provides access to Modrinth project versions, files, and dependencies.
You can fetch individual versions, retrieve versions for a project, resolve the latest compatible version, and look up versions by file hashes.
Access it through the main Modrinth client:
modrinth.versions()2. Getting a Version
Fetch a version by its ID:
Version version = modrinth.versions().get("version-id");val version = modrinth.versions().get("version-id")3. Getting Multiple Versions
Fetch multiple versions at once:
List<Version> versions = modrinth.versions().getMany(
"version-id-1",
"version-id-2"
);val versions = modrinth.versions().getMany(
"version-id-1",
"version-id-2"
)4. Getting Project Versions
Use getByProject() to fetch all versions of a project:
List<Version> versions = modrinth.versions()
.getByProject("sodium");val versions = modrinth.versions()
.getByProject("sodium")Filtering Project Versions
Pass a VersionSearchOptions object to filter versions:
VersionSearchOptions options = VersionSearchOptions.builder()
.gameVersions("1.21.11")
.loaders(ModLoader.FABRIC)
.featured(true)
.build();
List<Version> versions = modrinth.versions()
.getByProject("sodium", options);val options = VersionSearchOptions.builder()
.gameVersions("1.21.11")
.loaders(ModLoader.FABRIC)
.featured(true)
.build()
val versions = modrinth.versions()
.getByProject("sodium", options)5. Resolving Versions
By Version Number
Use getVersionByNumber() to find a project version by its version number:
Version version = modrinth.versions()
.getVersionByNumber("sodium", "mc1.21.11-0.8.0");val version = modrinth.versions()
.getVersionByNumber("sodium", "mc1.21.11-0.8.0")Latest Matching Version
Use resolveLatest() to get the first version matching the provided filters:
VersionSearchOptions options = VersionSearchOptions.builder()
.gameVersions("1.21.11")
.loaders(ModLoader.FABRIC)
.build();
Version latest = modrinth.versions()
.resolveLatest("sodium", options);val options = VersionSearchOptions.builder()
.gameVersions("1.21.11")
.loaders(ModLoader.FABRIC)
.build()
val latest = modrinth.versions()
.resolveLatest("sodium", options)6. Looking Up Versions by Hash
Versions can also be resolved from file hashes.
Single Hash
Version version = modrinth.versions()
.fromHash("file-hash");val version = modrinth.versions()
.fromHash("file-hash")Multiple Hashes
List<Version> versions = modrinth.versions().fromHashes(
"file-hash-1",
"file-hash-2"
);val versions = modrinth.versions().fromHashes(
"file-hash-1",
"file-hash-2"
)7. Getting Dependencies
Fetch the dependencies of a version:
List<VersionDependency> dependencies = modrinth.versions()
.dependencies("version-id");val dependencies = modrinth.versions()
.dependencies("version-id")8. Methods
VersionsClient Methods 9 available methods
get()
Fetches a version by its ID.
getMany()
Fetches multiple versions by their IDs.
getByProject()
Fetches versions belonging to a project, optionally using filters.
getVersionByNumber()
Finds a project version by its version number.
resolveLatest()
Returns the latest version matching the provided search options.
fromHashes()
Resolves multiple versions from file hashes.
fromHash()
Resolves a version from a file hash.
latestFromHashes()
Resolves the latest versions associated with multiple file hashes.
dependencies()
Fetches the dependencies of a version.
{/* This block has been copy pasted so many times that Ctrl+C and Ctrl+V are now considered npm dependencies:
yes
Does stuff.
*/}