diff --git a/.github/workflows/parity.yml b/.github/workflows/parity.yml index ef03b6df2..7289fe4de 100644 --- a/.github/workflows/parity.yml +++ b/.github/workflows/parity.yml @@ -33,6 +33,8 @@ jobs: run: bash tools/ci/runner-env.sh - name: Vanilla data, and resources prepared by this preparer run: bash tools/ci/vanilla-data.sh + - name: The version constants are the pinned jar's + run: python3 tools/gen_version_consts.py --check - name: The harnesses this change can affect env: PARITY_HOSTS: '' diff --git a/Cargo.lock b/Cargo.lock index 25c705b23..16ae8d6eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1539,6 +1539,7 @@ version = "0.1.0" dependencies = [ "flate2", "getrandom 0.3.4", + "horizon-core", "horizon-world", "serde_json", "sha1", diff --git a/crates/horizon-client/examples/particle_providers_probe.rs b/crates/horizon-client/examples/particle_providers_probe.rs index 7c819eccd..989895c07 100644 --- a/crates/horizon-client/examples/particle_providers_probe.rs +++ b/crates/horizon-client/examples/particle_providers_probe.rs @@ -137,7 +137,7 @@ fn world(assets: &Assets, facts: &BlockFacts, floor: bool) -> Result { fn main() -> Result<()> { let args: Vec = std::env::args().collect(); - let root = Path::new(".local/horizon-client/26.3"); + let root = &Path::new(".local/horizon-client").join(horizon_core::VANILLA_VERSION); let assets = Assets::load(root)?; let facts = BlockFacts::load(root, assets.registry)?; let collision = collisions::load(root, assets.registry)?; diff --git a/crates/horizon-client/src/bin/horizon-ctl/launch.rs b/crates/horizon-client/src/bin/horizon-ctl/launch.rs index b4f46634b..ee0b2b8b3 100644 --- a/crates/horizon-client/src/bin/horizon-ctl/launch.rs +++ b/crates/horizon-client/src/bin/horizon-ctl/launch.rs @@ -54,7 +54,7 @@ pub fn prepared_resources(dir: &Path) -> Option { .ok() .and_then(|t| serde_json::from_str::(&t).ok()) .and_then(|v| v["minecraft"]["version"].as_str().map(str::to_owned)) - .unwrap_or_else(|| "26.3".into()); + .unwrap_or_else(|| horizon_core::VANILLA_VERSION.into()); let resources = dir.join(".local/horizon-client").join(version); resources .join("horizon-resources.json") diff --git a/crates/horizon-client/src/crash.rs b/crates/horizon-client/src/crash.rs index b361a50ff..8ee5803b5 100644 --- a/crates/horizon-client/src/crash.rs +++ b/crates/horizon-client/src/crash.rs @@ -241,7 +241,10 @@ fn memory() -> String { pub fn system_details() -> Vec<(String, String)> { let mut out = vec![ ("Horizon Version".to_owned(), version()), - ("Minecraft Version".to_owned(), "26.3".to_owned()), + ( + "Minecraft Version".to_owned(), + horizon_core::VANILLA_VERSION.to_owned(), + ), ("Operating System".to_owned(), operating_system()), ("CPU".to_owned(), cpu()), ("Memory".to_owned(), memory()), @@ -605,7 +608,10 @@ mod tests { assert!(first.contains("crash.rs"), "{}", report.stack); let text = report.text(); assert!(text.contains("Description: Unexpected error")); - assert!(text.contains("\tMinecraft Version: 26.3\n")); + assert!(text.contains(&format!( + "\tMinecraft Version: {}\n", + horizon_core::VANILLA_VERSION + ))); assert!(text.contains("\tOperating System: ")); assert!(text.contains("\tCPU: ")); let home = std::env::temp_dir().join(format!("horizon-crash-save-{}", std::process::id())); diff --git a/crates/horizon-client/src/entities.rs b/crates/horizon-client/src/entities.rs index b9c8ee896..acb2203a4 100644 --- a/crates/horizon-client/src/entities.rs +++ b/crates/horizon-client/src/entities.rs @@ -597,7 +597,8 @@ mod fire_environment_tests { #[test] fn ordinary_items_burn_but_native_netherite_resists_lava() { let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) - .join("../../.local/horizon-client/26.3"); + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("items.json").exists() { return; } diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs index ee86211a1..d1c3665ed 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -1761,7 +1761,8 @@ mod axolotl_nbt_tests { #[test] fn bucket_cooldown_and_brain_memories_survive_and_expired_cooldown_is_removed() { let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) - .join("../../.local/horizon-client/26.3"); + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("items.json").exists() { return; } diff --git a/crates/horizon-client/src/front.rs b/crates/horizon-client/src/front.rs index 0b4eebd62..75c072eb6 100644 --- a/crates/horizon-client/src/front.rs +++ b/crates/horizon-client/src/front.rs @@ -230,7 +230,12 @@ impl Title { color::mix(muted, color::TEXT, hover), "Quit game", ); - ui.caps(24.0, h - 12.0 - 18.0, muted, "Horizon 26.3"); + ui.caps( + 24.0, + h - 12.0 - 18.0, + muted, + &format!("Horizon {}", horizon_core::VANILLA_VERSION), + ); } /// Home: the launcher's Play page over the backdrop. fn home(&self, ui: &mut Ui, x: f32, w: f32) { @@ -241,7 +246,10 @@ impl Title { x, y, muted, - "Minecraft 26.3 · Java Edition, rewritten in Rust", + &format!( + "Minecraft {} · Java Edition, rewritten in Rust", + horizon_core::VANILLA_VERSION + ), ); y += 24.0; let line = (t::HERO * 1.1).round(); @@ -1189,7 +1197,12 @@ pub mod pause { &["Game", "Advancements", "Statistics", "Options"], 0, ); - ui.caps(24.0, h - 12.0 - 18.0, color::FAINT, "Horizon 26.3"); + ui.caps( + 24.0, + h - 12.0 - 18.0, + color::FAINT, + &format!("Horizon {}", horizon_core::VANILLA_VERSION), + ); ui.offset = (0.0, 8.0 * (1.0 - p)); let x = SIDEBAR + 48.0; let cw = (w - x - 48.0).min(760.0); diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 13d8018df..4b516a4e7 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -292,7 +292,7 @@ impl Options { resources: if sibling.join("horizon-resources.json").exists() { sibling } else { - PathBuf::from(".local/horizon-client/26.3") + std::path::Path::new(".local/horizon-client").join(horizon_core::VANILLA_VERSION) }, distance: 12, distance_override: None, @@ -331,7 +331,8 @@ impl Options { match arg.as_str() { "--help" | "-h" => { println!( - "Horizon — Minecraft Java Edition 26.3 in Rust\n\n --resources PATH Prepared resources (horizon-prepare)\n --render-distance N Chunks, 2..64 (default 12)\n --world NAME World folder under saves/ (default \"New World\")\n --seed N World seed for new worlds (default 0)\n --creative Creative mode (default survival)\n --test-terrain Simple test terrain instead of vanilla generation\n --frames N Exit after N frames (testing)\n --world-frames N Exit after N frames drawn in the world (testing)\n --smoke-report PATH Write a JSON report on exit\n --benchmark SCENARIO Run a benchmark (standard, village, forest, ocean, mountain), write its report to benchmarks/ and quit\n --control Accept horizon-ctl commands on a local socket\n --control-socket PATH Control socket path (default $XDG_RUNTIME_DIR/horizon-control.sock)\n --server HOST[:PORT] Join a multiplayer server (offline mode) at start\n --name NAME Player name for multiplayer (default: generated once, kept in horizon-player.txt)\n --session-file PATH Signed-in account from the launcher (read once, then deleted)\n --dev-mod PATH A Horizon mod (.hmod or folder) to develop: always on, reloaded when rebuilt\n\nControls: mouse look, WASD move, Space jump, Left Shift sneak, Left Ctrl sprint,\nleft click break, right click place/use, 1-9/scroll hotbar, E inventory,\nQ drop, F3 debug, Esc pause." + "Horizon — Minecraft Java Edition {} in Rust\n\n --resources PATH Prepared resources (horizon-prepare)\n --render-distance N Chunks, 2..64 (default 12)\n --world NAME World folder under saves/ (default \"New World\")\n --seed N World seed for new worlds (default 0)\n --creative Creative mode (default survival)\n --test-terrain Simple test terrain instead of vanilla generation\n --frames N Exit after N frames (testing)\n --world-frames N Exit after N frames drawn in the world (testing)\n --smoke-report PATH Write a JSON report on exit\n --benchmark SCENARIO Run a benchmark (standard, village, forest, ocean, mountain), write its report to benchmarks/ and quit\n --control Accept horizon-ctl commands on a local socket\n --control-socket PATH Control socket path (default $XDG_RUNTIME_DIR/horizon-control.sock)\n --server HOST[:PORT] Join a multiplayer server (offline mode) at start\n --name NAME Player name for multiplayer (default: generated once, kept in horizon-player.txt)\n --session-file PATH Signed-in account from the launcher (read once, then deleted)\n --dev-mod PATH A Horizon mod (.hmod or folder) to develop: always on, reloaded when rebuilt\n\nControls: mouse look, WASD move, Space jump, Left Shift sneak, Left Ctrl sprint,\nleft click break, right click place/use, 1-9/scroll hotbar, E inventory,\nQ drop, F3 debug, Esc pause.", + horizon_core::VANILLA_VERSION ); return Ok(None); } diff --git a/crates/horizon-client/src/game/commands/extra.rs b/crates/horizon-client/src/game/commands/extra.rs index 7a4accb0d..ef69be6d9 100644 --- a/crates/horizon-client/src/game/commands/extra.rs +++ b/crates/horizon-client/src/game/commands/extra.rs @@ -59,12 +59,7 @@ pub(in crate::game) struct CommandExtras { pub results: Option>, } -/// `version.json` of the 26.3 jars. -const VERSION_ID: &str = "26.3"; -const DATA_VERSION: i32 = 5023; -const STABLE: bool = true; -/// `Date.toString()` of the build time in UTC. -const BUILD_TIME: &str = "Tue Sep 15 11:20:48 UTC 2026"; +use horizon_core::version::{BUILD_TIME, DATA_VERSION, STABLE, VANILLA_VERSION, VERSION_ID}; fn num(n: impl std::fmt::Display) -> Text { Text::literal(n.to_string()) @@ -974,7 +969,10 @@ impl Game<'_> { let protocol = horizon_protocol::PROTOCOL_VERSION; let mut lines: Vec = [ ("commands.version.id", vec![Text::literal(VERSION_ID)]), - ("commands.version.name", vec![Text::literal(VERSION_ID)]), + ( + "commands.version.name", + vec![Text::literal(VANILLA_VERSION)], + ), ("commands.version.data", vec![num(DATA_VERSION)]), ("commands.version.series", vec![Text::literal("main")]), ( diff --git a/crates/horizon-client/src/game/dedicated.rs b/crates/horizon-client/src/game/dedicated.rs index 8495ea129..44bd94082 100644 --- a/crates/horizon-client/src/game/dedicated.rs +++ b/crates/horizon-client/src/game/dedicated.rs @@ -484,7 +484,13 @@ impl Game<'_> { }) }, )); - log("INFO", "Starting minecraft server version 26.3"); + log( + "INFO", + &format!( + "Starting minecraft server version {}", + horizon_core::VANILLA_VERSION + ), + ); log("INFO", "Loading properties"); let game_mode = props.game_mode; log( diff --git a/crates/horizon-client/src/game/tnt.rs b/crates/horizon-client/src/game/tnt.rs index 80ad97d7f..8368b5d28 100644 --- a/crates/horizon-client/src/game/tnt.rs +++ b/crates/horizon-client/src/game/tnt.rs @@ -488,7 +488,8 @@ mod tests { #[test] fn primed_tnt_follows_water_currents_after_moving() { let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) - .join("../../.local/horizon-client/26.3"); + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("movement-properties.nbt").exists() { return; } diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 09e079e2a..1e816fc5c 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -4476,7 +4476,8 @@ mod sprite_upload_tests { #[test] fn real_rail_mips_do_not_change_with_larger_array_layers() { let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) - .join("../../.local/horizon-client/26.3"); + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root .join("assets/minecraft/textures/block/rail.png") .exists() diff --git a/crates/horizon-client/src/lan/conn.rs b/crates/horizon-client/src/lan/conn.rs index 2805cf1da..d5dbeb6cd 100644 --- a/crates/horizon-client/src/lan/conn.rs +++ b/crates/horizon-client/src/lan/conn.rs @@ -326,7 +326,10 @@ fn serve_legacy(mut stream: TcpStream, shared: &Shared) -> Result<(), String> { return Ok(()); } } - format!("\u{a7}1\0127\026.3\0{motd}\0{online}\0{max}") + format!( + "\u{a7}1\0127\0{}\0{motd}\0{online}\0{max}", + horizon_core::VANILLA_VERSION + ) }; let units: Vec = body.encode_utf16().collect(); let mut out = vec![0xFF]; diff --git a/crates/horizon-client/src/menu.rs b/crates/horizon-client/src/menu.rs index f5d8c8480..6dc8d7b7f 100644 --- a/crates/horizon-client/src/menu.rs +++ b/crates/horizon-client/src/menu.rs @@ -2014,7 +2014,8 @@ pub(crate) mod tests { /// A menu over the game's data (`.local/horizon-client`); skipped without it. pub(crate) fn with_menu(kind: Kind, test: impl FnOnce(&Env, &mut Menu)) { let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) - .join("../../.local/horizon-client/26.3"); + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("items.json").exists() { return; } diff --git a/crates/horizon-client/src/motion.rs b/crates/horizon-client/src/motion.rs index f8052a747..40f4d0657 100644 --- a/crates/horizon-client/src/motion.rs +++ b/crates/horizon-client/src/motion.rs @@ -2020,7 +2020,9 @@ mod tests { let root = std::env::var_os("HORIZON_TEST_RESOURCES") .map(std::path::PathBuf::from) .unwrap_or_else(|| { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3") + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION) }); if !root.join("movement-properties.nbt").exists() { eprintln!("skipped sword sweep regression: prepared resources unavailable"); @@ -2054,7 +2056,9 @@ mod tests { let root = std::env::var_os("HORIZON_TEST_RESOURCES") .map(std::path::PathBuf::from) .unwrap_or_else(|| { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3") + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION) }); if !root.join("movement-properties.nbt").exists() { return; @@ -2126,7 +2130,9 @@ mod tests { #[test] fn spectator_scroll_speed_controls_horizontal_and_vertical_flight() { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("movement-properties.nbt").exists() { return; } @@ -2167,7 +2173,9 @@ mod tests { #[test] fn resident_spectator_flight_ignores_solid_and_climbable_blocks() { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("movement-properties.nbt").exists() { return; } @@ -2230,7 +2238,9 @@ mod tests { let root = std::env::var_os("HORIZON_TEST_RESOURCES") .map(std::path::PathBuf::from) .unwrap_or_else(|| { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3") + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION) }); if !root.join("movement-properties.nbt").exists() { eprintln!("skipped hunger regression: prepared resources unavailable"); @@ -2297,7 +2307,9 @@ mod tests { let root = std::env::var_os("HORIZON_TEST_RESOURCES") .map(std::path::PathBuf::from) .unwrap_or_else(|| { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3") + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION) }); if !root.join("movement-properties.nbt").exists() { eprintln!("skipped damage regression: prepared resources unavailable"); @@ -2474,7 +2486,9 @@ mod tests { /// per `nextStep` metre while walking. #[test] fn resident_water_landing_cancels_a_preset_fall() { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("movement-properties.nbt").exists() { return; } @@ -2519,7 +2533,9 @@ mod tests { let root = std::env::var_os("HORIZON_TEST_RESOURCES") .map(std::path::PathBuf::from) .unwrap_or_else(|| { - Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3") + Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION) }); if !root.join("movement-properties.nbt").exists() { eprintln!("skipping resident water/lava test: prepared resources unavailable"); @@ -2776,7 +2792,9 @@ mod tests { #[test] fn resident_swimming_uses_previous_eyes_and_requires_water_at_the_feet() { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("movement-properties.nbt").exists() { return; } @@ -2849,7 +2867,9 @@ mod tests { #[test] fn resident_fire_precedes_first_tick_lava_and_water_extinguishing() { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("movement-properties.nbt").exists() { return; } @@ -2901,7 +2921,9 @@ mod tests { #[test] fn resident_bubble_columns_and_nautilus_preserve_their_air_rules() { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("movement-properties.nbt").exists() { return; } @@ -2971,7 +2993,9 @@ mod tests { #[test] fn resident_mixed_fluids_use_lava_height_for_ground_jumps() { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("movement-properties.nbt").exists() { return; } @@ -3020,7 +3044,9 @@ mod tests { #[test] fn footsteps_follow_the_walked_distance_not_the_tick() { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("movement-properties.nbt").exists() { return; } diff --git a/crates/horizon-client/src/packs.rs b/crates/horizon-client/src/packs.rs index 4c3972291..7af7518f8 100644 --- a/crates/horizon-client/src/packs.rs +++ b/crates/horizon-client/src/packs.rs @@ -15,7 +15,7 @@ use std::{ }; /// SharedConstants resource pack format of 26.3 (major, minor). -pub const RESOURCE_FORMAT: (i64, i64) = (97, 1); +pub const RESOURCE_FORMAT: (i64, i64) = horizon_core::version::RESOURCE_PACK_FORMAT; #[derive(Clone, Debug)] pub enum Source { diff --git a/crates/horizon-client/src/random_tick_sections.rs b/crates/horizon-client/src/random_tick_sections.rs index cd06f2ac9..ce5da051b 100644 --- a/crates/horizon-client/src/random_tick_sections.rs +++ b/crates/horizon-client/src/random_tick_sections.rs @@ -206,12 +206,16 @@ mod tick_parity { .map(PathBuf::from) .unwrap_or_else(|| { let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let local = manifest.join("../../.local/horizon-client/26.3"); + let local = manifest + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if local.join("gameplay-facts.json").exists() { local } else { // The branch worktree lives below the main checkout. - manifest.join("../../../../.local/horizon-client/26.3") + manifest + .join("../../../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION) } }); if !root.join("gameplay-facts.json").exists() { diff --git a/crates/horizon-client/src/save.rs b/crates/horizon-client/src/save.rs index 83c81bf67..f46be9ccc 100644 --- a/crates/horizon-client/src/save.rs +++ b/crates/horizon-client/src/save.rs @@ -46,7 +46,7 @@ use std::{ }, }; -pub const VERSION_NAME: &str = "26.3"; +pub const VERSION_NAME: &str = horizon_core::VANILLA_VERSION; /// Snapshot live block entities and custom names for a save batch without /// mutating the world. Each map is visited once, retaining its iteration order diff --git a/crates/horizon-client/src/sprites.rs b/crates/horizon-client/src/sprites.rs index c26e02ea7..e3caf1de4 100644 --- a/crates/horizon-client/src/sprites.rs +++ b/crates/horizon-client/src/sprites.rs @@ -415,7 +415,9 @@ mod tests { #[test] fn native_fire_sprites_register_full_animation_sequences() { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root .join("assets/minecraft/textures/block/fire_0.png") .exists() diff --git a/crates/horizon-client/src/stations.rs b/crates/horizon-client/src/stations.rs index 613086112..20750d6fe 100644 --- a/crates/horizon-client/src/stations.rs +++ b/crates/horizon-client/src/stations.rs @@ -877,7 +877,9 @@ mod tests { /// Checks against the prepared vanilla resources when they are present. #[test] fn prepared_vanilla_data() { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); if !root.join("items.json").exists() { return; } diff --git a/crates/horizon-client/src/title.rs b/crates/horizon-client/src/title.rs index 172fb821a..17684602c 100644 --- a/crates/horizon-client/src/title.rs +++ b/crates/horizon-client/src/title.rs @@ -825,8 +825,8 @@ impl Title { ]; } } - let version = "Horizon 26.3 (Rust)"; - batch.text(atlas, version, 2.0, h - 10.0, u32::MAX, true); + let version = format!("Horizon {} (Rust)", horizon_core::VANILLA_VERSION); + batch.text(atlas, &version, 2.0, h - 10.0, u32::MAX, true); let notice = "Not affiliated with Mojang or Microsoft"; let tw = HudBatch::text_width(atlas, notice); batch.text(atlas, notice, w - tw - 2.0, h - 10.0, u32::MAX, true); diff --git a/crates/horizon-client/src/title_edition.rs b/crates/horizon-client/src/title_edition.rs index 80c114dcf..e27cf042f 100644 --- a/crates/horizon-client/src/title_edition.rs +++ b/crates/horizon-client/src/title_edition.rs @@ -469,13 +469,14 @@ mod tests { /// Against the prepared vanilla resources when they are present. #[test] fn prepared_vanilla_edition() { - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join( - "../../.local/horizon-client/26.3/assets/minecraft/textures/gui/title/edition.png", - ); + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION) + .join("assets/minecraft/textures/gui/title/edition.png"); let Ok((w, h, pixels)) = crate::hud::decode(&path) else { return; }; - let out = rust_edition(w, h, &pixels).expect("vanilla 26.3's edition.png"); + let out = rust_edition(w, h, &pixels).expect("vanilla's edition.png"); assert_eq!( columns(&out, EDITION_START..WIDTH), columns(&pixels, EDITION_START..WIDTH) diff --git a/crates/horizon-client/tests/generation_saves.rs b/crates/horizon-client/tests/generation_saves.rs index df47d1fa3..30b971e05 100644 --- a/crates/horizon-client/tests/generation_saves.rs +++ b/crates/horizon-client/tests/generation_saves.rs @@ -24,7 +24,9 @@ use std::{ }; fn resources() -> Option { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); root.join("items.json").exists().then_some(root) } diff --git a/crates/horizon-client/tests/lan_bot.rs b/crates/horizon-client/tests/lan_bot.rs index 18af20343..79d411386 100644 --- a/crates/horizon-client/tests/lan_bot.rs +++ b/crates/horizon-client/tests/lan_bot.rs @@ -34,7 +34,9 @@ use std::{ }; fn resources() -> Option { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); root.join("items.json").exists().then_some(root) } @@ -305,7 +307,10 @@ fn status_and_join() { Ok(r.json) }); let v: serde_json::Value = serde_json::from_str(&json).unwrap(); - assert_eq!(v["version"]["protocol"], 777); + assert_eq!( + v["version"]["protocol"], + horizon_core::version::PROTOCOL_VERSION + ); // ServerStatus.CODEC writes a plain literal MOTD as a bare string. assert_eq!(v["description"], "Test - World"); diff --git a/crates/horizon-client/tests/streaming_meshes.rs b/crates/horizon-client/tests/streaming_meshes.rs index 3aa30a330..f0b6fb038 100644 --- a/crates/horizon-client/tests/streaming_meshes.rs +++ b/crates/horizon-client/tests/streaming_meshes.rs @@ -26,7 +26,9 @@ use std::{ }; fn resources() -> Option { - let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3"); + let root = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION); root.join("items.json").exists().then_some(root) } diff --git a/crates/horizon-core/src/lib.rs b/crates/horizon-core/src/lib.rs index 5b46ce2ef..c8077b327 100644 --- a/crates/horizon-core/src/lib.rs +++ b/crates/horizon-core/src/lib.rs @@ -1,4 +1,4 @@ -//! Horizon's initial simulation primitives, targeting Minecraft Java Edition 26.3. +//! Horizon's initial simulation primitives, targeting the Minecraft Java Edition version in [`version`]. //! //! This is not a playable game. Differential checks cover only the operations //! listed in docs/rust-parity.md; the rest of vanilla remains unimplemented. @@ -17,4 +17,6 @@ pub mod storage; pub mod text; pub mod ticks; -pub const VANILLA_VERSION: &str = "26.3"; +pub mod version; + +pub use version::VANILLA_VERSION; diff --git a/crates/horizon-core/src/version.rs b/crates/horizon-core/src/version.rs new file mode 100644 index 000000000..29994823c --- /dev/null +++ b/crates/horizon-core/src/version.rs @@ -0,0 +1,21 @@ +//! What Minecraft 26.3 states about itself (the client jar's `version.json`, +//! `SharedConstants.getCurrentVersion()`). Generated by tools/gen_version_consts.py; do not edit by hand. + +/// `WorldVersion.id()`. +pub const VERSION_ID: &str = "26.3"; +/// `WorldVersion.name()`: level.dat, the server list, crash reports. +pub const VANILLA_VERSION: &str = "26.3"; +/// `SharedConstants.getProtocolVersion()`. +pub const PROTOCOL_VERSION: i32 = 777; +/// `WorldVersion.dataVersion()`: the DataVersion of saved chunks, entities and level.dat. +pub const DATA_VERSION: i32 = 5023; +/// `WorldVersion.packVersion(PackType.CLIENT_RESOURCES)`: (major, minor). +pub const RESOURCE_PACK_FORMAT: (i64, i64) = (97, 1); +/// `WorldVersion.packVersion(PackType.SERVER_DATA)`: (major, minor). +pub const DATA_PACK_FORMAT: (i64, i64) = (121, 0); +/// The Java major version the game runs on. +pub const JAVA_VERSION: u32 = 25; +/// `WorldVersion.stable()`: false for snapshots and pre-releases. +pub const STABLE: bool = true; +/// `WorldVersion.buildTime()` as `Date.toString()` prints it in UTC (`/version`). +pub const BUILD_TIME: &str = "Tue Sep 15 11:20:48 UTC 2026"; diff --git a/crates/horizon-protocol/Cargo.toml b/crates/horizon-protocol/Cargo.toml index 66a0af162..05655e8af 100644 --- a/crates/horizon-protocol/Cargo.toml +++ b/crates/horizon-protocol/Cargo.toml @@ -7,6 +7,7 @@ rust-version.workspace = true description = "Horizon's Minecraft Java Edition 26.3 network protocol (version 777)" [dependencies] +horizon-core = { path = "../horizon-core" } horizon-world = { path = "../horizon-world" } flate2 = { version = "1.1.10", default-features = false, features = ["zlib-rs", "runtime_detection"] } serde_json = "1.0.151" diff --git a/crates/horizon-protocol/src/lib.rs b/crates/horizon-protocol/src/lib.rs index 1d0f081f7..855df6a5a 100644 --- a/crates/horizon-protocol/src/lib.rs +++ b/crates/horizon-protocol/src/lib.rs @@ -1,4 +1,4 @@ -//! The Minecraft Java Edition 26.3 network protocol (protocol version 777): +//! The Minecraft Java Edition network protocol (of the version in `horizon_core::version`): //! primitive codecs, framing, compression, encryption, and typed packets for //! every connection state, shared by the Horizon client and (later) server. #![forbid(unsafe_code)] @@ -17,10 +17,10 @@ pub mod secure_chat; pub mod servers; pub mod text; -/// SharedConstants.getProtocolVersion() for 26.3. -pub const PROTOCOL_VERSION: i32 = 777; +/// SharedConstants.getProtocolVersion(). +pub const PROTOCOL_VERSION: i32 = horizon_core::version::PROTOCOL_VERSION; /// The game version servers report in their status. -pub const GAME_VERSION: &str = "26.3"; +pub const GAME_VERSION: &str = horizon_core::VANILLA_VERSION; /// Connection protocol states (ConnectionProtocol). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] diff --git a/crates/horizon-world/src/datafix/files.rs b/crates/horizon-world/src/datafix/files.rs index 6237f2c64..07cf676f9 100644 --- a/crates/horizon-world/src/datafix/files.rs +++ b/crates/horizon-world/src/datafix/files.rs @@ -15,7 +15,7 @@ use std::io; use std::path::{Path, PathBuf}; /// The name `SharedConstants.getCurrentVersion().name()` writes in level.dat. -pub const VERSION_NAME: &str = "26.3"; +pub const VERSION_NAME: &str = horizon_core::version::VANILLA_VERSION; const FILE_FIXER_INTRODUCTION: i32 = 4772; /// The versions of the file fixes, in order. diff --git a/crates/horizon-world/src/level/growth_tests.rs b/crates/horizon-world/src/level/growth_tests.rs index ad66b5718..b72ccbcba 100644 --- a/crates/horizon-world/src/level/growth_tests.rs +++ b/crates/horizon-world/src/level/growth_tests.rs @@ -21,7 +21,8 @@ fn fixture() -> Option<&'static Fixture> { .map(PathBuf::from) .unwrap_or_else(|| { PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("../../.local/horizon-client/26.3") + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION) }); // Trees need the feature block-behaviour exports in the worldgen bundle. if !root.join("block-behaviours.json").exists() diff --git a/crates/horizon-world/src/level/tests.rs b/crates/horizon-world/src/level/tests.rs index c0ceddc6f..1a1b9ebae 100644 --- a/crates/horizon-world/src/level/tests.rs +++ b/crates/horizon-world/src/level/tests.rs @@ -1,5 +1,5 @@ //! Behaviour tests over an in-memory level. They need the prepared client -//! resources (`HORIZON_RESOURCES`, or `.local/horizon-client/26.3` at the +//! resources (`HORIZON_RESOURCES`, or `.local/horizon-client/` at the //! repository root) and are skipped when those are absent. use super::*; use crate::chunk::BlockState; @@ -22,7 +22,8 @@ fn fixture() -> Option<&'static Fixture> { .map(PathBuf::from) .unwrap_or_else(|| { PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("../../.local/horizon-client/26.3") + .join("../../.local/horizon-client") + .join(horizon_core::VANILLA_VERSION) }); if !root.join("block-behaviours.json").exists() { eprintln!("skipping level tests: no resources at {}", root.display()); diff --git a/crates/horizon-world/src/lib.rs b/crates/horizon-world/src/lib.rs index a055ec5ab..819262d46 100644 --- a/crates/horizon-world/src/lib.rs +++ b/crates/horizon-world/src/lib.rs @@ -122,7 +122,7 @@ pub mod world_movement; pub mod world_ray; pub mod worldgen; -pub const DATA_VERSION: i32 = 5023; +pub const DATA_VERSION: i32 = horizon_core::version::DATA_VERSION; pub mod item_stack_refs; pub mod simple_container; diff --git a/crates/horizon-world/src/main.rs b/crates/horizon-world/src/main.rs index ff61c99dd..aa9c60ba9 100644 --- a/crates/horizon-world/src/main.rs +++ b/crates/horizon-world/src/main.rs @@ -51,7 +51,7 @@ fn run(args: &[String]) -> Result<(), Box> { }; match command { "--help" | "-h" if args.len() == 1 => println!( - "Horizon world data tools — Java Edition 26.3\n\ + "Horizon world data tools — Java Edition {}\n\ inspect \n\ copy-region [gzip|zlib|none|lz4]\n\ get-block \n\ @@ -59,7 +59,8 @@ fn run(args: &[String]) -> Result<(), Box> { nbt-copy \n\ nbt-network-copy \n\ Existing output files are refused. edit-block-data changes saved block data only;\n\ - it does not run lighting, heightmaps, ticks or neighbor updates." + it does not run lighting, heightmaps, ticks or neighbor updates.", + horizon_core::VANILLA_VERSION ), "nbt-copy" | "nbt-network-copy" if args.len() == 5 => { let bytes = diff --git a/docs/version-ports.md b/docs/version-ports.md index 39765044e..cdc2b37de 100644 --- a/docs/version-ports.md +++ b/docs/version-ports.md @@ -25,23 +25,20 @@ to players. Players still prepare their own copy from their official launcher (` exporters (`mods/horizon/src/test/java/dev/horizonlab/parity/Vanilla*Exporter.java`) against the jar for block behaviours, worldgen bundles and the like. CI does the same through `tools/ci/vanilla-data.sh`, keyed by the version in `research-lock.json`. -- **Version facts baked into the code.** The client jar's own `version.json` states them (26.3: world version 5023, - protocol 777, resource pack 97.1, data pack 121.0, Java 25); Horizon copies them by hand today: - - | Where | What | - | --- | --- | - | `crates/horizon-core/src/lib.rs` | `VANILLA_VERSION` | - | `crates/horizon-protocol/src/lib.rs` | `PROTOCOL_VERSION`, `GAME_VERSION` | - | `crates/horizon-protocol/src/packets/configuration.rs` | the `minecraft:core` known pack version | - | `crates/horizon-world/src/lib.rs`, `crates/horizon-client/src/game/commands/extra.rs` | `DATA_VERSION` (twice) | - | `crates/horizon-client/src/save.rs`, `crates/horizon-world/src/datafix/files.rs`, `game/commands/extra.rs` | the version name (three times) | - | `crates/horizon-client/src/crash.rs`, `bin/horizon-ctl/launch.rs`, `launcher/src/backend.rs` | `"26.3"` fallbacks | - | `tools/perf_bench.py`, `tools/vanilla_client.py` | the vanilla client's `--version` | +- **Version facts in the code.** The client jar's own `version.json` states them (26.3: world version 5023, + protocol 777, resource pack 97.1, data pack 121.0, Java 25). `tools/gen_version_consts.py` writes them into + one generated file, `crates/horizon-core/src/version.rs` (`VANILLA_VERSION`, `PROTOCOL_VERSION`, + `DATA_VERSION`, the pack formats, Java, `/version`'s build time), and every Rust site reads them from there + (`horizon_protocol::PROTOCOL_VERSION`, `horizon_world::DATA_VERSION` and the save's version name are aliases + of it; the status, the legacy ping, the crash report, `/version`, the title screens and the default resource + folder use it). CI checks the file against the pinned jar (`--check`). Test fixtures that state a version + (a level.dat to read, a relay message) keep their literals: they test parsing, not the pin. - **Generated tables** (each has its generator in `tools/`): | Output | Generator | Input | | --- | --- | --- | + | `crates/horizon-core/src/version.rs` | `gen_version_consts.py` | the client jar's `version.json` | | `crates/horizon-protocol/src/ids.rs` | `generate_packet_ids.py` | `packets.json` report | | `crates/horizon-client/src/lan/tracking.rs` | `generate_entity_tracking.py` | decompiled `EntityTypes` | | `crates/horizon-client/src/lan/command_suggestions.rs` | `generate_command_suggestions.py` | `VanillaCommandSuggestionsExporter` | @@ -298,4 +295,5 @@ python3 tools/vanilla_map.py versions/26.3/classes.json net.minecraft.world.food | `detect`, `prepare`, `diff` (facts, packets, registries, blocks, items, commands, data, assets), `gc` | done | | Class index (`tools/class_index.py`), class diff with moves, `vanilla_map.json` (`tools/vanilla_map.py`) | done | | Port report (`tools/port_report.py`, `report`), `port` | done | -| Changed-class decompilation, `regen`, `version_consts` refactor, candidate harness run, `publish`, launchd agent | later | +| `version_consts`: one generated file for the version facts (`tools/gen_version_consts.py`) | done | +| Changed-class decompilation, `regen`, candidate harness run, `publish`, launchd agent | later | diff --git a/launcher/Cargo.lock b/launcher/Cargo.lock index da40a5694..b48a90543 100644 --- a/launcher/Cargo.lock +++ b/launcher/Cargo.lock @@ -2637,6 +2637,13 @@ dependencies = [ "serde_json", ] +[[package]] +name = "horizon-core" +version = "0.1.0" +dependencies = [ + "libm", +] + [[package]] name = "horizon-friends" version = "0.1.0" @@ -2663,6 +2670,7 @@ dependencies = [ "getrandom 0.3.4", "gpui", "horizon-bench", + "horizon-core", "horizon-friends", "horizon-port-pack", "horizon-prepare", diff --git a/launcher/Cargo.toml b/launcher/Cargo.toml index 6895deb3a..d6225cb96 100644 --- a/launcher/Cargo.toml +++ b/launcher/Cargo.toml @@ -22,6 +22,7 @@ dirs = "5" self-replace = "1" clap = { version = "4", features = ["derive"] } horizon-theme = { path = "../crates/horizon-theme" } +horizon-core = { path = "../crates/horizon-core" } horizon-prepare = { path = "../crates/horizon-prepare" } # Join a friend: invite codes (the game does the joining). horizon-friends = { path = "../crates/horizon-friends" } diff --git a/launcher/src/backend.rs b/launcher/src/backend.rs index 35a69da8c..74a4cb687 100644 --- a/launcher/src/backend.rs +++ b/launcher/src/backend.rs @@ -479,7 +479,7 @@ fn read_json(path: &Path) -> Option { fn game_version_at(dir: &Path) -> String { read_json(&dir.join("research-lock.json")) .and_then(|v| v["minecraft"]["version"].as_str().map(String::from)) - .unwrap_or_else(|| "26.3".into()) + .unwrap_or_else(|| horizon_core::VANILLA_VERSION.into()) } pub fn resources(tag: &str) -> PathBuf { diff --git a/launcher/src/desktop.rs b/launcher/src/desktop.rs index 430043dca..1c9fe931e 100644 --- a/launcher/src/desktop.rs +++ b/launcher/src/desktop.rs @@ -80,7 +80,7 @@ pub fn launcher_entry(exe: &Path) -> String { Type=Application\n\ Name=Horizon\n\ GenericName=Game launcher\n\ - Comment=Install, prepare and play Horizon, Minecraft: Java Edition 26.3 rewritten in Rust\n\ + Comment=Install, prepare and play Horizon, Minecraft: Java Edition {minecraft} rewritten in Rust\n\ Exec={}\n\ TryExec={}\n\ Icon=horizon\n\ @@ -88,7 +88,8 @@ pub fn launcher_entry(exe: &Path) -> String { Categories=Game;\n\ StartupWMClass=horizon-launcher\n", quote(exe), - exe.display() + exe.display(), + minecraft = horizon_core::VANILLA_VERSION, ) } diff --git a/launcher/src/mcp.rs b/launcher/src/mcp.rs index 906cd089f..ca2a81a87 100644 --- a/launcher/src/mcp.rs +++ b/launcher/src/mcp.rs @@ -31,7 +31,7 @@ fn tools() -> Value { "inputSchema": { "type": "object", "properties": { "tag": { "type": "string", "description": "A release tag such as v2026.10.13, or \"latest\"." } }, "required": ["tag"] } }, { "name": "remove_version", "description": "Remove an installed Horizon version and its prepared resources.", "inputSchema": { "type": "object", "properties": { "tag": { "type": "string" } }, "required": ["tag"] } }, - { "name": "prepare_resources", "description": "Prepare a version's resources from the player's own Minecraft install (needs Minecraft 26.3 played once in the official launcher and Java 25; versions before horizon-prepare also need Python 3.10+). Can take several minutes; returns the end of the log.", + { "name": "prepare_resources", "description": "Prepare a version's resources from the player's own Minecraft install (needs the Minecraft release that version is built for, played once in the official launcher, and its Java; versions before horizon-prepare also need Python 3.10+). Can take several minutes; returns the end of the log.", "inputSchema": { "type": "object", "properties": { "version": version, "minecraft_dir": { "type": "string", "description": "The game folder of the official launcher, Prism Launcher, MultiMC, the Modrinth App, ATLauncher or GDLauncher. Default: the launcher's setting, then every launcher's default folder." } } } }, { "name": "launch_client", "description": "Start the Horizon client (a game window on the player's screen) under agent control: the game_* tools then play it. Returns once it has started; game_wait_ready waits for the world.", "inputSchema": { "type": "object", "properties": { "version": version, diff --git a/tests/test_gen_version_consts.py b/tests/test_gen_version_consts.py new file mode 100644 index 000000000..61b12e62f --- /dev/null +++ b/tests/test_gen_version_consts.py @@ -0,0 +1,48 @@ +import json +from pathlib import Path +import re +import tempfile +import unittest +import zipfile + +from tools import gen_version_consts as gen +from tools import lab + +INFO = { + "id": "26.4", "name": "26.4", "world_version": 5100, "protocol_version": 780, + "pack_version": {"resource_major": 99, "resource_minor": 0, "data_major": 124, "data_minor": 2}, + "build_time": "2026-12-01T09:05:07+00:00", "java_version": 25, "stable": False, +} + + +class GenVersionConstsTests(unittest.TestCase): + def test_renders_every_fact(self): + text = gen.render(INFO) + for line in ['pub const VERSION_ID: &str = "26.4";', 'pub const VANILLA_VERSION: &str = "26.4";', + "pub const PROTOCOL_VERSION: i32 = 780;", "pub const DATA_VERSION: i32 = 5100;", + "pub const RESOURCE_PACK_FORMAT: (i64, i64) = (99, 0);", + "pub const DATA_PACK_FORMAT: (i64, i64) = (124, 2);", "pub const JAVA_VERSION: u32 = 25;", + "pub const STABLE: bool = false;", 'pub const BUILD_TIME: &str = "Tue Dec 01 09:05:07 UTC 2026";']: + self.assertIn(line, text) + + def test_build_time_is_printed_in_utc(self): + self.assertEqual(gen.java_date("2026-09-15T13:20:48+02:00"), "Tue Sep 15 11:20:48 UTC 2026") + + def test_reads_the_jar(self): + with tempfile.TemporaryDirectory() as directory: + jar = Path(directory) / "client.jar" + with zipfile.ZipFile(jar, "w") as archive: + archive.writestr("version.json", json.dumps(INFO)) + self.assertEqual(gen.jar_info(jar), INFO) + + def test_committed_file_is_the_pinned_version(self): + """A pin bump regenerates version.rs: the lock and the constants never disagree.""" + text = gen.OUT.read_text() + pinned = json.loads(lab.LOCK.read_text())["minecraft"] + self.assertEqual(re.search(r'VANILLA_VERSION: &str = "([^"]+)"', text)[1], pinned["version"]) + self.assertEqual(int(re.search(r"JAVA_VERSION: u32 = (\d+)", text)[1]), pinned["java_major"]) + self.assertIn("Generated by tools/gen_version_consts.py", text) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_port_report.py b/tests/test_port_report.py index 75e9a3a40..f1a8e1f35 100644 --- a/tests/test_port_report.py +++ b/tests/test_port_report.py @@ -72,12 +72,13 @@ class PortReportTests(unittest.TestCase): built = self.build() kinds = [(i["rank"], i["kind"]) for i in built["items"]] self.assertEqual(sorted(k for r, k in kinds if r == 1), - ["components", "facts", "protocol", "regenerate", "regenerate", "report-format", - "save-format"]) + ["components", "facts", "protocol", "regenerate", "regenerate", "regenerate", + "report-format", "save-format"]) self.assertEqual([i["id"] for i in built["items"]], list(range(1, len(kinds) + 1))) self.assertEqual(kinds, sorted(kinds, key=lambda k: k[0])) regenerated = {i["files"][0] for i in built["items"] if i["kind"] == "regenerate"} - self.assertEqual(regenerated, {"crates/horizon-protocol/src/ids.rs", "crates/horizon-client/src/lan/tracking.rs"}) + self.assertEqual(regenerated, {"crates/horizon-core/src/version.rs", "crates/horizon-protocol/src/ids.rs", + "crates/horizon-client/src/lan/tracking.rs"}) def test_save_format_lists_new_schemas_and_fixes(self): save = next(i for i in self.build()["items"] if i["kind"] == "save-format") diff --git a/tools/gen_version_consts.py b/tools/gen_version_consts.py new file mode 100644 index 000000000..07cecd747 --- /dev/null +++ b/tools/gen_version_consts.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +"""Generate crates/horizon-core/src/version.rs: what the pinned Minecraft version states about itself in its +client jar's version.json (name, protocol, data version, pack formats, Java, build time). Every Rust site that +needs one of these facts reads it from there, so a version bump rewrites this one file +(docs/version-ports.md, "Regenerate"). + + gen_version_consts.py [--jar CLIENT_JAR] [--out PATH] [--check] + +The default jar is the pinned one (.local/minecraft//jars/client.jar). +--check exits 1 when the committed file differs from what the jar says. +""" + +import argparse +from datetime import datetime, timezone +import json +from pathlib import Path +import sys +import zipfile + +try: + from . import lab +except ImportError: + import lab + +OUT = lab.ROOT / "crates/horizon-core/src/version.rs" + + +def jar_info(client_jar): + with zipfile.ZipFile(client_jar) as archive: + return json.loads(archive.read("version.json")) + + +def java_date(iso): + """`Date.toString()` of an ISO-8601 instant, in UTC (Locale.ROOT names).""" + return datetime.fromisoformat(iso).astimezone(timezone.utc).strftime("%a %b %d %H:%M:%S UTC %Y") + + +def render(info): + pack = info["pack_version"] + return "\n".join([ + f"//! What Minecraft {info['name']} states about itself (the client jar's `version.json`,", + "//! `SharedConstants.getCurrentVersion()`). Generated by tools/gen_version_consts.py; do not edit by hand.", + "", + "/// `WorldVersion.id()`.", + f"pub const VERSION_ID: &str = {json.dumps(info['id'])};", + "/// `WorldVersion.name()`: level.dat, the server list, crash reports.", + f"pub const VANILLA_VERSION: &str = {json.dumps(info['name'])};", + "/// `SharedConstants.getProtocolVersion()`.", + f"pub const PROTOCOL_VERSION: i32 = {info['protocol_version']};", + "/// `WorldVersion.dataVersion()`: the DataVersion of saved chunks, entities and level.dat.", + f"pub const DATA_VERSION: i32 = {info['world_version']};", + "/// `WorldVersion.packVersion(PackType.CLIENT_RESOURCES)`: (major, minor).", + f"pub const RESOURCE_PACK_FORMAT: (i64, i64) = ({pack['resource_major']}, {pack['resource_minor']});", + "/// `WorldVersion.packVersion(PackType.SERVER_DATA)`: (major, minor).", + f"pub const DATA_PACK_FORMAT: (i64, i64) = ({pack['data_major']}, {pack['data_minor']});", + "/// The Java major version the game runs on.", + f"pub const JAVA_VERSION: u32 = {info['java_version']};", + "/// `WorldVersion.stable()`: false for snapshots and pre-releases.", + f"pub const STABLE: bool = {'true' if info['stable'] else 'false'};", + "/// `WorldVersion.buildTime()` as `Date.toString()` prints it in UTC (`/version`).", + f"pub const BUILD_TIME: &str = {json.dumps(java_date(info['build_time']))};", + "", + ]) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--jar", type=Path, help="client jar (default: the pinned one in .local)") + parser.add_argument("--out", type=Path, default=OUT) + parser.add_argument("--check", action="store_true", help="exit 1 if --out differs instead of writing it") + args = parser.parse_args() + jar = args.jar or lab.config()[1] / "jars" / "client.jar" + text = render(jar_info(jar)) + if args.check: + if not args.out.exists() or args.out.read_text() != text: + print(f"{args.out} does not match {jar}; run tools/gen_version_consts.py", file=sys.stderr) + return 1 + return 0 + args.out.write_text(text) + print(f"wrote {args.out}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/port_report.py b/tools/port_report.py index afbb65861..94ad0b91d 100644 --- a/tools/port_report.py +++ b/tools/port_report.py @@ -30,6 +30,7 @@ PROTOCOL = "net/minecraft/network/protocol/" DATAFIX = "net/minecraft/util/datafix/" # Generated tables, what makes them stale, and how to regenerate them (docs/version-ports.md, "Regenerate"). GENERATORS = [ + ("crates/horizon-core/src/version.rs", "python3 tools/gen_version_consts.py", lambda d: bool(d["facts"])), ("crates/horizon-protocol/src/ids.rs", "python3 tools/generate_packet_ids.py", lambda d: bool(d["packets"])), ("crates/horizon-client/src/lan/tracking.rs", "python3 tools/generate_entity_tracking.py", diff --git a/tools/test_datafix_parity.py b/tools/test_datafix_parity.py index 8638c5cf1..a2d11009c 100644 --- a/tools/test_datafix_parity.py +++ b/tools/test_datafix_parity.py @@ -45,7 +45,7 @@ PARITY_SHARDS = 6 PARITY_RUST_SCOPE = [ 'crates/horizon-world/src/datafix/', 'crates/horizon-world/src/nbt.rs', 'crates/horizon-world/src/region.rs', 'crates/horizon-world/src/compression.rs', 'crates/horizon-core/src/position.rs', 'crates/horizon-core/src/position/', - 'crates/horizon-core/src/geometry/', + 'crates/horizon-core/src/geometry/', 'crates/horizon-core/src/version.rs', ] IGNORED = {