cobble_core/minecraft/models/
version_data.rs

1use crate::minecraft::models::{
2    AssetIndexInfo, LaunchArguments, Library, LoggingInfo, RecommendedJavaVersion,
3    VersionDownloads, VersionType,
4};
5use serde::{Deserialize, Serialize};
6use time::OffsetDateTime;
7
8/// Version data includes all necessary information for installing and launching Minecraft.
9/// Every Minecraft version (releases, snapshots, betas, ...) has its own version data.
10#[derive(Clone, Debug, Deserialize, Serialize)]
11pub struct VersionData {
12    /// Game and JVM arguments
13    pub arguments: Option<LaunchArguments>,
14    /// Information of the asset index
15    #[serde(alias = "assetIndex")]
16    pub asset_index: AssetIndexInfo,
17    /// ID of the used asset index
18    pub assets: String,
19    /// Compliance level
20    #[serde(alias = "complianceLevel")]
21    pub compliance_level: i32,
22    /// Download information of the client/server
23    pub downloads: Option<VersionDownloads>,
24    /// Version ID
25    pub id: String,
26    /// Recommended java version
27    #[serde(alias = "javaVersion")]
28    pub java_version: RecommendedJavaVersion,
29    /// Libraries
30    pub libraries: Vec<Library>,
31    /// Logging information
32    pub logging: Option<LoggingInfo>,
33    /// Main class / entry point
34    #[serde(alias = "mainClass")]
35    pub main_class: String,
36    /// Minecraft arguments of older versions
37    #[serde(alias = "minecraftArguments")]
38    pub minecraft_arguments: Option<String>,
39    /// Minimum version of the original launcher
40    #[serde(alias = "minimumLauncherVersion")]
41    pub minimum_launcher_version: i32,
42    /// Release time
43    #[serde(alias = "releaseTime", with = "time::serde::rfc3339")]
44    pub release_time: OffsetDateTime,
45    /// Release time
46    #[serde(with = "time::serde::rfc3339")]
47    pub time: OffsetDateTime,
48    /// Type of the version
49    #[serde(rename = "type")]
50    pub _type: VersionType,
51}
52
53impl VersionData {
54    /// Gets the version data from minecraft server.
55    pub async fn fetch(url: &str) -> reqwest::Result<Self> {
56        reqwest::get(url).await?.error_for_status()?.json().await
57    }
58
59    /// Returns all needed libraries by applying the rules of the libraries.
60    pub fn needed_libraries(&self) -> Vec<&Library> {
61        self.libraries
62            .iter()
63            .filter(|library| library.check_use())
64            .collect()
65    }
66}