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 CIT: glints only on stacks with foil; enchantment rules need a texture; a graceful cycle end
some-du6edccfdc7b5165
diff --git a/crates/horizon-client-render/src/cit.rs b/crates/horizon-client-render/src/cit.rsindex 3d435f33d..6f556e23e 100644--- a/crates/horizon-client-render/src/cit.rs+++ b/crates/horizon-client-render/src/cit.rs@@ -169,11 +169,19 @@ impl CitRules {/// The glint layers this stack draws in `hand` (`Hand::Main` in a GUI) and whether/// vanilla's still does (`StackGlint`), worked out once per stack and hand; `None` when the- /// pack changes no glint.- pub fn glint(&self, stack: &ItemStack, hand: Hand, max_damage: u32) -> Option<Arc<StackGlint>> {+ /// pack changes no glint. `foil` is whether the stack draws a glint at all+ /// (`ItemStack::has_foil`): one that doesn't gets no layers.+ pub fn glint(+ &self,+ stack: &ItemStack,+ hand: Hand,+ max_damage: u32,+ foil: bool,+ ) -> Option<Arc<StackGlint>> {let no_rules =self.any_item.is_empty() && self.by_item[Kind::Enchantment as usize].is_empty();- if no_rules && self.global.use_glint {+ // Before the cache, which `foil` is not part of.+ if !foil || (no_rules && self.global.use_glint) {return None;}let comps = encode_components(stack);@@ -703,6 +711,21 @@ mod tests {assert_eq!(item(&cit, enchanted("diamond_sword", &sharp)), None);}+ /// `CitRules::glint` in the main hand, with the stack's own `has_foil` as callers pass it.+ fn glint(cit: &CitRules, stack: &ItemStack, item_glint: bool) -> Option<Arc<StackGlint>> {+ cit.glint(stack, Hand::Main, 0, stack.has_foil(item_glint))+ }++ /// `stack` with its `enchantment_glint_override` set to `on`.+ fn overridden(mut stack: ItemStack, on: bool) -> ItemStack {+ let flag = (+ "minecraft:enchantment_glint_override".to_owned(),+ Tag::Byte(on.into()),+ );+ stack.data_mut().other.push(flag);+ stack+ }+#[test]fn a_stack_glint_reads_the_book_and_the_pack_file() {let mut cit = rules(&[@@ -718,22 +741,49 @@ mod tests {(Arc::from("minecraft:sharpness"), 3),(Arc::from("minecraft:mending"), 1),];- let glint = cit.glint(&book, Hand::Main, 0).unwrap();- let weights: Vec<_> = glint.layers.iter().map(|l| l.weight).collect();+ let book = glint(&cit, &book, true).unwrap();+ let weights: Vec<_> = book.layers.iter().map(|l| l.weight).collect();assert_eq!(weights, [0.75, 0.25]);- assert!(glint.vanilla);- let plain = cit- .glint(&enchanted("stick", &[("sharpness", 1)]), Hand::Main, 0)- .unwrap();+ assert!(book.vanilla);+ let plain = glint(&cit, &enchanted("stick", &[("sharpness", 1)]), false).unwrap();assert_eq!(plain.layers.len(), 1);assert!(!plain.vanilla);// No enchantment rules: nothing changes, unless the pack turns vanilla's glint off.let mut bare = rules(&[("stick", "items=stick")]);- assert!(bare.glint(&new("stick"), Hand::Main, 0).is_none());+ assert!(glint(&bare, &overridden(new("stick"), true), false).is_none());bare.global.use_glint = false;- assert!(!bare.glint(&new("stick"), Hand::Main, 0).unwrap().vanilla);+ assert!(+ !glint(&bare, &overridden(new("stick"), true), false)+ .unwrap()+ .vanilla+ );cit.global.use_glint = false;- assert!(cit.glint(&new("stick"), Hand::Main, 0).unwrap().is_empty());+ assert!(+ glint(&cit, &overridden(new("stick"), true), false)+ .unwrap()+ .is_empty()+ );+ }++ #[test]+ fn only_a_stack_with_a_glint_gets_layers() {+ let cit = rules(&[("any", "type=enchantment")]);+ assert!(glint(&cit, &new("stick"), false).is_none());+ // The override turns an enchanted stack's glint off, and an unenchanted one's on.+ let off = overridden(enchanted("stick", &[("sharpness", 1)]), false);+ assert!(glint(&cit, &off, false).is_none());+ let on = glint(&cit, &overridden(new("stick"), true), false).unwrap();+ let weights: Vec<_> = on.layers.iter().map(|l| l.weight).collect();+ assert_eq!(+ weights,+ [1.0],+ "nothing to share: the rule at full strength"+ );+ // The same stack, asked again without its glint, is not answered from the cache.+ assert!(+ cit.glint(&overridden(new("stick"), true), Hand::Main, 0, false)+ .is_none()+ );}#[test]@@ -744,7 +794,7 @@ mod tests {]);let sword = enchanted("diamond_sword", &[("sharpness", 1)]);let layers = |hand| -> Vec<&str> {- let glint = cit.glint(&sword, hand, 0).unwrap();+ let glint = cit.glint(&sword, hand, 0, true).unwrap();glint.layers.iter()diff --git a/crates/horizon-client-render/src/cit_glint.rs b/crates/horizon-client-render/src/cit_glint.rsindex f2d1a7c6a..ad47afc01 100644--- a/crates/horizon-client-render/src/cit_glint.rs+++ b/crates/horizon-client-render/src/cit_glint.rs@@ -65,7 +65,8 @@ impl StackGlint {layers.sort_by_key(|&i| rules[i].glint.layer);let cycle = global.method == Method::Cycle;// OptiFine's doc: `cap` is for `average` and `layered`, and keeps the topmost layers.- // (CIT Resewn keeps the bottom ones, and caps cycles too.)+ // `none`, which OptiFine lacks, is capped too, as CIT Resewn caps every method (it keeps+ // the bottom layers, though, and caps cycles as well).if let Some(cap) = global.cap.filter(|_| !cycle) {let cap = usize::try_from(cap).unwrap_or(usize::MAX);layers = layers.split_off(layers.len().saturating_sub(cap));@@ -157,7 +158,8 @@ fn cycle_intensity(layers: &[GlintLayer], fade: f32, index: usize, seconds: f64)return if i == index { 1.0 } else { 0.0 };}t -= duration;- // The last fade takes whatever rounding left of the period.+ // Defensive: the last fade also takes anything rounding might leave of the period+ // (none seen), ending fully on the first layer.if t < fade || i + 1 == n {let into = if fade > 0.0 {(t / fade).min(1.0) as f32@@ -174,7 +176,8 @@ fn cycle_intensity(layers: &[GlintLayer], fade: f32, index: usize, seconds: f64)}t -= fade;}- unreachable!("the last layer's fade ends the period")+ // Not reached, as the last layer returns above; no layer rather than a panic.+ 0.0}#[cfg(test)]@@ -234,10 +237,6 @@ mod tests {assert_eq!(weights("method=layered"), [1.0, 1.0 / 3.0, 1.0, 0.0]);assert_eq!(weights("method=cycle"), [1.0; 4]);assert_eq!(weights("method=none"), [1.0; 4]);- // An unenchanted stack: nothing to share.- let g = StackGlint::new(&rules, &[0, 2], &[] as &[(&str, u32)], &Global::default());- assert_eq!(g.layers[0].weight, 0.0);- assert_eq!(g.layers[1].weight, 1.0);}#[test]@@ -263,6 +262,8 @@ mod tests {assert_eq!(rules_of(&g), [1, 2]);let g = StackGlint::new(&rules, &[0, 1, 2], &SWORD, &global("cap=0"));assert!(g.is_empty());+ let g = StackGlint::new(&rules, &[0, 1, 2], &SWORD, &global("cap=1\nmethod=none"));+ assert_eq!(rules_of(&g), [2]);// Cycles show every layer in turn.let g = StackGlint::new(&rules, &[0, 1, 2], &SWORD, &global("cap=1\nmethod=cycle"));assert_eq!(rules_of(&g), [0, 1, 2]);@@ -331,7 +332,9 @@ mod tests {&SWORD,&global("method=cycle\nfade=0.3"),);- // Just under a period, where rounding could leave no layer.+ // Every millisecond of the first two seconds, and just under a period, the last fade's+ // end. (Rounding has not been seen to leave time past it; the last fade's clamp is+ // defensive.)let period: f64 = [0.1f32, 0.7, 0.2].map(|d| f64::from(d) + f64::from(0.3f32)).iter()diff --git a/crates/horizon-optifine/src/cit.rs b/crates/horizon-optifine/src/cit.rsindex e91b0b251..89718087f 100644--- a/crates/horizon-optifine/src/cit.rs+++ b/crates/horizon-optifine/src/cit.rs@@ -581,6 +581,11 @@ impl Rule {if texture.is_none() && model.is_none() && textures.is_empty() && models.is_empty() {return None;}+ // A glint is a texture: CIT Resewn drops an enchantment rule without one ("No texture+ // specified"), whatever models it names.+ if kind == Kind::Enchantment && texture.is_none() {+ return None;+ }// Only an enchantment rule reads the glint keys: an item rule's `blend=` is no reason to// drop it.let glint = if kind == Kind::Enchantment {@@ -1017,6 +1022,25 @@ mod tests {assert_eq!(elytra.items, ["minecraft:elytra"]);}+ #[test]+ fn an_enchantment_rule_needs_a_texture() {+ let dir = "assets/minecraft/optifine/cit/glint";+ let files = [+ format!("{dir}/shine.json"),+ format!("{dir}/shine.png"),+ format!("{dir}/other.png"),+ ];+ let refs: Vec<&str> = files.iter().map(String::as_str).collect();+ let path = format!("{dir}/shine.properties");+ // The model is there: an item rule takes it.+ assert!(rule(&path, "items=stick\nmodel=shine", &refs).is_some());+ assert!(rule(&path, "type=enchantment\nmodel=shine", &refs).is_none());+ assert!(rule(&path, "type=enchantment\ntexture.a=other", &refs).is_none());+ // The texture beside the file still counts.+ let beside = rule(&path, "type=enchantment", &refs).unwrap();+ assert_eq!(beside.texture.as_deref(), Some(&*files[1]));+ }+#[test]fn legacy_nbt_paths_land_on_components() {let source = |key: &str| {