lighty-version 26.5.10

Minecraft version management for Lighty Launcher
Documentation
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# How to Use lighty-version

## Basic Usage

### Step 1: Initialize AppState

```rust
use lighty_core::AppState;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    AppState::init("MyLauncher")?;

    Ok(())
}
```

### Step 2: Create VersionBuilder

```rust
use lighty_version::VersionBuilder;
use lighty_loaders::types::Loader;

// Vanilla instance
let vanilla = VersionBuilder::new(
    "vanilla-1.21",
    Loader::Vanilla,
    "",              // No loader version for Vanilla
    "1.21.1",
);

// Fabric instance
let fabric = VersionBuilder::new(
    "fabric-1.21",
    Loader::Fabric,
    "0.16.9",        // Fabric loader version
    "1.21.1",
);

// Quilt instance
let quilt = VersionBuilder::new(
    "quilt-1.21",
    Loader::Quilt,
    "0.27.1",        // Quilt loader version
    "1.21.1",
);

// NeoForge instance
let neoforge = VersionBuilder::new(
    "neoforge-1.21",
    Loader::NeoForge,
    "21.1.80",       // NeoForge version
    "1.21.1",
);
```

## VersionBuilder Features

### Get Version Information

```rust
use lighty_loaders::types::VersionInfo;

println!("Name: {}", vanilla.name());
println!("Loader: {:?}", vanilla.loader());
println!("Loader version: {}", vanilla.loader_version());
println!("Minecraft version: {}", vanilla.minecraft_version());
println!("Game directory: {}", vanilla.game_dirs().display());
println!("Java directory: {}", vanilla.java_dirs().display());
println!("Full ID: {}", vanilla.full_identifier());
```

**Output**:
```
Name: vanilla-1.21
Loader: Vanilla
Loader version:
Minecraft version: 1.21.1
Game directory: /home/user/.local/share/MyLauncher/vanilla-1.21
Java directory: /home/user/.config/MyLauncher/jre
Full ID: vanilla-1.21-1.21.1-
```

### Custom Directories

```rust
use std::path::PathBuf;

let instance = VersionBuilder::new(
    "custom",
    Loader::Fabric,
    "0.16.9",
    "1.21.1",
)
.with_custom_java_dir(PathBuf::from("/usr/lib/jvm/java-21"));

println!("Java dir: {}", instance.java_dirs().display());
// Output: Java dir: /usr/lib/jvm/java-21

// To relocate the runtime (mods/saves/options.txt), pass an override
// through the launch builder. Relative resolves under game_dirs,
// absolute replaces:
//   instance.launch(&profile, JavaDistribution::Temurin)
//       .with_arguments()
//           .set(KEY_GAME_DIRECTORY, "runtime")      // → game_dirs/runtime
//           // or .set(KEY_GAME_DIRECTORY, "/mnt/games/custom")  // absolute
//           .done()
//       .run().await?;
```

### Check Directory Existence

```rust
use lighty_loaders::types::VersionInfo;

if instance.game_dir_exists() {
    println!("Game directory exists");
} else {
    println!("Game directory needs to be created");
}

if instance.java_dir_exists() {
    println!("Java directory exists");
}
```

### Get Both Directories

```rust
use lighty_loaders::types::VersionInfo;

let (game_dir, java_dir) = instance.paths();
println!("Game: {}", game_dir.display());
println!("Java: {}", java_dir.display());
```

## LightyVersionBuilder (Custom Server)

For custom servers using LightyUpdater:

```rust
use lighty_core::AppState;
use lighty_version::LightyVersionBuilder;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    AppState::init("MyLauncher")?;

    // Create LightyUpdater instance
    let modpack = LightyVersionBuilder::new(
        "my-modpack",
        "https://myserver.com/api",
    );

    println!("Instance: {}", modpack.name());
    println!("Server API: {}", modpack.loader_version());

    Ok(())
}
```

**Key Features**:
- Connects to custom server API
- Downloads modpack manifest from server
- Automatically handles mod updates
- See [LightyUpdater Repository]https://github.com/Lighty-Launcher/LightyUpdater for server setup

## Using with LoaderExtensions

Both builders implement `VersionInfo`, enabling all loader operations:

```rust
use lighty_loaders::types::{VersionInfo, LoaderExtensions};

// VersionBuilder
let fabric = VersionBuilder::new(
    "fabric-1.21",
    Loader::Fabric,
    "0.16.9",
    "1.21.1",
);

// Get metadata (LoaderExtensions trait)
let metadata = fabric.get_metadata().await?;
println!("Main class: {}", metadata.main_class);
println!("Libraries: {}", metadata.libraries.len());

// Get specific parts
let libraries = fabric.get_libraries().await?;
let assets = fabric.get_assets().await?;

// LightyVersionBuilder
let modpack = LightyVersionBuilder::new(
    "modpack",
    "https://server.com/api",
);

// Same methods available
let metadata = modpack.get_metadata().await?;
```

## Using with InstanceControl

Both builders also support instance management:

