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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-17 21:46:38 +02:00
parent 2e531f35e5
commit 580c2b1dd7
4 changed files with 19 additions and 5 deletions
@@ -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");
+1 -1
View File
@@ -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, &registry_owner)?;
let motion = MotionResources::load_with_facts(&root, &registry_owner, &facts)?;
log::info!(
"load collision+motion: {:.2}s",
started.elapsed().as_secs_f32()
+16 -1
View File
@@ -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> {
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<Self> {
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")?,
+1 -2
View File
@@ -33,8 +33,7 @@ pub struct FluidResources {
pub shapes: Mutex<FluidShapeCache>,
}
impl FluidResources {
pub fn load(root: &Path, assets: &Assets) -> Result<Self> {
let facts = crate::blocks::BlockFacts::load(root, assets.registry)?;
pub fn new(assets: &Assets, facts: &crate::blocks::BlockFacts) -> Result<Self> {
Ok(Self {
states: FluidStateTable::new(assets.registry)?,
sturdy: facts.states.iter().map(|s| s.sturdy_full).collect(),