1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use uuid::Uuid;
/// Installation functions for instance.
mod install;
/// Launching functions for instance.
mod launch;
/// Helpers for getting all different paths for instance.
mod paths;
/// A single instance of Minecraft with defined locations for libraries, assets and the .minecraft folder.
/// An instance can be configured to pass different arguments to the game when launching like window size.
///
/// An instance can be created using the builder pattern:
///
/// ```rust
/// # use cobble_core::instance::{Instance, InstanceBuilder, InstanceBuilderError};
/// # fn function() -> Result<(), InstanceBuilderError> {
///
/// let instance: Instance = InstanceBuilder::default()
/// .name("Minecraft Instance".to_string())
/// .version("1.18.2".to_string())
/// .instance_path(".".to_string())
/// .libraries_path("./libraries".to_string())
/// .assets_path("./assets".to_string())
/// .build()?;
///
/// # Ok(())
/// # }
/// ```
#[derive(Builder, Clone, Debug, Deserialize, Serialize)]
pub struct Instance {
/// Instance [`UUID`](uuid::Uuid).
///
/// Defaults to [`uuid::Uuid::new_v4()`](uuid::Uuid::new_v4) when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default = "uuid::Uuid::new_v4()")]
pub uuid: Uuid,
/// Name of the instance.
pub name: String,
/// Description of the instance.
///
/// Default to an empty string when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default)]
pub description: String,
/// Minecraft version used by the instance.
pub version: String,
/// Path for the instance.
/// This path contains the `.minecraft` folder and the version data JSON.
pub instance_path: String,
/// Path for libraries.
pub libraries_path: String,
/// Path for assets.
pub assets_path: String,
/// Launches the game in fullscreen mode.
/// When set to `true`, the window size is ignored.
///
/// Defaults to `false` when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default)]
pub use_fullscreen: bool,
/// Enables a custom resolution for the game window.
/// Only has an effect when game is **not** launched in fullscreen mode.
///
/// Defaults to `false` when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default)]
pub enable_window_size: bool,
/// Game window width.
/// Used when `enable_window_size` is set to true.
///
/// Defaults to `1280` when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default = "1280")]
pub window_width: u32,
/// Game window height.
/// Used when `enable_window_size` is set to true.
///
/// Defaults to `720` when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default = "720")]
pub window_height: u32,
/// Enables custom memory JVM arguments.
///
/// Defaults to `false` when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default)]
pub enable_memory: bool,
/// JVM initial heap size in megabytes.
/// Adds the `-Xms` option to the command.
/// Gets added before `jvm_args`.
///
/// Defaults to `1024` when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default = "1024")]
pub min_memory: u32,
/// JVM max heap size in megabytes.
/// Adds the `-Xmx` opti`on to the command.
/// Gets added before `jvm_args`.
///
/// Defaults to `2048` when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default = "2048")]
pub max_memory: u32,
/// Enables a custom java executable.
/// Launching an instance tries to use the instances `java_exec` when enabled, then tries `java_exec` for
///
/// Defaults to `false` when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default)]
pub enable_java_exec: bool,
/// Java executable used to launch minecraft.
///
/// Defaults to `java` when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default = "String::from(\"java\")")]
pub java_exec: String,
/// Enables custom JVM arguments.
/// When disabled and the version data provides JVM arguments, the arguments from the version data are used.
/// When enabled, arguments from version data are ignored.
///
/// Defaults to `false` when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default)]
pub enable_jvm_args: bool,
/// Custom JVM arguments.
///
/// Defaults to and empty string when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default)]
pub jvm_args: String,
/// Created timestamp.
///
/// Defaults to [`time::OffsetDateTime::now_utc()`](time::OffsetDateTime::now_utc) when using [`InstanceBuilder`](InstanceBuilder).
#[builder(default = "OffsetDateTime::now_utc()")]
#[serde(with = "time::serde::rfc3339")]
pub created: OffsetDateTime,
}