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: the pack's overlays leave native mods their 32

some-du6ecba1912a1fa9
diff --git a/crates/horizon-client-render/src/assets.rs b/crates/horizon-client-render/src/assets.rs
index 2b5590c79..7b0ae711a 100644
--- a/crates/horizon-client-render/src/assets.rs
+++ b/crates/horizon-client-render/src/assets.rs
@@ -247,7 +247,6 @@ impl RenderAssets {
let mut emissive = Vec::new();
let connected = if draws {
crate::native_emissive::load(root, &mut sprites);
- emissive = crate::native_emissive::load_optifine(root, &mut sprites);
// A side's sprite, for rules that connect by tile: the first quad facing it.
let catalog = &models.catalog;
let mut found = Vec::new();
@@ -274,6 +273,11 @@ impl RenderAssets {
} else {
Default::default()
};
+ // After the connected tiles: a tile identical to a block shares its layer, and the
+ // overlays skip shared layers.
+ if draws {
+ emissive = crate::native_emissive::load_optifine(root, &mut sprites);
+ }
sprites.save_disk_cache();
if draws {
sprites.finish();
diff --git a/crates/horizon-client-render/src/native_emissive.rs b/crates/horizon-client-render/src/native_emissive.rs
index 23ac4ba7e..959fe0397 100644
--- a/crates/horizon-client-render/src/native_emissive.rs
+++ b/crates/horizon-client-render/src/native_emissive.rs
@@ -31,7 +31,8 @@ pub fn load(root: &Path, sprites: &mut Sprites) {
/// OptiFine's emissive overlays of the block sprites already loaded (what the terrain draws;
/// items draw from the HUD atlas): for each
/// `<ns>:block/<name>` whose `<name><suffix>.png` sits beside it, the overlay is loaded too and
-/// paired with it, first by name, at most [`MAX`]. A pack without such files adds nothing.
+/// paired with it, first by name, at most [`MAX`] - [`NATIVE`] (native mods keep their share of
+/// the table). A pack without such files adds nothing.
pub fn load_optifine(root: &Path, sprites: &mut Sprites) -> Vec<(String, String)> {
let suffix = horizon_optifine::emissive::suffix(root);
// Blocks with identical pixels share a layer (and the shader pairs by layer): a shared
@@ -58,7 +59,7 @@ pub fn load_optifine(root: &Path, sprites: &mut Sprites) -> Vec<(String, String)
if !std::fs::metadata(&file).is_ok_and(|m| m.is_file()) {
continue;
}
- if pairs.len() == MAX {
+ if pairs.len() == MAX - NATIVE {
log::warn!(
"Horizon: more than {MAX} emissive block overlays: {overlay} and later skipped"
);
@@ -82,8 +83,8 @@ pub fn load_optifine(root: &Path, sprites: &mut Sprites) -> Vec<(String, String)
pub const CUTOUT: u32 = 1 << 31;
/// The frame's overlay table: native mods' pairs (at most [`NATIVE`] requested), then the packs'
-/// OptiFine pairs flagged [`CUTOUT`], one per base layer (native first), sorted by base layer
-/// for the shader's early exit, at most [`MAX`].
+/// OptiFine pairs flagged [`CUTOUT`] (at most [`MAX`] - [`NATIVE`], as [`load_optifine`] loads),
+/// one per base layer with native mods' first, sorted by base layer for the shader's early exit.
pub fn table<'a>(
layers: &BTreeMap<String, u32>,
native: impl IntoIterator<Item = (&'a str, &'a str)>,
@@ -97,7 +98,7 @@ pub fn table<'a>(
for [b, o, z, w] in mappings(layers, optifine) {
by_base.entry(b).or_insert([b, o | CUTOUT, z, w]);
}
- by_base.into_values().take(MAX).collect()
+ by_base.into_values().collect()
}
/// Only loaded base/overlay pairs are sent to the GPU; sorted for vertex lookup.
@@ -218,9 +219,18 @@ mod tests {
[[2, 3 | CUTOUT, 0, 0], [5, 9, 0, 0]],
"sorted by base layer"
);
- // Native mods keep their 32.
- let many: Vec<(&str, &str)> = (0..40).map(|_| ("b", "native")).collect();
- assert_eq!(table(&layers, many, &[]), [[2, 9, 0, 0]]);
+ // Native mods keep their 32: of 40 requests on 40 bases, the first 32.
+ let layers: BTreeMap<String, u32> =
+ (0..41u32).map(|i| (format!("s{i}"), 100 + i)).collect();
+ let names: Vec<String> = (1..41).map(|i| format!("s{i}")).collect();
+ let many = names.iter().map(|n| (n.as_str(), "s0"));
+ let t = table(&layers, many, &[]);
+ assert_eq!(t.len(), 32);
+ assert_eq!(
+ t.last(),
+ Some(&[132, 100, 0, 0]),
+ "s32 last; s33 to s40 cut"
+ );
}
#[test]
fn only_existing_pairs_are_mapped() {
diff --git a/crates/horizon-client-render/src/sprites.rs b/crates/horizon-client-render/src/sprites.rs
index de55cb985..48521e5b7 100644
--- a/crates/horizon-client-render/src/sprites.rs
+++ b/crates/horizon-client-render/src/sprites.rs
@@ -302,9 +302,6 @@ impl Sprites {
}
}
}
- /// The layer of a texture, added on first use. A texture that is missing
- /// or does not load (a resource pack's filter or a broken file) becomes
- /// vanilla's missing texture, as in a stitched atlas.
/// [`Sprites::insert`] without the missing-texture fallback: a file that doesn't load is an
/// error, and nothing is added.
pub fn try_insert(&mut self, root: &Path, name: &str) -> Result<u32> {
@@ -313,6 +310,9 @@ impl Sprites {
None => self.load(root, name),
}
}
+ /// The layer of a texture, added on first use. A texture that is missing
+ /// or does not load (a resource pack's filter or a broken file) becomes
+ /// vanilla's missing texture, as in a stitched atlas.
pub fn insert(&mut self, root: &Path, name: &str) -> Result<u32> {
if let Some(layer) = self.layers.get(name) {
return Ok(*layer);
diff --git a/docs/resource-packs.md b/docs/resource-packs.md
index 0805714ef..f7965c03c 100644
--- a/docs/resource-packs.md
+++ b/docs/resource-packs.md
@@ -40,7 +40,7 @@ harness named checks that loader against vanilla).
| 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, 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 128 block overlays (with native mods'), cutout; not over items, armour trims, other projectiles, minecarts or end crystals, nor connected-texture tiles |
+| 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 |
| 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` |