From 580c2b1dd790d19e7146159d91bd9f8fecb3f4f7 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 21:46:38 +0200 Subject: [PATCH] Motion: reuse the game's block facts for the fluid tables FluidResources decoded gameplay-facts.json a second time for three per-state columns the game's BlockFacts already has. With ATM10's carried mods that file is 211 MB: the second decode took a few seconds and peaked about 500 MB above what the game keeps. MotionResources::load_with_facts takes the game's facts; load still decodes them itself for tests and tools. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/examples/resource_memory.rs | 2 +- crates/horizon-client/src/game.rs | 2 +- crates/horizon-client/src/motion.rs | 17 ++++++++++++++++- crates/horizon-client/src/motion/fluids.rs | 3 +-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/examples/resource_memory.rs b/crates/horizon-client/examples/resource_memory.rs index c292ff2f4..1eb6c45b7 100644 --- a/crates/horizon-client/examples/resource_memory.rs +++ b/crates/horizon-client/examples/resource_memory.rs @@ -120,7 +120,7 @@ fn main() -> Result<()> { step("mesh tables"); let collision = collisions::load(&root, assets.registry)?; step("collision"); - let motion = MotionResources::load(&root, &assets)?; + let motion = MotionResources::load_with_facts(&root, &assets, &facts)?; step("motion"); let terrain = VanillaTerrain::new(&root.join("worldgen"), assets.registry, &biomes, 1234)?; step("worldgen"); diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 6de683c67..37b8b1919 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -10379,7 +10379,7 @@ pub fn run() -> Result<()> { log::info!("load atlas: {:.2}s", started.elapsed().as_secs_f32()); let registry_owner = assets.clone(); let collision = collisions::load(&root, registry_owner.registry)?; - let motion = MotionResources::load(&root, ®istry_owner)?; + let motion = MotionResources::load_with_facts(&root, ®istry_owner, &facts)?; log::info!( "load collision+motion: {:.2}s", started.elapsed().as_secs_f32() diff --git a/crates/horizon-client/src/motion.rs b/crates/horizon-client/src/motion.rs index 4c026ac45..321af2458 100644 --- a/crates/horizon-client/src/motion.rs +++ b/crates/horizon-client/src/motion.rs @@ -56,7 +56,22 @@ pub struct MotionResources { pub fluids: FluidResources, } impl MotionResources { + /// [`Self::load_with_facts`] with the block facts decoded here. pub fn load(root: &Path, assets: &Assets) -> Result { + Self::load_with_facts( + root, + assets, + &crate::blocks::BlockFacts::load(root, assets.registry)?, + ) + } + /// The motion tables, with the block facts the game already decoded + /// (decoding `gameplay-facts.json` again costs a second or more and, with + /// a big modpack, hundreds of megabytes while it runs). + pub fn load_with_facts( + root: &Path, + assets: &Assets, + facts: &crate::blocks::BlockFacts, + ) -> Result { let attributes = Arc::new(Catalog::from_json(&serde_json::from_slice(&fs::read( root.join("attributes.json"), )?)?)?); @@ -85,7 +100,7 @@ impl MotionResources { Ok(Self { landing: crate::landing::load(root, &properties)?, health: crate::health::HealthResources::load(root)?, - fluids: FluidResources::load(root, assets)?, + fluids: FluidResources::new(assets, facts)?, attributes, blocks: properties.bind(&MovementTags { fences: tag("minecraft:fences")?, diff --git a/crates/horizon-client/src/motion/fluids.rs b/crates/horizon-client/src/motion/fluids.rs index f85f755a9..89affeb64 100644 --- a/crates/horizon-client/src/motion/fluids.rs +++ b/crates/horizon-client/src/motion/fluids.rs @@ -33,8 +33,7 @@ pub struct FluidResources { pub shapes: Mutex, } impl FluidResources { - pub fn load(root: &Path, assets: &Assets) -> Result { - let facts = crate::blocks::BlockFacts::load(root, assets.registry)?; + pub fn new(assets: &Assets, facts: &crate::blocks::BlockFacts) -> Result { Ok(Self { states: FluidStateTable::new(assets.registry)?, sturdy: facts.states.iter().map(|s| s.sturdy_full).collect(),