Struct 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 .minecraftfolder 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>
Available on crate feature fabric only.

Fabric loader version that is used by this instance.

Defaults to None.

Implementations§

Source§

impl Instance

Source

pub async fn import( src: impl AsRef<Path>, instance_path: impl AsRef<Path>, libraries_path: impl AsRef<Path>, assets_path: impl AsRef<Path>, offline: bool, ) -> CobbleResult<Self>

Available on crate feature backup only.

Imports an instance from an archive file.

Source§

impl Instance

Source

pub fn instance_path(&self) -> PathBuf

Path to the instance folder.

Source

pub fn dot_minecraft_path(&self) -> PathBuf

Path to the .minecraft folder.

Source

pub fn libraries_path(&self) -> PathBuf

Path to the libraries folder.

Source

pub fn assets_path(&self) -> PathBuf

Path to the assets folder.

Source

pub fn natives_path(&self) -> PathBuf

Path to the natives folder.

Source

pub fn resources_path(&self) -> PathBuf

Path to the resources folder.

Source

pub fn asset_indexes_path(&self) -> PathBuf

Path to the asset indexes folder.

Source

pub fn log_configs_path(&self) -> PathBuf

Path to the log configs folder.

Source

pub fn version_data_path(&self) -> PathBuf

Path to the version data JSON file.

Source

pub fn fabric_version_data_path(&self) -> PathBuf

Available on crate feature fabric only.

Path to the version data JSON file.

Source§

impl Instance

Source

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

Source

pub async fn load_log_files(&self) -> CobbleResult<Vec<LogFile>>

Available on crate feature log-files only.

Loads all log files from this instance.

Source§

impl Instance

Source

pub fn resourcepacks_path(&self) -> PathBuf

Available on crate feature resourcepacks only.

Path to the .minecraft/resourcepacks or .minecraft/texturepacks folder.

Source

pub fn resourcepacks_type(&self) -> ResourcepackType

Available on crate feature resourcepacks only.

Gets whether the instance uses resource- or texturepacks.

Source

pub async fn load_resourcepacks(&self) -> CobbleResult<Vec<Resourcepack>>

Available on crate feature resourcepacks only.

Loads all resourcepacks from this instance.

Source

pub async fn add_resourcepack( &self, src: impl AsRef<Path>, ) -> CobbleResult<Option<Resourcepack>>

Available on crate feature 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

Source

pub fn save_games_path(&self) -> PathBuf

Available on crate feature save-games only.

Path to the .minecraft/saves folder.

Source

pub async fn load_save_games(&self) -> CobbleResult<Vec<SaveGame>>

Available on crate feature save-games only.

Loads all save games from this instance.

Source

pub async fn import_save_game( &self, src: impl AsRef<Path>, ) -> CobbleResult<Option<SaveGame>>

Available on crate feature backup only.

Imports a save game from an exported archive. Parses the imported save game and returns None if parsing fails.

Source§

impl Instance

Source

pub async fn load_screenshots(&self) -> CobbleResult<Vec<Screenshot>>

Available on crate feature screenshots only.

Loads all screenshots from this instance.

Source§

impl Instance

Source

pub fn servers_file(&self) -> PathBuf

Available on crate feature servers only.

Path to the .minecraft/servers.dat file.

Source

pub async fn load_servers(&self) -> CobbleResult<Vec<Server>>

Available on crate feature servers only.

Loads all screenshots from this instance.

Source

pub async fn add_server(&self, server: Server) -> CobbleResult<()>

Available on crate feature servers only.

Adds a new server to this instance. Also sets the correct path to this instances servers.dat file.

Source§

impl Instance

Source

pub async fn export( &self, dest: impl AsRef<Path>, offline: bool, compression: u32, ) -> CobbleResult<()>

Available on crate feature 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

Source

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

Source

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.

Source

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.

Source

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

Source

pub fn loader_mods_path(&self) -> PathBuf

Available on crate feature loader-mods only.

Path to the .minecraft/mods folder.

Source

pub async fn load_loader_mods(&self) -> CobbleResult<Vec<LoaderMod>>

Available on crate feature loader-mods only.

Loads all log files from this instance.

Source

pub async fn add_loader_mod( &self, src: impl AsRef<Path>, ) -> CobbleResult<Option<LoaderMod>>

Available on crate feature loader-mods only.

Adds a loader mod.

Returns None when src is not a valid resourcepack.

Source§

impl Instance

Source

pub fn shaderpacks_path(&self) -> PathBuf

Available on crate feature shaderpacks only.

Path to the .minecraft/resourcepacks or .minecraft/texturepacks folder.

Source

pub async fn load_shaderpacks(&self) -> CobbleResult<Vec<Shaderpack>>

Available on crate feature shaderpacks only.

Loads all shaderpacks from this instance.

Source

pub async fn add_shaderpack( &self, src: impl AsRef<Path>, ) -> CobbleResult<Option<Shaderpack>>

Available on crate feature shaderpacks only.

Adds a shaderpack.

Returns None when src is not a valid shaderpack.

Trait Implementations§

Source§

impl Clone for Instance

Source§

fn clone(&self) -> Instance

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Instance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Instance

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Instance

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T