cobble_core/instance/mod.rs
1#[cfg(feature = "backup")]
2mod backup;
3#[cfg(not(feature = "fabric"))]
4mod install;
5#[cfg(not(feature = "fabric"))]
6mod launch;
7mod paths;
8mod remove;
9mod version_data;
10
11// Vanilla features
12#[cfg(feature = "log-files")]
13mod log_files;
14#[cfg(feature = "resourcepacks")]
15mod resourcepacks;
16#[cfg(feature = "save-games")]
17mod save_games;
18#[cfg(feature = "screenshots")]
19mod screenshots;
20#[cfg(feature = "servers")]
21mod servers;
22
23// Modded features
24#[cfg(feature = "fabric")]
25mod fabric;
26#[cfg(feature = "loader-mods")]
27mod loader_mods;
28#[cfg(feature = "shaderpacks")]
29mod shaderpacks;
30
31use derive_builder::Builder;
32use std::path::PathBuf;
33use time::OffsetDateTime;
34use uuid::Uuid;
35
36/// A Minecraft instance with defined locations for installing libraries, assets and other game data.
37/// An instance enables multiple instances to be installed while sharing common data like assets and libraries.
38///
39/// An instance can be created using the builder pattern:
40///
41/// ```rust
42/// # use cobble_core::instance::{Instance, InstanceBuilder, InstanceBuilderError};
43/// # fn function() -> Result<(), InstanceBuilderError> {
44///
45/// let instance: Instance = InstanceBuilder::default()
46/// .name("Minecraft Instance".to_string())
47/// .version("1.18.2".to_string())
48/// .instance_path(".".to_string())
49/// .libraries_path("./libraries".to_string())
50/// .assets_path("./assets".to_string())
51/// .build()?;
52///
53/// # Ok(())
54/// # }
55/// ```
56#[derive(serde::Deserialize, serde::Serialize, Builder, Clone, Debug)]
57pub struct Instance {
58 /// Instance [`UUID`](uuid::Uuid).
59 ///
60 /// Defaults to `Uuid::new_v4()`.
61 #[builder(default = "Uuid::new_v4()")]
62 pub uuid: Uuid,
63
64 /// Name of the instance.
65 #[builder(setter(into))]
66 pub name: String,
67
68 /// Optional description of the instance.
69 #[builder(setter(into, strip_option), default)]
70 pub description: Option<String>,
71
72 /// Minecraft version identifier for this instance.
73 #[builder(setter(into))]
74 pub version: String,
75
76 /// Path for the instance folder.
77 /// This path contains the `.minecraft`folder and some other metadata.
78 #[builder(setter(into))]
79 pub instance_path: PathBuf,
80
81 /// Path for the libraries.
82 #[builder(setter(into))]
83 pub libraries_path: PathBuf,
84
85 /// Path for the assets.
86 #[builder(setter(into))]
87 pub assets_path: PathBuf,
88
89 /// Enables fullscreen.
90 /// Overwrites the custom window size.
91 ///
92 /// Defaults to `false`.
93 #[builder(default)]
94 pub fullscreen: bool,
95
96 /// Enables custom window size.
97 /// Takes effect when not launching in fullscreen.
98 /// The width and height can be configured with `custom_width` and `custom_height`.
99 ///
100 /// Defaults to `false`.
101 #[builder(default)]
102 pub enable_custom_window_size: bool,
103
104 /// Custom game window width.
105 /// Used when `enable_custom_window_size` is enabled.
106 ///
107 /// Defaults to `1280`.
108 #[builder(default = "1280")]
109 pub custom_width: u32,
110
111 /// Custom game window height.
112 /// Used when `enable_custom_window_size` is enabled.
113 ///
114 /// Defaults to `720`.
115 #[builder(default = "720")]
116 pub custom_height: u32,
117
118 /// Enables custom JVM memory restrictions.
119 /// The minimum and maximum can be configured with `custom_min_memory` and `custom_max_memory`.
120 ///
121 /// Defaults to `false`.
122 #[builder(default)]
123 pub enable_custom_memory: bool,
124
125 /// JVM initial heap size in megabytes.
126 /// Adds the `-Xms` option to the command.
127 /// Gets added before `custom_jvm_args`.
128 /// Used when `enable_custom_memory` is enabled.
129 ///
130 /// Defaults to `1024`.
131 #[builder(default = "1024")]
132 pub custom_min_memory: u32,
133
134 /// JVM max heap size in megabytes.
135 /// Adds the `-Xmx` opti`on to the command.
136 /// Gets added before `custom_jvm_args`.
137 /// Used when `enable_custom_memory` is enabled.
138 ///
139 /// Defaults to `2048`.
140 #[builder(default = "2048")]
141 pub custom_max_memory: u32,
142
143 /// Custom java executable.
144 ///
145 /// Defaults to `None`.
146 #[builder(setter(into, strip_option), default)]
147 pub custom_java_executable: Option<String>,
148
149 /// Custom JVM arguments
150 ///
151 /// Defaults to `None`.
152 #[builder(setter(into, strip_option), default)]
153 pub custom_jvm_arguments: Option<String>,
154
155 /// Environment variables used for launching the game.
156 ///
157 /// Defaults to `vec![]`.
158 #[builder(default)]
159 pub environment_variables: Vec<(String, Option<String>)>,
160
161 /// Flag whether the instance was installed.
162 ///
163 /// Defaults to `false`.
164 #[builder(default)]
165 pub installed: bool,
166
167 /// Created timestamp.
168 ///
169 /// Defaults to `OffsetDateTime::now_utc()`.
170 #[builder(default = "OffsetDateTime::now_utc()")]
171 #[cfg_attr(feature = "serde", serde(with = "time::serde::rfc3339"))]
172 pub created: OffsetDateTime,
173
174 /// Fabric loader version that is used by this instance.
175 ///
176 /// Defaults to `None`.
177 #[cfg_attr(doc_cfg, doc(cfg(feature = "fabric")))]
178 #[cfg(feature = "fabric")]
179 #[builder(default)]
180 #[cfg_attr(feature = "serde", serde(default))]
181 pub fabric_version: Option<String>,
182}