Launcher: data packs into a world

datapacks.rs lists a world's datapacks/ (zips and folders with
pack.mcmeta, as the game discovers them; off when datapacks.json lists them
disabled), adds a data pack zip under a free name (refusing resource packs:
no data/ folder) and removes one to the trash, forgetting it in
datapacks.json. The game turns a new pack on when the world opens.

Home: each world gets "Data packs", which opens its packs under the row
with Add data pack… and Remove; a zip dropped on a world goes into it.
CLI: `worlds datapack-list|datapack-add|datapack-remove <world>`;
datapack-remove needs confirm over MCP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-27 02:49:42 +01:00
parent cac63dedca
commit aa6fdac501
11 changed files with 640 additions and 4 deletions
+62
View File
@@ -212,6 +212,27 @@ enum WorldsCmd {
#[arg(long)]
instance: Option<String>,
},
/// A world's data packs, and which are on
DatapackList {
world: String,
#[arg(long)]
instance: Option<String>,
},
/// Copy a data pack zip into a world (the game turns it on when the world opens)
DatapackAdd {
world: String,
file: PathBuf,
#[arg(long)]
instance: Option<String>,
},
/// Move a world's data pack to the system's trash
DatapackRemove {
world: String,
/// Its file name, with or without .zip
pack: String,
#[arg(long)]
instance: Option<String>,
},
}
#[derive(Clone, Copy, clap::ValueEnum)]
@@ -1816,6 +1837,7 @@ fn multiplayer(action: MultiplayerCmd, as_json: bool) -> Result<(), String> {
}
fn worlds(action: WorldsCmd, as_json: bool) -> Result<(), String> {
use horizon_launcher::datapacks;
use horizon_launcher::worlds::{self, World};
let home = |instance: Option<String>| -> Result<PathBuf, String> {
Ok(match instance {
@@ -1873,6 +1895,46 @@ fn worlds(action: WorldsCmd, as_json: bool) -> Result<(), String> {
worlds::delete(&w)?;
println!("{} is in the trash.", w.name);
}
WorldsCmd::DatapackList { world, instance } => {
let w = worlds::find(&home(instance)?, &world)?;
let packs = datapacks::list(&w.path);
if as_json {
json(
packs
.iter()
.map(|p| serde_json::json!({ "file": p.file, "description": p.description, "enabled": p.enabled, "path": p.path }))
.collect(),
);
} else if packs.is_empty() {
println!("No data packs in {}", w.name);
}
for p in packs.iter().filter(|_| !as_json) {
let on = if p.enabled { "on " } else { "off" };
println!(" {on} {} {}", p.file, p.description);
}
}
WorldsCmd::DatapackAdd {
world,
file,
instance,
} => {
let w = worlds::find(&home(instance)?, &world)?;
let p = datapacks::add(&w.path, &file)?;
println!(
"Added {} to {}: the game turns it on when the world opens.",
p.file, w.name
);
}
WorldsCmd::DatapackRemove {
world,
pack,
instance,
} => {
let w = worlds::find(&home(instance)?, &world)?;
let p = datapacks::find(&w.path, &pack)?;
datapacks::remove(&w.path, &p)?;
println!("{} is in the trash.", p.file);
}
}
Ok(())
}