Struct cobble_core::instance::Instance
source · [−]pub struct Instance {Show 19 fields
pub uuid: Uuid,
pub name: String,
pub description: String,
pub version: String,
pub instance_path: String,
pub libraries_path: String,
pub assets_path: String,
pub use_fullscreen: bool,
pub enable_window_size: bool,
pub window_width: u32,
pub window_height: u32,
pub enable_memory: bool,
pub min_memory: u32,
pub max_memory: u32,
pub enable_java_exec: bool,
pub java_exec: String,
pub enable_jvm_args: bool,
pub jvm_args: String,
pub created: OffsetDateTime,
}
Expand description
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:
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::Uuid::new_v4()
when using InstanceBuilder
.
name: String
Name of the instance.
description: String
Description of the instance.
Default to an empty string when using InstanceBuilder
.
version: String
Minecraft version used by the instance.
instance_path: String
Path for the instance.
This path contains the .minecraft
folder and the version data JSON.
libraries_path: String
Path for libraries.
assets_path: String
Path for assets.
use_fullscreen: bool
Launches the game in fullscreen mode.
When set to true
, the window size is ignored.
Defaults to false
when using InstanceBuilder
.
enable_window_size: 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
.
window_width: u32
Game window width.
Used when enable_window_size
is set to true.
Defaults to 1280
when using InstanceBuilder
.
window_height: u32
Game window height.
Used when enable_window_size
is set to true.
Defaults to 720
when using InstanceBuilder
.
enable_memory: bool
Enables custom memory JVM arguments.
Defaults to false
when using InstanceBuilder
.
min_memory: u32
JVM initial heap size in megabytes.
Adds the -Xms
option to the command.
Gets added before jvm_args
.
Defaults to 1024
when using InstanceBuilder
.
max_memory: u32
JVM max heap size in megabytes.
Adds the -Xmx
option to the command. Gets added before
jvm_args`.
Defaults to 2048
when using InstanceBuilder
.
enable_java_exec: bool
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
.
java_exec: String
Java executable used to launch minecraft.
Defaults to java
when using InstanceBuilder
.
enable_jvm_args: bool
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
.
jvm_args: String
Custom JVM arguments.
Defaults to and empty string when using InstanceBuilder
.
created: OffsetDateTime
Created timestamp.
Defaults to time::OffsetDateTime::now_utc()
when using InstanceBuilder
.
Implementations
sourceimpl Instance
impl Instance
sourcepub fn save_asset_index(&self) -> CobbleResult<()>
pub fn save_asset_index(&self) -> CobbleResult<()>
Saves the asset index JSON to disk.
sourcepub fn read_asset_index(&self) -> CobbleResult<AssetIndexData>
pub fn read_asset_index(&self) -> CobbleResult<AssetIndexData>
Read the asset index JSON from disk. This does not download the index if it does not exist.
sourceimpl Instance
impl Instance
sourcepub fn install_assets(
&self,
update_sender: Sender<InstallationUpdate>,
cancel: Arc<AtomicBool>
) -> CobbleResult<()>
pub fn install_assets(
&self,
update_sender: Sender<InstallationUpdate>,
cancel: Arc<AtomicBool>
) -> CobbleResult<()>
Installs all the needed assets. Installs the assets as resources for older versions.
Needs to be called after the asset index is saved to disk.
sourceimpl Instance
impl Instance
sourcepub fn check_installed(&self) -> CobbleResult<bool>
pub fn check_installed(&self) -> CobbleResult<bool>
Checks if the instance is already installed.
Currently only checks
- Version data exists and
- Minecraft client exists
sourceimpl Instance
impl Instance
sourcepub fn install_client(
&self,
update_sender: Sender<InstallationUpdate>,
cancel: Arc<AtomicBool>
) -> CobbleResult<()>
pub fn install_client(
&self,
update_sender: Sender<InstallationUpdate>,
cancel: Arc<AtomicBool>
) -> CobbleResult<()>
Installs the Minecraft client.
Needs to be called after version data is saved to disk.
sourceimpl Instance
impl Instance
sourcepub fn install_libraries(
&self,
update_sender: Sender<InstallationUpdate>,
cancel: Arc<AtomicBool>
) -> CobbleResult<()>
pub fn install_libraries(
&self,
update_sender: Sender<InstallationUpdate>,
cancel: Arc<AtomicBool>
) -> CobbleResult<()>
Installs the all needed libraries. Also extracts natives.
Needs to be called after version data is saved to disk.
sourceimpl Instance
impl Instance
sourcepub fn install_log_config(
&self,
update_sender: Sender<InstallationUpdate>,
cancel: Arc<AtomicBool>
) -> CobbleResult<()>
pub fn install_log_config(
&self,
update_sender: Sender<InstallationUpdate>,
cancel: Arc<AtomicBool>
) -> CobbleResult<()>
Installs the log config file.
Needs to be called after version data is saved to disk.
sourceimpl Instance
impl Instance
sourcepub fn save_version_data(&self) -> CobbleResult<()>
pub fn save_version_data(&self) -> CobbleResult<()>
Saves the version data JSON to disk.
sourcepub fn read_version_data(&self) -> CobbleResult<VersionData>
pub fn read_version_data(&self) -> CobbleResult<VersionData>
Read the version data JSON from disk. This does not download the index if it does not exist.
sourceimpl Instance
impl Instance
sourcepub fn update_channel(
) -> (Sender<InstallationUpdate>, Receiver<InstallationUpdate>)
pub fn update_channel(
) -> (Sender<InstallationUpdate>, Receiver<InstallationUpdate>)
Provides the channel needed for full_install()
.
Eliminates the need to use crossbeam_channel
to get the needed channel.
sourcepub fn full_install(
&self,
update_sender: Sender<InstallationUpdate>,
cancel: Arc<AtomicBool>
) -> CobbleResult<()>
pub fn full_install(
&self,
update_sender: Sender<InstallationUpdate>,
cancel: Arc<AtomicBool>
) -> CobbleResult<()>
Does a full installation of Minecraft.
Includes:
- Version Data
- Asset Index
- Libraries
- Assets or Resources
- Log Config
- Client
let (sender, receiver) = Instance::update_channel();
let cancel = Arc::new(AtomicBool::new(false));
thread::spawn(move || {
instance.full_install(sender, cancel)
});
while let Ok(update) = receiver.recv() {
println!("{:#?}", update);
}
sourceimpl Instance
impl Instance
sourcepub fn launch_command(&self, options: &LaunchOptions) -> CobbleResult<Command>
pub fn launch_command(&self, options: &LaunchOptions) -> CobbleResult<Command>
Builds the command that launches the game. It is required to install all game resources or the game will exit immediately.
This function enables to consume to make modifications to the command.
sourcepub fn launch(&self, options: &LaunchOptions) -> CobbleResult<()>
pub fn launch(&self, options: &LaunchOptions) -> CobbleResult<()>
Launches the game. It is required to install all game resources or the game will exit immediately.
sourceimpl Instance
impl Instance
sourcepub fn instance_path(&self) -> PathBuf
pub fn instance_path(&self) -> PathBuf
Path to the instance. This path contains the version data JSON and the .minecraft 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 game libraries. Path can be shared with other instances of same/different version..
sourcepub fn assets_path(&self) -> PathBuf
pub fn assets_path(&self) -> PathBuf
Path to the game assets.
sourcepub fn natives_path(&self) -> PathBuf
pub fn natives_path(&self) -> PathBuf
Path to the natives.
sourcepub fn resources_path(&self) -> PathBuf
pub fn resources_path(&self) -> PathBuf
Path to the game resources.
sourcepub fn version_data_path(&self) -> PathBuf
pub fn version_data_path(&self) -> PathBuf
Path to the version data JSON file.
sourcepub fn asset_index_path(&self) -> PathBuf
pub fn asset_index_path(&self) -> PathBuf
Path to the asset index JSON file.
sourcepub fn log_configs_path(&self) -> PathBuf
pub fn log_configs_path(&self) -> PathBuf
Path to the log config XML file.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Instance
impl<'de> Deserialize<'de> for Instance
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for Instance
impl Send for Instance
impl Sync for Instance
impl Unpin for Instance
impl UnwindSafe for Instance
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more