cobble_core/minecraft/launch/
launch_options.rs

1use derive_builder::Builder;
2
3/// Options for launching Minecraft.
4/// The options can be created using the builder pattern:
5///
6/// ```rust
7/// # use cobble_core::minecraft::{LaunchOptions, LaunchOptionsBuilder};
8/// # fn function() {
9///
10/// let options: LaunchOptions = LaunchOptionsBuilder::default()
11///     .player_name("Steve".to_string())
12///     .fullscreen(true)
13///     .java_executable("/usr/bin/java".to_string())
14///     .build();
15///
16/// # }
17/// ```
18#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
19#[derive(Builder, Clone, Debug)]
20#[builder(build_fn(private, name = "fallible_build"))]
21pub struct LaunchOptions {
22    /// Name of the launcher that gets passed as a game argument.
23    ///
24    /// Defaults to the crates name.
25    #[builder(setter(into), default = "String::from(env!(\"CARGO_PKG_NAME\"))")]
26    pub(crate) launcher_name: String,
27
28    /// Version of the launcher that gets passed as a game argument.
29    ///
30    /// Defaults to the crates version.
31    #[builder(setter(into), default = "String::from(env!(\"CARGO_PKG_VERSION\"))")]
32    pub(crate) launcher_version: String,
33
34    /// Player name for the game.
35    ///
36    /// Defaults to `Steve`.
37    #[builder(setter(into), default = "String::from(\"Steve\")")]
38    pub(crate) player_name: String,
39
40    /// The profile ID.
41    /// This is needed for online mode.
42    ///
43    /// Default to `None`.
44    #[builder(setter(strip_option), default)]
45    pub(crate) profile_id: Option<String>,
46
47    /// The minecraft access token.
48    /// This is needed for online mode.
49    ///
50    /// Defaults to `None`.
51    #[builder(setter(strip_option), default)]
52    pub(crate) token: Option<String>,
53
54    /// Enables fullscreen.
55    /// Overwrites the custom window size.
56    ///
57    /// Defaults to `false`.
58    #[builder(default)]
59    pub(crate) fullscreen: bool,
60
61    /// Enables custom window size.
62    /// Takes effect when not launching in fullscreen.
63    /// The width and height can be configured with `custom_width` and `custom_height`.
64    ///
65    /// Defaults to `false`.
66    #[builder(default)]
67    pub(crate) enable_custom_window_size: bool,
68
69    /// Custom game window width.
70    /// Used when `enable_custom_window_size` is enabled.
71    ///
72    /// Defaults to `1280`.
73    #[builder(default = "1280")]
74    pub(crate) custom_width: u32,
75
76    /// Custom game window height.
77    /// Used when `enable_custom_window_size` is enabled.
78    ///
79    /// Defaults to `720`.
80    #[builder(default = "720")]
81    pub(crate) custom_height: u32,
82
83    /// Enables custom JVM memory restrictions.
84    /// The minimum and maximum can be configured with `custom_min_memory` and `custom_max_memory`.
85    ///
86    /// Defaults to `false`.
87    #[builder(default)]
88    pub(crate) enable_custom_memory: bool,
89
90    /// JVM initial heap size in megabytes.
91    /// Adds the `-Xms` option to the command.
92    /// Gets added before `custom_jvm_args`.
93    /// Used when `enable_custom_memory` is enabled.
94    ///
95    /// Defaults to `1024`.
96    #[builder(default = "1024")]
97    pub(crate) custom_min_memory: u32,
98
99    /// JVM max heap size in megabytes.
100    /// Adds the `-Xmx` opti`on to the command.
101    /// Gets added before `custom_jvm_args`.
102    /// Used when `enable_custom_memory` is enabled.
103    ///
104    /// Defaults to `2048`.
105    #[builder(default = "2048")]
106    pub(crate) custom_max_memory: u32,
107
108    /// Java executable.
109    ///
110    /// Defaults to `java`.
111    #[builder(setter(into), default = "String::from(\"java\")")]
112    pub(crate) java_executable: String,
113
114    /// Custom JVM arguments
115    ///
116    /// Defaults to `None`.
117    #[builder(setter(into, strip_option), default)]
118    pub(crate) custom_jvm_arguments: Option<String>,
119
120    /// Environment variables used for launching the game.
121    ///
122    /// Defaults to `vec![]`.
123    #[builder(default)]
124    pub(crate) environment_variables: Vec<(String, Option<String>)>,
125}
126
127impl Default for LaunchOptions {
128    fn default() -> Self {
129        LaunchOptionsBuilder::default().build()
130    }
131}
132
133impl LaunchOptionsBuilder {
134    /// Builds new `LaunchOptions`.
135    pub fn build(&self) -> LaunchOptions {
136        self.fallible_build().unwrap()
137    }
138}