Skip to content

Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.

OptiFine emissive textures: a blink frame glows with its own overlay only

some-du6edfc2b8b7c05e
diff --git a/crates/horizon-client/src/mobs/render.rs b/crates/horizon-client/src/mobs/render.rs
index 33b8e6e96..52d2b0fc5 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_of(drawn)?)
+ atlas(emissive.overlay(drawn)?)
};
let mut poses = Poses::new(&model);
anim::setup(m, &s, &mut poses, &data.animations);
@@ -3136,8 +3136,9 @@ mod emissive_tests {
std::fs::write(path, text).unwrap();
}
let random = RandomTextures::scan(&root);
- let emissive = Emissive::scan(&root, &random);
let blinks = Blinks::scan(&root, &random);
+ let mut emissive = Emissive::scan(&root, &random);
+ emissive.pair_beside(&root, blinks.files());
let _ = std::fs::remove_dir_all(&root);
MobData {
states: Vec::new(),
@@ -3220,6 +3221,43 @@ mod emissive_tests {
assert!(shut(&uvs(89 + 150)));
}
+ #[test]
+ fn a_blink_shows_its_own_glow_or_none() {
+ let atlas = |name: &str| {
+ let u = match name {
+ "entity/silverfish" => 0.0,
+ "entity/silverfish_e" => 0.25,
+ "entity/silverfish_blink" => 0.5,
+ "entity/silverfish_blink_e" => 0.75,
+ _ => return None,
+ };
+ Some([u, 0.0, u + 0.25, 1.0])
+ };
+ let base = [
+ "assets/minecraft/textures/entity/silverfish.png",
+ "assets/minecraft/textures/entity/silverfish_e.png",
+ "assets/minecraft/textures/entity/silverfish_blink.png",
+ ];
+ let at = |data: &MobData, age: u32| {
+ let mut m = silverfish();
+ m.age = age;
+ drawn(&m, data, &atlas)
+ };
+ // Age 89 is shut (see above), 0 open.
+ let plain = data(&base);
+ let open = at(&plain, 0);
+ assert_eq!(open.len(), 8);
+ assert!(inside(&open[4..], 0.25), "the texture's glow");
+ let shut = at(&plain, 89);
+ assert_eq!(shut.len(), 4, "no glowing open eyes over the shut ones");
+ assert!(inside(&shut, 0.5));
+ let mut own = base.to_vec();
+ own.push("assets/minecraft/textures/entity/silverfish_blink_e.png");
+ let shut = at(&data(&own), 89);
+ assert_eq!(shut.len(), 8);
+ assert!(inside(&shut[4..], 0.75), "the frame's own glow");
+ }
+
/// Draws `m` and returns each vertex's (uv, light).
fn drawn(m: &Mob, data: &MobData, atlas: Atlas) -> Vec<([f32; 2], u32)> {
let mut out = Vec::new();
diff --git a/crates/horizon-optifine/src/emissive.rs b/crates/horizon-optifine/src/emissive.rs
index b1c6ba0e2..77689f18d 100644
--- a/crates/horizon-optifine/src/emissive.rs
+++ b/crates/horizon-optifine/src/emissive.rs
@@ -8,9 +8,10 @@
//! `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 them over mobs and
-//! block entities.
-//! Blocks and items have their own atlas.
+//! the entity atlas's names ([`crate::random_textures`]), and through [`Emissive::pair_beside`]
+//! random variants and their blink frames wherever they are. A blink frame glows with its own
+//! overlay only: the texture's would paint its open eyes over the shut ones. Blocks and items
+//! have their own atlas.
//!
//! Written from OptiFine's `emissive.properties` and ETF's `EMISSIVE_GUIDE.md` and
//! `emissive.properties`; no mod's source was read.
@@ -105,17 +106,6 @@ impl Emissive {
}
}
- /// 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 {
self.overlays.is_empty()
}
@@ -272,7 +262,7 @@ mod tests {
}
#[test]
- fn blink_frames_glow_with_their_own_overlay_or_their_textures() {
+ fn blink_frames_glow_with_their_own_overlay_only() {
let (root, mut e) = pack(
"blink",
&[
@@ -289,18 +279,10 @@ mod tests {
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_eq!(e.overlay(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);
+ // No pig_blink_e: the shut eye doesn't take the pig's glow (its open eyes, mostly).
+ assert_eq!(e.overlay("entity/pig/pig_blink"), None);
let _ = fs::remove_dir_all(root);
}