Merge pull request #1538 from ludovic111/fix/builtin-packs
🤖 Agent: merged after verify and CI parity passed, built merged with current main (goldendays-1). Prepare copies vanilla's built-in Programmer Art and High Contrast packs from the player's own launcher asset store (SHA-1 checked; nothing ships with Horizon), so packs made to sit on Programmer Art, like Golden Days, show their classic textures.
This commit is contained in:
@@ -17,7 +17,7 @@ pub mod pyjson;
|
||||
mod sounds;
|
||||
mod survival;
|
||||
|
||||
pub use sounds::{fonts, panorama, sounds};
|
||||
pub use sounds::{fonts, packs, panorama, sounds};
|
||||
|
||||
use pyjson::Value;
|
||||
use sha2::Digest;
|
||||
@@ -692,7 +692,7 @@ fn steps(
|
||||
}
|
||||
|
||||
// The JAR holds only gray 1x1 panorama placeholders and an empty Unifont
|
||||
// include. Import the indexed ones afterwards, including on reruns that just
|
||||
// include, and none of the built-in packs. Import the indexed ones afterwards, including on reruns that just
|
||||
// extracted the JAR again. They are optional when preparing from
|
||||
// already-imported JARs.
|
||||
sounds::optional_assets(repo, minecraft, run.log);
|
||||
|
||||
@@ -19,6 +19,7 @@ Usage: horizon-prepare [--prepare] [--server-jar PATH] [--minecraft-dir PATH] [-
|
||||
horizon-prepare sounds [--minecraft-dir PATH] [--root PATH]
|
||||
horizon-prepare panorama [--minecraft-dir PATH] [--root PATH]
|
||||
horizon-prepare fonts [--minecraft-dir PATH] [--root PATH]
|
||||
horizon-prepare packs [--minecraft-dir PATH] [--root PATH]
|
||||
|
||||
--prepare Import the pinned game files from your own copy first
|
||||
--server-jar PATH The pinned server jar you downloaded yourself
|
||||
@@ -34,7 +35,8 @@ The resources go to <root>/.local/horizon-client/<version>; pass that to horizon
|
||||
|
||||
horizon-prepare panorama repairs the classic menu background in existing resources without Java.
|
||||
horizon-prepare fonts adds the GNU Unifont glyphs (characters the bitmap fonts lack) the same way.
|
||||
Full preparation also imports both after extracting the client JAR's placeholders.
|
||||
horizon-prepare packs adds the built-in Programmer Art and High Contrast resource packs the same way.
|
||||
Full preparation also imports all three after extracting the client JAR's placeholders.
|
||||
|
||||
horizon-prepare sounds copies the pinned version's sounds (about 380 MB) from the official
|
||||
launcher's asset store into the same folder, checking every file. It is optional: without it the
|
||||
@@ -66,7 +68,8 @@ fn main() -> ExitCode {
|
||||
};
|
||||
let mut root = None;
|
||||
let mut args = std::env::args_os().skip(1).peekable();
|
||||
let assets = args.next_if(|a| a == "sounds" || a == "panorama" || a == "fonts");
|
||||
let assets =
|
||||
args.next_if(|a| matches!(a.to_str(), Some("sounds" | "panorama" | "fonts" | "packs")));
|
||||
while let Some(arg) = args.next() {
|
||||
let text = arg.to_string_lossy().into_owned();
|
||||
let (flag, inline) = match text.split_once('=') {
|
||||
@@ -132,6 +135,9 @@ fn main() -> ExitCode {
|
||||
Some("fonts") => {
|
||||
horizon_prepare::fonts(&options.root, options.minecraft_dir.as_deref(), &log)
|
||||
}
|
||||
Some("packs") => {
|
||||
horizon_prepare::packs(&options.root, options.minecraft_dir.as_deref(), &log)
|
||||
}
|
||||
_ => horizon_prepare::prepare(&options, &log),
|
||||
};
|
||||
match result {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The pinned version's sounds and title panorama from the player's own official
|
||||
//! launcher install, each object checked against the asset index's SHA-1, copied into
|
||||
//! The pinned version's sounds, title panorama, Unifont glyphs and built-in resource packs
|
||||
//! from the player's own official launcher install, each object checked against the asset index's SHA-1, copied into
|
||||
//! `.local/horizon-client/<version>/assets` where the game reads them (tools/fetch_sounds.py and
|
||||
//! the tools/lab.py functions it called). Nothing is downloaded.
|
||||
|
||||
@@ -124,6 +124,11 @@ pub(crate) fn optional_assets(root: &Path, minecraft: Option<&Path>, log: Log) {
|
||||
"Unifont glyphs not imported: {error}; run horizon-prepare fonts later"
|
||||
));
|
||||
}
|
||||
if let Err(error) = packs(root, minecraft, log) {
|
||||
log(&format!(
|
||||
"Programmer Art and High Contrast not imported: {error}; run horizon-prepare packs later"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
const PANORAMA: [&str; 7] = [
|
||||
@@ -145,6 +150,30 @@ const UNIFONT: [&str; 2] = [
|
||||
"minecraft/font/unifont.zip",
|
||||
];
|
||||
|
||||
/// Adds the built-in Programmer Art and High Contrast packs, which only the asset index holds
|
||||
/// (`BuiltInPackSource.populatePackList` lists `minecraft:resourcepacks` of the vanilla pack).
|
||||
/// Packs made to sit on Programmer Art, like Golden Days, show the default textures without it.
|
||||
/// Also usable on prepared resources without Java.
|
||||
pub fn packs(root: &Path, minecraft: Option<&Path>, log: Log) -> Result<PathBuf, String> {
|
||||
copy_assets(
|
||||
root,
|
||||
minecraft,
|
||||
log,
|
||||
is_built_in_pack,
|
||||
"Built-in pack",
|
||||
&BUILT_IN_PACKS,
|
||||
)
|
||||
}
|
||||
|
||||
const BUILT_IN_PACKS: [&str; 2] = [
|
||||
"minecraft/resourcepacks/programmer_art.zip",
|
||||
"minecraft/resourcepacks/high_contrast.zip",
|
||||
];
|
||||
|
||||
fn is_built_in_pack(name: &str) -> bool {
|
||||
name.starts_with("minecraft/resourcepacks/")
|
||||
}
|
||||
|
||||
/// The fonts only the asset index holds (the JAR has the bitmap fonts).
|
||||
fn is_font(name: &str) -> bool {
|
||||
name.starts_with("minecraft/font/")
|
||||
@@ -228,11 +257,13 @@ mod tests {
|
||||
crate::hex(&sha1::Sha1::digest(data))
|
||||
}
|
||||
|
||||
/// Where the fixture's panorama objects start.
|
||||
const FIRST_FACE: usize = 6;
|
||||
/// Where the fixture's built-in packs and panorama objects start.
|
||||
const FIRST_PACK: usize = 6;
|
||||
const FIRST_FACE: usize = 8;
|
||||
|
||||
/// A Horizon folder and an official launcher directory holding version `9.9` with
|
||||
/// sounds, a language file and the full title panorama in its asset store.
|
||||
/// sounds, a language file, Unifont, the built-in packs and the full title panorama in its
|
||||
/// asset store.
|
||||
struct Fixture {
|
||||
dir: PathBuf,
|
||||
root: PathBuf,
|
||||
@@ -263,6 +294,8 @@ mod tests {
|
||||
b"{\"providers\": [{\"type\": \"unihex\"}]}".to_vec(),
|
||||
),
|
||||
(UNIFONT[1], b"PK unifont".to_vec()),
|
||||
(BUILT_IN_PACKS[0], b"PK programmer art".to_vec()),
|
||||
(BUILT_IN_PACKS[1], b"PK high contrast".to_vec()),
|
||||
];
|
||||
for &name in panorama {
|
||||
// Distinct object bytes let the test catch swapped faces too.
|
||||
@@ -499,15 +532,25 @@ mod tests {
|
||||
lines[0],
|
||||
format!("Title panorama not imported: {error}; run horizon-prepare panorama later")
|
||||
);
|
||||
// The fonts come on their own when only a panorama face is missing.
|
||||
// The fonts and packs come on their own when only a panorama face is missing.
|
||||
match missing {
|
||||
"last-object" => assert_eq!(lines[1], "Font assets ready: 2 files, 0.0 MB"),
|
||||
_ => assert!(
|
||||
lines[1].starts_with("Unifont glyphs not imported: "),
|
||||
"{lines:?}"
|
||||
"last-object" => assert_eq!(
|
||||
lines[1..],
|
||||
[
|
||||
"Font assets ready: 2 files, 0.0 MB",
|
||||
"Built-in pack assets ready: 2 files, 0.0 MB"
|
||||
]
|
||||
),
|
||||
_ => {
|
||||
assert!(lines[1].starts_with("Unifont glyphs not imported: "));
|
||||
assert!(
|
||||
lines[2].starts_with("Programmer Art and High Contrast not imported: ")
|
||||
&& lines[2].ends_with("; run horizon-prepare packs later"),
|
||||
"{lines:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
assert_eq!(lines.len(), 2);
|
||||
assert_eq!(lines.len(), 3);
|
||||
for name in PANORAMA {
|
||||
assert_eq!(fs::read(target.join(name)).unwrap(), b"jar placeholder");
|
||||
}
|
||||
@@ -528,7 +571,7 @@ mod tests {
|
||||
lines.borrow_mut().push(l.to_string())
|
||||
});
|
||||
assert_eq!(done.unwrap(), target);
|
||||
for (name, data) in &f.objects[4..FIRST_FACE] {
|
||||
for (name, data) in &f.objects[4..FIRST_PACK] {
|
||||
assert_eq!(&fs::read(target.join("assets").join(name)).unwrap(), data);
|
||||
}
|
||||
assert_eq!(*lines.borrow(), ["Font assets ready: 2 files, 0.0 MB"]);
|
||||
@@ -536,6 +579,31 @@ mod tests {
|
||||
assert!(!target.join("assets/minecraft/textures").exists());
|
||||
}
|
||||
|
||||
/// Golden Days is made to sit on Programmer Art, which the client JAR lacks: the asset
|
||||
/// index has it, where `BuiltInPackSource` lists `minecraft:resourcepacks`.
|
||||
#[test]
|
||||
fn packs_add_programmer_art_and_high_contrast_where_the_pack_list_finds_them() {
|
||||
let f = Fixture::new("packs");
|
||||
let target = f.root.join(".local/horizon-client/9.9");
|
||||
let lines = std::cell::RefCell::new(Vec::new());
|
||||
let done = packs(&f.root, Some(&f.minecraft), &|l| {
|
||||
lines.borrow_mut().push(l.to_string())
|
||||
});
|
||||
assert_eq!(done.unwrap(), target);
|
||||
for (name, data) in &f.objects[FIRST_PACK..FIRST_FACE] {
|
||||
assert_eq!(&fs::read(target.join("assets").join(name)).unwrap(), data);
|
||||
}
|
||||
assert!(target
|
||||
.join("assets/minecraft/resourcepacks/programmer_art.zip")
|
||||
.is_file());
|
||||
assert_eq!(
|
||||
*lines.borrow(),
|
||||
["Built-in pack assets ready: 2 files, 0.0 MB"]
|
||||
);
|
||||
assert!(!target.join("assets/minecraft/sounds.json").exists());
|
||||
assert!(!target.join("assets/minecraft/font").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_index_must_hold_the_sounds() {
|
||||
let f = Fixture::new("index");
|
||||
|
||||
@@ -7,7 +7,8 @@ screen (the same screen as vanilla's) or in game, and every loader reloads from
|
||||
## How it works
|
||||
|
||||
`packs.rs` finds the packs (`FolderRepositorySource`: folders and zips, plus the built-in Programmer Art and High
|
||||
Contrast), reads `pack.mcmeta` (format range, overlays, filters) and builds one overlay directory that layers the
|
||||
Contrast, which only the asset index holds: preparation copies them, `horizon-prepare packs` repairs older resources),
|
||||
reads `pack.mcmeta` (format range, overlays, filters) and builds one overlay directory that layers the
|
||||
selected packs over the prepared vanilla resources, later packs winning. Files vanilla reads as a resource *stack*
|
||||
(language files, `sounds.json`, font definitions, atlas definitions) are merged layer by layer as vanilla merges them.
|
||||
Every loader then reads that one tree; `game/packs.rs` (`reload_packs`) reloads all of them in game, as
|
||||
|
||||
Reference in New Issue
Block a user