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 emissive and ETF blinking: the gaps the merged PRs' last reviews found
some-du6e69be592cb222
diff --git a/crates/horizon-client-render/src/hud.rs b/crates/horizon-client-render/src/hud.rsindex 0e9680767..6750718e8 100644--- a/crates/horizon-client-render/src/hud.rs+++ b/crates/horizon-client-render/src/hud.rs@@ -751,16 +751,18 @@ impl HudAtlas {} else {Default::default()};- let emissive = std::sync::Arc::new(if folders.contains(&"entity") {- horizon_optifine::emissive::Emissive::scan(root, &random_textures)- } else {- Default::default()- });let blinks = if folders.contains(&"entity") {horizon_optifine::blink::Blinks::scan(root, &random_textures)} else {Default::default()};+ let emissive = std::sync::Arc::new(if folders.contains(&"entity") {+ let mut e = horizon_optifine::emissive::Emissive::scan(root, &random_textures);+ e.pair_beside(root, blinks.files());+ e+ } else {+ Default::default()+ });let mut named: HashMap<PathBuf, String> = HashMap::new();let extra = random_textures.files()@@ -773,7 +775,12 @@ impl HudAtlas {// A pack's variants can't grow the shared atlas past what a GPU takes: every variant// (those beside their texture too) counts, in name order, and those past the budget// stay out (their mobs wear the texture itself), not the whole pack.- let overlays: HashSet<PathBuf> = emissive.files().map(|(f, _)| root.join(f)).collect();+ // Overlays and blink frames only after every variant.+ let overlays: HashSet<PathBuf> = emissive+ .files()+ .chain(blinks.files())+ .map(|(f, _)| root.join(f))+ .collect();let kept = budgeted(named.keys(), &overlays, RANDOM_TEXELS);if kept.len() < named.len() {log::warn!(@@ -781,7 +788,20 @@ impl HudAtlas {named.len() - kept.len());}- files.retain(|p| !named.contains_key(p) || kept.contains(p));+ // A dropped variant beside its texture takes its walked overlay with it: nothing+ // would draw it.+ let png = format!("{}.png", emissive.suffix);+ let orphans: HashSet<PathBuf> = named+ .keys()+ .filter(|p| !kept.contains(*p))+ .filter_map(|p| {+ Some(PathBuf::from(format!(+ "{}{png}",+ p.to_str()?.strip_suffix(".png")?+ )))+ })+ .collect();+ files.retain(|p| (!named.contains_key(p) || kept.contains(p)) && !orphans.contains(p));// Those beside their texture are walked already.let walked: HashSet<&PathBuf> = files.iter().collect();let mut extra: Vec<PathBuf> = keptdiff --git a/crates/horizon-client/src/game/armor_stands.rs b/crates/horizon-client/src/game/armor_stands.rsindex 0dbf6e50c..36ba2c640 100644--- a/crates/horizon-client/src/game/armor_stands.rs+++ b/crates/horizon-client/src/game/armor_stands.rs@@ -886,12 +886,17 @@ impl Game<'_> {let assets = &self.armor_stand_assets;let sprites = &self.gui.atlas.sprites;let uv_of = |name: &str| sprites.get(name).map(|r| [r.u0, r.v0, r.u1, r.v1]);- let emissive = self- .res- .mob_data()- .emissive- .read()- .unwrap_or_else(std::sync::PoisonError::into_inner);+ // A texture's OptiFine emissive overlay. The lock is read per lookup and let go:+ // `wings_geometry` below reads it too.+ let glow_of = |texture: &str| {+ let emissive = self+ .res+ .mob_data()+ .emissive+ .read()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ emissive.overlay(texture).and_then(|e| uv_of(e))+ };let Some(wood) = uv_of("entity/armorstand/armorstand") else {return;};@@ -931,6 +936,19 @@ impl Game<'_> {0,out,);+ if let Some(glow) = glow_of("entity/armorstand/armorstand") {+ let full = horizon_client::mobs::render::FULL_BRIGHT;+ horizon_client::mobs::render::draw(+ model,+ base,+ &poses,+ glow,+ 0xFFFF_FFFF,+ full,+ 0,+ out,+ );+ }}self.armor_stand_items(a, model, base, &posed, packed, out);// HumanoidArmorLayer: head, chest, legs, feet.@@ -997,7 +1015,7 @@ impl Game<'_> {out,);// The layer's OptiFine emissive overlay, full bright without the glint.- if let Some(glow) = emissive.overlay(texture).and_then(|e| uv_of(e)) {+ if let Some(glow) = glow_of(texture) {horizon_client::mobs::render::draw(part,base,diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rsindex f785e1a24..7440eebc1 100644--- a/crates/horizon-client/src/game/creatures.rs+++ b/crates/horizon-client/src/game/creatures.rs@@ -6444,6 +6444,28 @@ impl Game<'_> {0,out,);+ // The trident texture's OptiFine emissive overlay, full bright.+ let glow = self+ .res+ .mob_data()+ .emissive+ .read()+ .unwrap_or_else(std::sync::PoisonError::into_inner)+ .overlay("entity/trident/trident")+ .and_then(|e| atlas.sprites.get(e))+ .copied();+ if let Some(g) = glow {+ horizon_client::mobs::render::draw(+ model,+ m,+ &poses,+ [g.u0, g.v0, g.u1, g.v1],+ 0xFFFF_FFFF,+ horizon_client::mobs::render::FULL_BRIGHT,+ 0,+ out,+ );+ }continue;}// WindChargeRenderer.diff --git a/crates/horizon-client/src/mobs/data.rs b/crates/horizon-client/src/mobs/data.rsindex 35dc29ab6..969fc96af 100644--- a/crates/horizon-client/src/mobs/data.rs+++ b/crates/horizon-client/src/mobs/data.rs@@ -93,10 +93,11 @@ impl MobData {.unwrap_or_default();data.villager_hats = std::sync::RwLock::new(super::villager_hats::VillagerHats::load(root));let random = horizon_optifine::random_textures::RandomTextures::scan(root);- data.emissive = std::sync::RwLock::new(std::sync::Arc::new(- horizon_optifine::emissive::Emissive::scan(root, &random),- ));- data.blinks = std::sync::RwLock::new(horizon_optifine::blink::Blinks::scan(root, &random));+ let blinks = horizon_optifine::blink::Blinks::scan(root, &random);+ let mut emissive = horizon_optifine::emissive::Emissive::scan(root, &random);+ emissive.pair_beside(root, blinks.files());+ data.emissive = std::sync::RwLock::new(std::sync::Arc::new(emissive));+ data.blinks = std::sync::RwLock::new(blinks);data.random_textures = std::sync::RwLock::new(random);data}diff --git a/crates/horizon-client/src/mobs/render.rs b/crates/horizon-client/src/mobs/render.rsindex 5f29dcda2..33b8e6e96 100644--- a/crates/horizon-client/src/mobs/render.rs+++ b/crates/horizon-client/src/mobs/render.rs@@ -1792,7 +1792,7 @@ fn render_visible(if emissive.is_empty() {return None;}- atlas(emissive.overlay(drawn)?)+ atlas(emissive.overlay_of(drawn)?)};let mut poses = Poses::new(&model);anim::setup(m, &s, &mut poses, &data.animations);diff --git a/crates/horizon-optifine/src/blink.rs b/crates/horizon-optifine/src/blink.rsindex 31391182a..681928d04 100644--- a/crates/horizon-optifine/src/blink.rs+++ b/crates/horizon-optifine/src/blink.rs@@ -105,7 +105,8 @@ impl Blink {.and_then(|v| v.parse().ok()).unwrap_or(default)};- let length: u32 = number("blinkLength", LENGTH).max(1);+ // At least a tick, and short of `u32::MAX` so the frequency can exceed it.+ let length: u32 = number("blinkLength", LENGTH).clamp(1, u32::MAX - 1);let half = format!("{stem}_blink2");Self {shut: name(&format!("{stem}_blink")),@@ -221,4 +222,23 @@ mod tests {);let _ = fs::remove_dir_all(root);}++ #[test]+ fn a_huge_blink_length_still_opens_the_eyes() {+ let (root, b) = pack(+ "huge",+ &[+ (&format!("{ENTITY}/pig/pig.png"), ""),+ (&format!("{ENTITY}/pig/pig_blink.png"), ""),+ (+ &format!("{ENTITY}/pig/pig_blink.properties"),+ "blinkLength=4294967295",+ ),+ ],+ );+ let pig = b.get("entity/pig/pig").unwrap();+ assert_eq!((pig.length, pig.frequency), (u32::MAX - 1, u32::MAX));+ assert_eq!(pig.frame(u32::MAX - 1, 0), None, "the one open tick");+ let _ = fs::remove_dir_all(root);+ }}diff --git a/crates/horizon-optifine/src/emissive.rs b/crates/horizon-optifine/src/emissive.rsindex ea7e659bc..b1c6ba0e2 100644--- a/crates/horizon-optifine/src/emissive.rs+++ b/crates/horizon-optifine/src/emissive.rs@@ -8,7 +8,8 @@//! `zombie3`, never over `zombie`.//!//! This pairs entity textures, those under `textures/entity/` (mobs' and block entities'), by-//! the entity atlas's names ([`crate::random_textures`]); the game draws mobs' overlays.+//! the entity atlas's names ([`crate::random_textures`]); the game draws them over mobs and+//! block entities.//! Blocks and items have their own atlas.//!//! Written from OptiFine's `emissive.properties` and ETF's `EMISSIVE_GUIDE.md` and@@ -76,21 +77,43 @@ impl Emissive {}}}- for (file, name) in random.files() {+ out.pair_beside(root, random.files());+ out+ }++ /// Pairs each of `files` (file from the root, atlas name: random variants, blink frames)+ /// with an overlay beside it, and lists those outside `textures/` for the atlas.+ pub fn pair_beside<'a>(+ &mut self,+ root: &Path,+ files: impl Iterator<Item = (&'a str, &'a str)>,+ ) {+ let png = format!("{}.png", self.suffix);+ for (file, name) in files {let Some(stem) = file.strip_suffix(".png") else {continue;};let overlay = format!("{stem}{png}");if root.join(&overlay).is_file() {- let overlay_name = format!("{name}{}", out.suffix);- out.overlays.insert(name.to_owned(), overlay_name.clone());+ let overlay_name = format!("{name}{}", self.suffix);+ self.overlays.insert(name.to_owned(), overlay_name.clone());// Those under `textures/` are the atlas's already.if !overlay.contains("/textures/") {- out.files.push((overlay, overlay_name));+ self.files.push((overlay, overlay_name));}}}- out+ }++ /// The overlay drawn over `drawn`: its own, or for a blink frame without one, the overlay of+ /// the texture it blinks (so the glow doesn't go out with every blink).+ pub fn overlay_of(&self, drawn: &str) -> Option<&str> {+ self.overlay(drawn).or_else(|| {+ let texture = drawn+ .strip_suffix("_blink2")+ .or_else(|| drawn.strip_suffix("_blink"))?;+ self.overlay(texture)+ })}pub fn is_empty(&self) -> bool {@@ -248,6 +271,39 @@ mod tests {}}+ #[test]+ fn blink_frames_glow_with_their_own_overlay_or_their_textures() {+ let (root, mut e) = pack(+ "blink",+ &[+ &format!("{RANDOM}/zombie/zombie3.png"),+ &format!("{RANDOM}/zombie/zombie3_e.png"),+ &format!("{RANDOM}/zombie/zombie3_blink.png"),+ &format!("{RANDOM}/zombie/zombie3_blink_e.png"),+ &format!("{ENTITY}/pig/pig.png"),+ &format!("{ENTITY}/pig/pig_e.png"),+ &format!("{ENTITY}/pig/pig_blink.png"),+ ],+ None,+ );+ let blinks = crate::blink::Blinks::scan(&root, &RandomTextures::scan(&root));+ e.pair_beside(&root, blinks.files());+ let frame = "minecraft:optifine/random/entity/zombie/zombie3_blink";+ assert_eq!(e.overlay_of(frame), Some(format!("{frame}_e").as_str()));+ assert!(e.files().any(|(_, name)| name == format!("{frame}_e")));+ // No pig_blink_e: the shut eye keeps the pig's glow.+ assert_eq!(+ e.overlay_of("entity/pig/pig_blink"),+ Some("entity/pig/pig_e")+ );+ assert_eq!(+ e.overlay_of("entity/pig/pig_blink2"),+ Some("entity/pig/pig_e")+ );+ assert_eq!(e.overlay_of("entity/cow/cow_blink"), None);+ let _ = fs::remove_dir_all(root);+ }+#[test]fn no_overlays_no_entries() {let (root, e) = pack("none", &[&format!("{ENTITY}/zombie/zombie.png")], None);diff --git a/docs/resource-packs.md b/docs/resource-packs.mdindex 1df4467de..f7decac33 100644--- a/docs/resource-packs.md+++ b/docs/resource-packs.md@@ -39,6 +39,9 @@ harness named checks that loader against vanilla).| 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; Entity Model Features' files win over OptiFine's | `optifine/cem/`, `emf/cem/` | partly | `mobs::cem` and `mobs::cem_anim` unit tests; 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 and block entities | `optifine/emissive.properties` | partly | `horizon-optifine` `emissive` tests, `mobs::render::emissive_tests`, `block_entity_render` tests; not over blocks, items, other projectiles, minecarts or end crystals |+| 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 || Textures, any resolution (16x to 512x) | `textures/` | works | atlases stitched from the overlay; Faithful 32x, Default HD 128x and FPBR measured in [reuse-pack-overlays.md](reuse-pack-overlays.md) || Texture animation: frames, frame time, frame size | `*.png.mcmeta` `animation` | works | `test_sprite_animation_parity` || Texture animation: `interpolate` | `*.png.mcmeta` `animation` | **no** | frames step instead of blending (vanilla's own prismarine, magma, stems, lit furnaces and campfires, command blocks, sculk too): fix in progress |