Struct cobble_core::instance::Instance
source · pub struct Instance {Show 20 fields
pub uuid: Uuid,
pub name: String,
pub description: Option<String>,
pub version: String,
pub instance_path: PathBuf,
pub libraries_path: PathBuf,
pub assets_path: PathBuf,
pub fullscreen: bool,
pub enable_custom_window_size: bool,
pub custom_width: u32,
pub custom_height: u32,
pub enable_custom_memory: bool,
pub custom_min_memory: u32,
pub custom_max_memory: u32,
pub custom_java_executable: Option<String>,
pub custom_jvm_arguments: Option<String>,
pub environment_variables: Vec<(String, Option<String>)>,
pub installed: bool,
pub created: OffsetDateTime,
pub fabric_version: Option<String>,
}
Expand description
A Minecraft instance with defined locations for installing libraries, assets and other game data. An instance enables multiple instances to be installed while sharing common data like assets and libraries.
An instance can be created using the builder pattern:
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()?;
Fields§
§uuid: Uuid
Instance UUID
.
Defaults to Uuid::new_v4()
.
name: String
Name of the instance.
description: Option<String>
Optional description of the instance.
version: String
Minecraft version identifier for this instance.
instance_path: PathBuf
Path for the instance folder.
This path contains the .minecraft
folder and some other metadata.
libraries_path: PathBuf
Path for the libraries.
assets_path: PathBuf
Path for the assets.
fullscreen: bool
Enables fullscreen. Overwrites the custom window size.
Defaults to false
.
enable_custom_window_size: bool
Enables custom window size.
Takes effect when not launching in fullscreen.
The width and height can be configured with custom_width
and custom_height
.
Defaults to false
.
custom_width: u32
Custom game window width.
Used when enable_custom_window_size
is enabled.
Defaults to 1280
.
custom_height: u32
Custom game window height.
Used when enable_custom_window_size
is enabled.
Defaults to 720
.
enable_custom_memory: bool
Enables custom JVM memory restrictions.
The minimum and maximum can be configured with custom_min_memory
and custom_max_memory
.
Defaults to false
.
custom_min_memory: u32
JVM initial heap size in megabytes.
Adds the -Xms
option to the command.
Gets added before custom_jvm_args
.
Used when enable_custom_memory
is enabled.
Defaults to 1024
.
custom_max_memory: u32
JVM max heap size in megabytes.
Adds the -Xmx
option to the command. Gets added before
custom_jvm_args. Used when
enable_custom_memory` is enabled.
Defaults to 2048
.
custom_java_executable: Option<String>
Custom java executable.
Defaults to None
.
custom_jvm_arguments: Option<String>
Custom JVM arguments
Defaults to None
.
environment_variables: Vec<(String, Option<String>)>
Environment variables used for launching the game.
Defaults to vec![]
.
installed: bool
Flag whether the instance was installed.
Defaults to false
.
created: OffsetDateTime
Created timestamp.
Defaults to OffsetDateTime::now_utc()
.
fabric_version: Option<String>
fabric
only.Fabric loader version that is used by this instance.
Defaults to None
.
Implementations§
source§impl Instance
impl Instance
sourcepub fn instance_path(&self) -> PathBuf
pub fn instance_path(&self) -> PathBuf
Path to the instance folder.
sourcepub fn dot_minecraft_path(&self) -> PathBuf
pub fn dot_minecraft_path(&self) -> PathBuf
Path to the .minecraft folder.
sourcepub fn libraries_path(&self) -> PathBuf
pub fn libraries_path(&self) -> PathBuf
Path to the libraries folder.
sourcepub fn assets_path(&self) -> PathBuf
pub fn assets_path(&self) -> PathBuf
Path to the assets folder.
sourcepub fn natives_path(&self) -> PathBuf
pub fn natives_path(&self) -> PathBuf
Path to the natives folder.
sourcepub fn resources_path(&self) -> PathBuf
pub fn resources_path(&self) -> PathBuf
Path to the resources folder.
sourcepub fn asset_indexes_path(&self) -> PathBuf
pub fn asset_indexes_path(&self) -> PathBuf
Path to the asset indexes folder.
sourcepub fn log_configs_path(&self) -> PathBuf
pub fn log_configs_path(&self) -> PathBuf
Path to the log configs folder.
sourcepub fn version_data_path(&self) -> PathBuf
pub fn version_data_path(&self) -> PathBuf
Path to the version data JSON file.
sourcepub fn fabric_version_data_path(&self) -> PathBuf
Available on crate feature fabric
only.
pub fn fabric_version_data_path(&self) -> PathBuf
fabric
only.Path to the version data JSON file.
source§impl Instance
impl Instance
sourcepub async fn remove(self) -> CobbleResult<()>
pub async fn remove(self) -> CobbleResult<()>
Removes the instance from disk.
Warning: This will permanently delete the following files:
- Resourcepacks
- Save games
- Screenshots
- Servers
- Shaderpacks
- Mods
It basically deletes the whole .minecraft folder.
source§impl Instance
impl Instance
sourcepub async fn load_log_files(&self) -> CobbleResult<Vec<LogFile>>
Available on crate feature log-files
only.
pub async fn load_log_files(&self) -> CobbleResult<Vec<LogFile>>
log-files
only.Loads all log files from this instance.
source§impl Instance
impl Instance
sourcepub fn resourcepacks_path(&self) -> PathBuf
Available on crate feature resourcepacks
only.
pub fn resourcepacks_path(&self) -> PathBuf
resourcepacks
only.Path to the .minecraft/resourcepacks or .minecraft/texturepacks folder.
sourcepub fn resourcepacks_type(&self) -> ResourcepackType
Available on crate feature resourcepacks
only.
pub fn resourcepacks_type(&self) -> ResourcepackType
resourcepacks
only.Gets whether the instance uses resource- or texturepacks.
sourcepub async fn load_resourcepacks(&self) -> CobbleResult<Vec<Resourcepack>>
Available on crate feature resourcepacks
only.
pub async fn load_resourcepacks(&self) -> CobbleResult<Vec<Resourcepack>>
resourcepacks
only.Loads all resourcepacks from this instance.
sourcepub async fn add_resourcepack(
&self,
src: impl AsRef<Path>
) -> CobbleResult<Option<Resourcepack>>
Available on crate feature resourcepacks
only.
pub async fn add_resourcepack(
&self,
src: impl AsRef<Path>
) -> CobbleResult<Option<Resourcepack>>
resourcepacks
only.Adds a resourcepack. Tries to put it in the apropriate folder for the current version. If it fails to determine the correct folder, it assumes the instance uses resourcepacks.
Returns None
when src
is not a valid resourcepack.
source§impl Instance
impl Instance
sourcepub fn save_games_path(&self) -> PathBuf
Available on crate feature save-games
only.
pub fn save_games_path(&self) -> PathBuf
save-games
only.Path to the .minecraft/saves folder.
sourcepub async fn load_save_games(&self) -> CobbleResult<Vec<SaveGame>>
Available on crate feature save-games
only.
pub async fn load_save_games(&self) -> CobbleResult<Vec<SaveGame>>
save-games
only.Loads all save games from this instance.
sourcepub async fn import_save_game(
&self,
src: impl AsRef<Path>
) -> CobbleResult<Option<SaveGame>>
Available on crate feature backup
only.
pub async fn import_save_game(
&self,
src: impl AsRef<Path>
) -> CobbleResult<Option<SaveGame>>
backup
only.Imports a save game from an exported archive.
Parses the imported save game and returns None
if parsing fails.
source§impl Instance
impl Instance
sourcepub async fn load_screenshots(&self) -> CobbleResult<Vec<Screenshot>>
Available on crate feature screenshots
only.
pub async fn load_screenshots(&self) -> CobbleResult<Vec<Screenshot>>
screenshots
only.Loads all screenshots from this instance.
source§impl Instance
impl Instance
sourcepub fn servers_file(&self) -> PathBuf
Available on crate feature servers
only.
pub fn servers_file(&self) -> PathBuf
servers
only.Path to the .minecraft/servers.dat file.
sourcepub async fn load_servers(&self) -> CobbleResult<Vec<Server>>
Available on crate feature servers
only.
pub async fn load_servers(&self) -> CobbleResult<Vec<Server>>
servers
only.Loads all screenshots from this instance.
sourcepub async fn add_server(&self, server: Server) -> CobbleResult<()>
Available on crate feature servers
only.
pub async fn add_server(&self, server: Server) -> CobbleResult<()>
servers
only.Adds a new server to this instance. Also sets the correct path to this instances servers.dat file.
source§impl Instance
impl Instance
sourcepub async fn export(
&self,
dest: impl AsRef<Path>,
offline: bool,
compression: u32
) -> CobbleResult<()>
Available on crate feature backup
only.
pub async fn export(
&self,
dest: impl AsRef<Path>,
offline: bool,
compression: u32
) -> CobbleResult<()>
backup
only.Exports the instance using a gzip compressed tar archive.
The compression
is a level is an integer from 0-9 where 0 means “no
compression” and 9 means “take as long as you’d like”.
The offline
parameter determines whether all needed assets are packaged as well.
source§impl Instance
impl Instance
sourcepub async fn full_installation(
&mut self,
parallel: u16,
retries: u16,
verify: bool,
update_sender: Sender<InstallationUpdate>
) -> CobbleResult<()>
pub async fn full_installation(
&mut self,
parallel: u16,
retries: u16,
verify: bool,
update_sender: Sender<InstallationUpdate>
) -> CobbleResult<()>
Performs a full installation of Minecraft.
Includes
- Saving version data
- Saving fabric version data
- Libraries
- Fabric libraries (when enabled)
- Assets / Resources
- Log config
- Client
source§impl Instance
impl Instance
sourcepub async fn launch_command(
&self,
options: &LaunchOptions
) -> CobbleResult<Command>
pub async fn launch_command(
&self,
options: &LaunchOptions
) -> CobbleResult<Command>
Builds the launch command for this instance. Uses fabric when enabled. The instance needs to be properly installed.
sourcepub async fn launch<I, O, E>(
&self,
options: &LaunchOptions,
stdin: I,
stdout: O,
stderr: E
) -> CobbleResult<Child>where
I: Into<Stdio>,
O: Into<Stdio>,
E: Into<Stdio>,
pub async fn launch<I, O, E>(
&self,
options: &LaunchOptions,
stdin: I,
stdout: O,
stderr: E
) -> CobbleResult<Child>where
I: Into<Stdio>,
O: Into<Stdio>,
E: Into<Stdio>,
Launches the instance as a child process. Uses fabric when enabled. Game process exits if parent exits.
sourcepub async fn detached_launch<I, O, E>(
&self,
options: &LaunchOptions,
stdin: I,
stdout: O,
stderr: E
) -> CobbleResult<GameProcessHandle>where
I: Into<Stdio>,
O: Into<Stdio>,
E: Into<Stdio>,
pub async fn detached_launch<I, O, E>(
&self,
options: &LaunchOptions,
stdin: I,
stdout: O,
stderr: E
) -> CobbleResult<GameProcessHandle>where
I: Into<Stdio>,
O: Into<Stdio>,
E: Into<Stdio>,
Launches the instance as a detached process. Uses fabric when enabled. Game process does not exit if parent exits.
On unix platforms it is done by forking the process.
On windows it is done using the DETACHED_PROCESS and CREATE_NEW_PROCESS_GROUP flags.
source§impl Instance
impl Instance
sourcepub fn loader_mods_path(&self) -> PathBuf
Available on crate feature loader-mods
only.
pub fn loader_mods_path(&self) -> PathBuf
loader-mods
only.Path to the .minecraft/mods folder.
sourcepub async fn load_loader_mods(&self) -> CobbleResult<Vec<LoaderMod>>
Available on crate feature loader-mods
only.
pub async fn load_loader_mods(&self) -> CobbleResult<Vec<LoaderMod>>
loader-mods
only.Loads all log files from this instance.
sourcepub async fn add_loader_mod(
&self,
src: impl AsRef<Path>
) -> CobbleResult<Option<LoaderMod>>
Available on crate feature loader-mods
only.
pub async fn add_loader_mod(
&self,
src: impl AsRef<Path>
) -> CobbleResult<Option<LoaderMod>>
loader-mods
only.Adds a loader mod.
Returns None
when src
is not a valid resourcepack.
source§impl Instance
impl Instance
sourcepub fn shaderpacks_path(&self) -> PathBuf
Available on crate feature shaderpacks
only.
pub fn shaderpacks_path(&self) -> PathBuf
shaderpacks
only.Path to the .minecraft/resourcepacks or .minecraft/texturepacks folder.
sourcepub async fn load_shaderpacks(&self) -> CobbleResult<Vec<Shaderpack>>
Available on crate feature shaderpacks
only.
pub async fn load_shaderpacks(&self) -> CobbleResult<Vec<Shaderpack>>
shaderpacks
only.Loads all shaderpacks from this instance.
sourcepub async fn add_shaderpack(
&self,
src: impl AsRef<Path>
) -> CobbleResult<Option<Shaderpack>>
Available on crate feature shaderpacks
only.
pub async fn add_shaderpack(
&self,
src: impl AsRef<Path>
) -> CobbleResult<Option<Shaderpack>>
shaderpacks
only.Adds a shaderpack.
Returns None
when src
is not a valid shaderpack.