```rust
use lighty_launch::InstanceControl;

// Create instance
let mut instance = VersionBuilder::new(
    "my-game",
    Loader::Fabric,
    "0.16.9",
    "1.21.1",
);

// Get metadata
let metadata = instance.get_metadata().await?;

// Calculate size
let size = instance.size_of_instance(&metadata);
println!("Total: {:.2} GB", size.total_gb());

// Get running PID
if let Some(pid) = instance.get_pid() {
    println!("Running with PID: {}", pid);

    // Close instance
    instance.close_instance(pid).await?;
}

// Delete instance
instance.delete_instance().await?;
```

## Complete Workflow

### Standard Loader Workflow

```rust
use lighty_core::AppState;
use lighty_version::VersionBuilder;
use lighty_loaders::types::{Loader, VersionInfo, LoaderExtensions};
use lighty_launch::InstanceControl;
use lighty_auth::{offline::OfflineAuth, Authenticator};
use lighty_java::JavaDistribution;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // 1. Initialize AppState
    AppState::init("MyLauncher")?;

    // 2. Create instance
    let mut instance = VersionBuilder::new(
        "fabric-modded",
        Loader::Fabric,
        "0.16.9",
        "1.21.1",
    );

    println!("Instance: {}", instance.name());
    println!("Game dir: {}", instance.game_dirs().display());

    // 3. Get metadata
    let metadata = instance.get_metadata().await?;
    println!("Version: {}", metadata.id);
    println!("Libraries: {}", metadata.libraries.len());

    // 4. Calculate size
    let size = instance.size_of_instance(&metadata);
    println!("Size: {:.2} GB", size.total_gb());

    // 5. Authenticate
    let mut auth = OfflineAuth::new("Player123");

    #[cfg(not(feature = "events"))]
    let profile = auth.authenticate().await?;

    #[cfg(feature = "events")]
    let profile = auth.authenticate(None).await?;

    // 6. Launch
    instance.launch(&profile, JavaDistribution::Temurin)
        .run()
        .await?;

    println!("Game launched!");

    // 7. Get PID
    if let Some(pid) = instance.get_pid() {
        println!("Running with PID: {}", pid);
    }

    Ok(())
}
```

### Custom Server Workflow

```rust
use lighty_core::AppState;
use lighty_version::LightyVersionBuilder;
use lighty_loaders::types::{VersionInfo, LoaderExtensions};
use lighty_launch::InstanceControl;
use lighty_auth::{microsoft::MicrosoftAuth, Authenticator};
use lighty_java::JavaDistribution;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // 1. Initialize AppState
    AppState::init("MyLauncher")?;

    // 2. Create LightyUpdater instance
    let mut modpack = LightyVersionBuilder::new(
        "survival-modpack",
        "https://play.myserver.com/api",
    );

    println!("Modpack: {}", modpack.name());
    println!("Server: {}", modpack.loader_version());

    // 3. Get metadata from server
    let metadata = modpack.get_metadata().await?;
    println!("Minecraft: {}", metadata.id);
    println!("Mods: {}", metadata.mods.as_ref().map_or(0, |m| m.len()));

    // 4. Authenticate
    let mut auth = MicrosoftAuth::new("your-client-id");
    auth.set_device_code_callback(|code, url| {
        println!("Visit: {}", url);
        println!("Code: {}", code);
    });

    #[cfg(not(feature = "events"))]
    let profile = auth.authenticate().await?;

    #[cfg(feature = "events")]
    let profile = auth.authenticate(None).await?;

    // 5. Launch modpack
    modpack.launch(&profile, JavaDistribution::Temurin)
        .run()
        .await?;

    println!("Modpack launched!");

    Ok(())
}
```

## Directory Structure

Both builders create the following structure:

```
game_dirs/
├── {instance-name}/         # Instance root
│   ├── versions/
│   │   └── {version}/
│   │       ├── {version}.json
│   │       └── {version}.jar
│   ├── libraries/           # Java libraries
│   ├── assets/              # Game assets
│   ├── mods/                # Mod files (if applicable)
│   ├── config/              # Mod configurations
│   └── saves/               # Worlds

java_dirs/
└── jre/                     # Java runtimes
    ├── java-8/
    ├── java-17/
    └── java-21/
```

## Exports

**In lighty_version**:
```rust
use lighty_version::{
    VersionBuilder,
    LightyVersionBuilder,
};
```

**In lighty_launcher**:
```rust
use lighty_launcher::{
    version::{VersionBuilder, LightyVersionBuilder},
    // or via prelude
    prelude::*,  // Includes VersionBuilder
};
```

## Related Documentation

- [Overview]./overview.md - Architecture and design
- [Exports]./exports.md - Complete export reference
- [VersionBuilder]./version-builder.md - Standard builder details
- [LightyVersionBuilder]./lighty-version-builder.md - Custom server builder details
- [lighty-loaders Traits]../../loaders/docs/traits.md - VersionInfo and LoaderExtensions

## Related Crates

- **[lighty-loaders]../../loaders/README.md** - VersionInfo trait and loaders
- **[lighty-core]../../core/README.md** - AppState for launcher paths
- **[lighty-launch]../../launch/README.md** - Uses VersionBuilder for launching
- **[lighty-auth]../../auth/README.md** - User authentication
- **[lighty-java]../../java/README.md** - Java runtime management