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
OptiFine entity models: a shared .jem paints only the models it reshapes
some-du6ec3911b7608be
diff --git a/crates/horizon-client-render/src/block_entity_cem.rs b/crates/horizon-client-render/src/block_entity_cem.rsindex 84638b084..378fda131 100644--- a/crates/horizon-client-render/src/block_entity_cem.rs+++ b/crates/horizon-client-render/src/block_entity_cem.rs@@ -198,6 +198,9 @@ fn reshape_all(};let mut out = model.clone();let hits = apply(&mut out, jem, t.parts);+ // A file shared by several models (the conduit's, the pot's) paints only the models+ // it reshapes: vanilla geometry keeps its own texture's layout.+ let reshapes = hits.iter().any(|hit| *hit);let marks = used.entry(path).or_insert_with(|| vec![false; jem.parts.len()]);@@ -206,7 +209,7 @@ fn reshape_all(}models.insert(t.key, out);reshaped.insert(t.key);- if let Some(texture) = jem.texture.as_deref().and_then(atlas_name) {+ if reshapes && let Some(texture) = jem.texture.as_deref().and_then(atlas_name) {textures.insert(t.key, texture);}}@@ -328,6 +331,31 @@ pub(crate) mod tests {.collect();format!(r#"{{"models": [{}]}}"#, entries.join(", "))}+ /// A `.jem` replacing each of `parts` with a box of its own: the `i`th is `i + 1` pixels+ /// deep, so a part that took another entry's box shows.+ fn jem_sized(parts: &[&str]) -> String {+ let entries: Vec<_> = parts+ .iter()+ .enumerate()+ .map(|(i, p)| {+ let depth = i + 1;+ format!(+ r#"{{"part": "{p}", "boxes": [{{"coordinates": [0, 0, 0, 1, 1, {depth}], "textureOffset": [0, 0]}}]}}"#+ )+ })+ .collect();+ format!(r#"{{"models": [{}]}}"#, entries.join(", "))+ }+ /// How deep (z) the custom box under `model`'s part `name` is.+ fn depth(model: &ModelPart, name: &str) -> f32 {+ let part = model.child(name).unwrap();+ let zs = part+ .children+ .iter()+ .flat_map(|(_, c)| c.polygons.iter().flatten().map(|v| v[2]));+ let (lo, hi) = zs.fold((f32::MAX, f32::MIN), |(lo, hi), z| (lo.min(z), hi.max(z)));+ hi - lo+ }/// Whether `model`'s part `name` was replaced by one custom box: its own face gone, and one/// child of a box's six faces.fn replaced(model: &ModelPart, name: &str) -> bool {@@ -440,11 +468,12 @@ pub(crate) mod tests {.or_default().extend(["bottom", "lid", "lock"]);}+ let files_by_name = files.clone();let files: Vec<_> = files.iter().map(|(file, parts)| {let parts: Vec<_> = parts.iter().copied().collect();- (format!("optifine/cem/{file}.jem"), jem(&parts))+ (format!("optifine/cem/{file}.jem"), jem_sized(&parts))}).collect();let files: Vec<_> = files.iter().map(|(p, t)| (p.as_str(), t.clone())).collect();@@ -464,6 +493,13 @@ pub(crate) mod tests {replaced(&models[key], vanilla),"{file}.jem {part}: {key} {vanilla}");+ // The box is this entry's own: swapped names (left and right, body and base) show.+ let own = files_by_name[file].iter().position(|p| *p == part).unwrap() + 1;+ assert_eq!(+ depth(&models[key], vanilla),+ own as f32,+ "{file}.jem {part}: {key} {vanilla}"+ );}assert_eq!(unused, Vec::new());}@@ -562,4 +598,32 @@ pub(crate) mod tests {assert!(replaced(&models["book"], "left_lid"));assert!(replaced(&models["lectern_book"], "left_lid"));}++ #[test]+ fn a_shared_file_paints_only_the_models_it_reshapes() {+ // The conduit's file reshapes its eye alone: the shell, cage and wind keep their+ // vanilla geometry and so their own textures.+ let file = format!(+ r#"{{"texture": "textures/entity/conduit/custom.png", "models": [{{"part": "eye", {BOX}}}]}}"#+ );+ let root = pack("conduit", &[("optifine/cem/conduit.jem", file)]);+ let vanilla: HashMap<_, _> = [+ "conduit_shell",+ "conduit_cage",+ "conduit_wind",+ "conduit_eye",+ ]+ .map(|key| {+ let part = if key == "conduit_eye" { "eye" } else { "shell" };+ (key, plane(vec![(part, plane(vec![]))]))+ })+ .into();+ let result = reshape(&root, &vanilla);+ fs::remove_dir_all(&root).unwrap();+ let (models, textures) = result.unwrap();+ assert!(replaced(&models["conduit_eye"], "eye"));+ let painted: BTreeSet<_> = textures.keys().copied().collect();+ assert_eq!(painted, BTreeSet::from(["conduit_eye"]));+ assert_eq!(textures["conduit_eye"], "entity/conduit/custom");+ }}diff --git a/docs/resource-packs.md b/docs/resource-packs.mdindex ab577e96f..ff851a0a7 100644--- a/docs/resource-packs.md+++ b/docs/resource-packs.md@@ -38,7 +38,7 @@ harness named checks that loader against vanilla).| Block states: variants, multipart, weights, rotations, uvlock | `blockstates/` | works | `test_blockstate_model_parity`, `test_model_choice_parity`, `test_blockstate_transform_parity` || Block models: parents, elements, rotations, faces, cullface, tint, shade, light emission, ambient occlusion | `models/block/` | works | `test_model_resolution_parity`, `test_model_baking_parity`, `test_section_mesh_parity` || Item definitions and item models (all model types, display transforms, tints) | `items/`, `models/item/` | works | `test_item_model_parity` |-| Custom entity models (OptiFine/EMF): a `.jem` reshapes a mob's model layer, with its animations and texture, or a block entity's model (chests, shulker boxes, banners, heads, bells, books, conduits, decorated pots) with its texture but no animations yet; Entity Model Features' files win over OptiFine's | `optifine/cem/`, `emf/cem/` | partly | `mobs::cem`, `mobs::cem_anim`, `block_entity_cem` and `block_entity_render` unit tests; trapped and ender chests read only their own files and copper chests keep vanilla's model; no sign, hanging sign or bed models, no per-bone textures, no random models, no textures under `optifine/` (vanilla's own entity models are code in 26.3, which `test_entity_model_parity` checks) |+| Custom entity models (OptiFine/EMF): a `.jem` reshapes a mob's model layer, with its animations and texture, or a block entity's model (chests, shulker boxes, banners, heads, bells, books, conduits, decorated pots) with its texture but no animations yet; Entity Model Features' files win over OptiFine's | `optifine/cem/`, `emf/cem/` | partly | `mobs::cem`, `mobs::cem_anim`, `block_entity_cem` and `block_entity_render` unit tests, `horizon-optifine` `cem::files` (which file wins); trapped and ender chests read only their own files and copper chests keep vanilla's model; no sign, hanging sign or bed models, no per-bone textures, no random models, no textures under `optifine/` (vanilla's own entity models are code in 26.3, which `test_entity_model_parity` checks) || Random entity textures (OptiFine/ETF): numbered variants and their rules (biome, height, name, profession, colour, baby, health, moon, time, weather, size, blocks), chosen per entity from its UUID and rechecked once a second | `optifine/random/`, `optifine/mob/`, `mcpatcher/mob/`, `etf/random/`, `textures/entity/` with a `.properties` | partly | `horizon-optifine` `random` and `random_textures` tests, `mobs::random_textures` tests; no `nbt.*` or ETF's extra conditions (teams, items...), no block entities || Emissive textures (OptiFine/ETF): `<texture>_e.png` (or the pack's `suffix.emissive`) drawn full bright over mobs, their layers and armour, armour stands, the elytra, the dragon, thrown tridents, block entities and placed blocks | `<texture>_e.png` beside its texture (also random variants' and blink frames'); the suffix from `optifine/emissive.properties`, `etf/emissive.properties` or `textures/emissive.properties` | partly | `horizon-optifine` `emissive` tests, `mobs::render::emissive_tests`, `block_entity_render` and `native_emissive` tests; at most 96 block overlays (native mods keep 32 more), cutout; none on translucent faces, nor on blocks whose texture is pixel-identical to another's (they share a layer); not over items, armour trims, other projectiles, minecarts or end crystals, nor connected-texture tiles || Blinking textures (ETF): `<texture>_blink.png` and `_blink2.png`, `blinkLength`/`blinkFrequency` | `textures/entity/`, random variants' folders | works | `horizon-optifine` `blink` tests, `mobs::render` blink test; sleeping villagers keep their eyes shut |