Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
Entity models parsed at startup, not on first sight
Ludovic Marie491d9f5e25f4
diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rsindex 3721e78f3..969459a10 100644--- a/crates/horizon-client/src/game.rs+++ b/crates/horizon-client/src/game.rs@@ -2608,6 +2608,8 @@ struct Game<'a> {crystal_model: Option<horizon_client::mobs::Part>,/// CushionModel's baked layer.cushion_model: Option<horizon_client::mobs::Part>,+ /// Models drawn only once such an entity shows up (lead knots, wind charges...).+ entity_models: EntityModels,carts: Vec<minecarts::Minecart>,/// Songs playing from jukeboxes (tracked sound handles).jukebox_sounds: HashMap<(i32, i32, i32), u64>,@@ -18319,6 +18321,7 @@ impl<'a> Game<'a> {boat_models: prepared.boat_models,crystal_model: prepared.crystal_model,cushion_model: prepared.cushion_model,+ entity_models: prepared.entity_models,carts: Vec::new(),jukebox_sounds: HashMap::new(),bolts: Vec::new(),@@ -18525,8 +18528,41 @@ struct GameCpuResources {arrow_model: Option<horizon_client::mobs::Part>,bee_stinger_model: Option<horizon_client::mobs::Part>,trident_model: Option<horizon_client::mobs::Part>,+ entity_models: EntityModels,creative_screen: Creative,}+/// Baked layers of entities that may first show up deep into a session. They come from the+/// document parsed once at startup: parsing entity-models.json (2.4 MB) when the first one+/// appeared stalled that frame by 40 ms of CPU and the file read.+#[derive(Default)]+struct EntityModels {+ /// LeashKnotModel.+ leash_knot: Option<horizon_client::mobs::Part>,+ /// WindChargeModel.+ wind_charge: Option<horizon_client::mobs::Part>,+ /// ShulkerBulletModel.+ shulker_bullet: Option<horizon_client::mobs::Part>,+ /// SkullModel of the wither skull.+ wither_skull: Option<horizon_client::mobs::Part>,+ /// EvokerFangsModel.+ evoker_fangs: Option<Arc<horizon_client::mobs::Part>>,+ /// BannerModel's pole and flag (a raid captain's banner).+ banner: Option<(horizon_client::mobs::Part, horizon_client::mobs::Part)>,+}+impl EntityModels {+ fn load(document: Option<&horizon_client::mobs::EntityModelDocument>) -> Self {+ let model = |key| document.and_then(|document| document.model(key));+ Self {+ leash_knot: model("minecraft:leash_knot#main"),+ wind_charge: model("minecraft:wind_charge#main"),+ shulker_bullet: model("minecraft:shulker_bullet#main"),+ wither_skull: model("minecraft:wither_skull#main"),+ evoker_fangs: model("minecraft:evoker_fangs#main").map(Arc::new),+ banner: model("minecraft:standing_banner#main")+ .zip(model("minecraft:standing_banner#flag")),+ }+ }+}impl GameCpuResources {fn load(root: &std::path::Path) -> Result<Self> {let document = horizon_client::mobs::EntityModelDocument::load(root).ok();@@ -18547,6 +18583,7 @@ impl GameCpuResources {arrow_model: model("minecraft:arrow#main"),bee_stinger_model: model("minecraft:bee_stinger#main"),trident_model: model("minecraft:trident#main"),+ entity_models: EntityModels::load(document.as_ref()),creative_screen: Creative::load(root)?,})}@@ -20766,6 +20803,10 @@ mod startup_cpu_tests {std::fs::remove_dir_all(&root).unwrap();assert!(prepared.crystal_model.is_some());assert!(prepared.cushion_model.is_some());+ let models = &prepared.entity_models;+ assert!(models.leash_knot.is_some() && models.wind_charge.is_some());+ assert!(models.shulker_bullet.is_some() && models.wither_skull.is_some());+ assert!(models.evoker_fangs.is_some() && models.banner.is_some());assert!(prepared.dragon_model.is_some());assert!(prepared.arrow_model.is_some());assert!(prepared.trident_model.is_some());diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rsindex ca75a792a..fcd411ef1 100644--- a/crates/horizon-client/src/game/creatures.rs+++ b/crates/horizon-client/src/game/creatures.rs@@ -6475,14 +6475,7 @@ impl Game<'_> {// ShulkerBulletRenderer: the tumbling bullet model, then a larger// translucent copy of it (colour 0x26FFFFFF); always 15 block light.if matches!(a.kind, ProjectileKind::ShulkerBullet { .. }) {- static BULLET: std::sync::OnceLock<Option<horizon_client::mobs::Part>> =- std::sync::OnceLock::new();- let model = BULLET.get_or_init(|| {- horizon_client::mobs::load_model(- &self.options.resources,- "minecraft:shulker_bullet#main",- )- });+ let model = &self.entity_models.shulker_bullet;if let (Some(model), Some(r)) =(model, atlas.sprites.get("entity/shulker/spark").copied()){@@ -6534,14 +6527,7 @@ impl Game<'_> {}// WitherSkullRenderer: the skull model facing its flight.if let Some(dangerous) = super::wither::skull_kind(a) {- static SKULL: std::sync::OnceLock<Option<horizon_client::mobs::Part>> =- std::sync::OnceLock::new();- let model = SKULL.get_or_init(|| {- horizon_client::mobs::load_model(- &self.options.resources,- "minecraft:wither_skull#main",- )- });+ let model = &self.entity_models.wither_skull;let tex = if dangerous {"entity/wither/wither_invulnerable"} else {diff --git a/crates/horizon-client/src/game/fangs.rs b/crates/horizon-client/src/game/fangs.rsindex 6a5194051..b8e237004 100644--- a/crates/horizon-client/src/game/fangs.rs+++ b/crates/horizon-client/src/game/fangs.rs@@ -28,11 +28,7 @@ impl Game<'_> {pub(super) fn insert_fangs(&mut self, id: u32, at: [f64; 3], yaw: f32, delay: i32, owner: u32) {if self.fangs.model.is_none() {- self.fangs.model = horizon_client::mobs::load_model(- &self.options.resources,- "minecraft:evoker_fangs#main",- )- .map(Arc::new);+ self.fangs.model = self.entity_models.evoker_fangs.clone();}self.fangs.list.push(Fangs {id,diff --git a/crates/horizon-client/src/game/leads.rs b/crates/horizon-client/src/game/leads.rsindex ebb186f3f..b62e6b123 100644--- a/crates/horizon-client/src/game/leads.rs+++ b/crates/horizon-client/src/game/leads.rs@@ -598,12 +598,9 @@ impl Game<'_> {}}// The knots: a 6 by 8 by 6 pixel block on the fence post.- static KNOT: std::sync::OnceLock<Option<horizon_client::mobs::Part>> =- std::sync::OnceLock::new();- let model = KNOT.get_or_init(|| {- horizon_client::mobs::load_model(&self.options.resources, "minecraft:leash_knot#main")- });- let Some(model) = model else { return };+ let Some(model) = self.entity_models.leash_knot.as_ref() else {+ return;+ };let Some(r) = atlas.sprites.get("entity/lead_knot/lead_knot").copied() else {return;};diff --git a/crates/horizon-client/src/game/mob_blocks.rs b/crates/horizon-client/src/game/mob_blocks.rsindex 48561be53..d2432c91c 100644--- a/crates/horizon-client/src/game/mob_blocks.rs+++ b/crates/horizon-client/src/game/mob_blocks.rs@@ -173,18 +173,11 @@ impl Game<'_> {light: u32,out: &mut Vec<Vertex>,) {- use horizon_client::mobs::{Part, anim::Poses, load_model};- static MODELS: std::sync::OnceLock<Option<(Part, Part)>> = std::sync::OnceLock::new();+ use horizon_client::mobs::anim::Poses;if !horizon_client::mobs::raider::is_captain(mob) {return;}- let Some((pole, flag)) = MODELS.get_or_init(|| {- let root = &self.options.resources;- Some((- load_model(root, "minecraft:standing_banner#main")?,- load_model(root, "minecraft:standing_banner#flag")?,- ))- }) else {+ let Some((pole, flag)) = &self.entity_models.banner else {return;};let Some(head) =diff --git a/crates/horizon-client/src/game/wind.rs b/crates/horizon-client/src/game/wind.rsindex e2d6a882b..5101ca6f1 100644--- a/crates/horizon-client/src/game/wind.rs+++ b/crates/horizon-client/src/game/wind.rs@@ -694,12 +694,9 @@ impl Game<'_> {partial: f32,out: &mut Vec<horizon_client::mesher::Vertex>,) {- static MODEL: std::sync::OnceLock<Option<horizon_client::mobs::Part>> =- std::sync::OnceLock::new();- let model = MODEL.get_or_init(|| {- horizon_client::mobs::load_model(&self.options.resources, "minecraft:wind_charge#main")- });- let Some(model) = model else { return };+ let Some(model) = self.entity_models.wind_charge.as_ref() else {+ return;+ };let Some(r) = self.gui.atlas