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 CTM: connected glass panes look as OptiFine draws them

some-du6e28e10cbf9575
diff --git a/crates/horizon-client-render/src/connected.rs b/crates/horizon-client-render/src/connected.rs
index e844042d2..894aaf1a3 100644
--- a/crates/horizon-client-render/src/connected.rs
+++ b/crates/horizon-client-render/src/connected.rs
@@ -79,8 +79,13 @@ struct StateInfo {
axis: Option<Axis>,
/// `half=upper`: `linked` random tiles follow the lower half.
upper: bool,
+ /// A pane's arms (`north`, `east`, `south`, `west` true), as bits of [`ARMS`].
+ arms: u8,
}
+/// A pane's arm properties, in [`StateInfo::arms`]' bit order.
+const ARMS: [&str; 4] = ["north", "east", "south", "west"];
+
#[derive(Default)]
pub struct ConnectedTextures {
rules: Vec<LoadedRule>,
@@ -299,6 +304,11 @@ impl ConnectedTextures {
_ => None,
},
upper: prop("half") == Some("upper"),
+ arms: ARMS
+ .iter()
+ .enumerate()
+ .filter(|&(_, arm)| prop(arm) == Some("true"))
+ .fold(0, |bits, (i, _)| bits | 1 << i),
});
list.clear();
if let Some(candidates) = by_block.get(name) {
@@ -318,6 +328,35 @@ impl ConnectedTextures {
self.rules.is_empty()
}
+ /// Whether a pane's top or bottom strip, centred at `centre` (block-local x, z), is hidden by
+ /// the pane `other` stacked on it (Continuity's "Glass Pane Culling Fix"): only for a pane
+ /// with connected-texture rules, under or over the same block, where `other` has the same
+ /// part (the post, or the arm toward the strip).
+ pub fn stacked_pane_hides(&self, state: u32, other: u32, [x, z]: [f32; 2]) -> bool {
+ let (Some(own), Some(theirs)) = (
+ self.states.get(state as usize),
+ self.states.get(other as usize),
+ ) else {
+ return false;
+ };
+ if own.block != theirs.block || self.list(&self.by_state, state as usize).is_empty() {
+ return false;
+ }
+ let (dx, dz) = (x - 0.5, z - 0.5);
+ // The post is 2 pixels wide; an arm runs from it to the block's edge.
+ if dx.abs() <= 1.0 / 16.0 && dz.abs() <= 1.0 / 16.0 {
+ return true;
+ }
+ let arm = if dz.abs() > dx.abs() {
+ if dz < 0.0 { 0 } else { 2 }
+ } else if dx > 0.0 {
+ 1
+ } else {
+ 3
+ };
+ theirs.arms & 1 << arm != 0
+ }
+
fn list(&self, ranges: &[(u32, u32)], i: usize) -> &[u16] {
ranges.get(i).map_or(&[], |&(start, len)| {
&self.lists[start as usize..(start + len) as usize]
@@ -978,6 +1017,47 @@ mod tests {
assert_eq!((layers, pick), (vec![1001, 3000], Pick::Keep));
}
+ #[test]
+ fn stacked_panes_hide_the_strips_they_share() {
+ let props = |pairs: &[(&str, &str)]| -> BlockProperties {
+ pairs
+ .iter()
+ .map(|(k, v)| (k.to_string(), v.to_string()))
+ .collect()
+ };
+ // 0 a pane with north and east arms, 1 the same pane with only a north arm, 2 another
+ // pane block, 3 a pane no rule names.
+ let states = [
+ (
+ "minecraft:glass_pane",
+ props(&[("north", "true"), ("east", "true")]),
+ ),
+ ("minecraft:glass_pane", props(&[("north", "true")])),
+ (
+ "minecraft:white_stained_glass_pane",
+ props(&[("north", "true")]),
+ ),
+ ("minecraft:iron_bars", props(&[("north", "true")])),
+ ];
+ let ctm = ConnectedTextures::build(
+ rules(&[(
+ "pane.properties",
+ "matchBlocks=glass_pane white_stained_glass_pane\nmethod=ctm\ntiles=0-46",
+ )]),
+ states.iter().map(|(n, p)| Some((*n, p))),
+ |_| None,
+ );
+ let (post, north, east) = ([0.5, 0.5], [0.5, 0.2], [0.8, 0.5]);
+ assert!(ctm.stacked_pane_hides(0, 1, post));
+ assert!(ctm.stacked_pane_hides(0, 1, north));
+ // The pane above has no east arm: the strip shows.
+ assert!(!ctm.stacked_pane_hides(0, 1, east));
+ assert!(ctm.stacked_pane_hides(1, 0, north));
+ // Another block, or a pane without rules, hides nothing.
+ assert!(!ctm.stacked_pane_hides(1, 2, post));
+ assert!(!ctm.stacked_pane_hides(3, 3, post));
+ }
+
#[test]
fn sprite_names() {
assert_eq!(
diff --git a/crates/horizon-client-render/src/mesher.rs b/crates/horizon-client-render/src/mesher.rs
index c232c7dfb..af3d9a59c 100644
--- a/crates/horizon-client-render/src/mesher.rs
+++ b/crates/horizon-client-render/src/mesher.rs
@@ -16,6 +16,7 @@ use crate::{
graphics::LeafCullingMode,
models::catalog::BakedFace,
};
+use horizon_assets::model::Direction as ModelDirection;
use horizon_core::{
biome::BiomeZoom, geometry::Direction, position::BlockPos, random::position_seed,
};
@@ -474,6 +475,9 @@ struct Info {
overlay: bool,
/// `LeavesBlock`: with opaque leaves the faces between two leaf blocks are skipped.
leaves: bool,
+ /// A glass pane: connected-texture tiles take the cube's UVs on it (OptiFine's pane models
+ /// drop vanilla's mirrored faces).
+ pane: bool,
/// A full opaque cube: `RenderShape::Model`, `can_occlude`, `solid_render`
/// and a full collision shape. The only block leaf culling treats as solid.
opaque_cube: bool,
@@ -654,6 +658,7 @@ impl MeshTables {
legacy_solid: s.legacy_solid,
overlay: s.has_class("HalfTransparentBlock") || s.has_class("LeavesBlock"),
leaves: s.has_class("LeavesBlock"),
+ pane: s.has_class("IronBarsBlock") && name.ends_with("glass_pane"),
opaque_cube: leaf_culling::opaque_cube(
s.render_shape,
s.can_occlude,
@@ -1251,11 +1256,30 @@ impl Mesher<'_> {
)
.unwrap_or(true);
}
+ let connected = &self.render.connected;
for model in &models {
for face in &model.faces {
if face.quad.cull.is_some_and(|d| !visible[d as usize]) {
continue;
}
+ // A pane's top and bottom strips between stacked panes, with
+ // connected textures.
+ if state.pane
+ && !connected.is_empty()
+ && let Some(dy) = match face.quad.facing {
+ ModelDirection::Up => Some(1),
+ ModelDirection::Down => Some(-1),
+ _ => None,
+ }
+ {
+ let p = &face.quad.positions;
+ let centre =
+ [0, 2].map(|k| p.iter().map(|v| v[k]).sum::<f32>() / 4.0);
+ let other = pad.blocks[pi(x, y + dy, z)];
+ if connected.stacked_pane_hides(id, other, centre) {
+ continue;
+ }
+ }
self.face(
pad,
&mut tints,
@@ -1377,7 +1401,11 @@ impl Mesher<'_> {
)
})
};
- let corners = vertices(tint, q.uv);
+ // Vanilla's pane models mirror some faces' textures; OptiFine's don't, so a tile's borders
+ // land where the neighbours are: on a pane, tiles take the cube's own UVs.
+ let standard = q.positions.map(|p| standard_uv(q.facing, p));
+ let tiled = !matches!(pick, Pick::Keep);
+ let corners = vertices(tint, if state.pane && tiled { standard } else { q.uv });
// Opaque leaves (forceOpaque) and leaves a leaf-culling mode proved internal draw in the
// solid layer whatever their sprite.
let solid_leaves = !self.cutout_leaves && state.leaves || interior_leaf;
@@ -1426,10 +1454,9 @@ impl Mesher<'_> {
Pick::Tile(t) => self.translucent(tile(t)),
Pick::Quarters(tiles) => tiles.into_iter().any(|t| self.translucent(tile(t))),
};
- // Overlay tiles face the standard way (Continuity: "overlay textures always have the
+ // Overlay tiles face the standard way too (Continuity: "overlay textures always have the
// standard orientation"), whatever turns the model's own UVs (dirt's and sand's random
- // rotations): the cube's UVs at the quad's corners.
- let standard = q.positions.map(|p| standard_uv(q.facing, p));
+ // rotations).
// Over a `ctm_compact` face, the same pieces: the same depths and sort centres.
let cuts = match pick {
Pick::Quarters(_) => cuts(&corners),
diff --git a/crates/horizon-client-render/src/mesher/leaf_culling.rs b/crates/horizon-client-render/src/mesher/leaf_culling.rs
index 04f7027d7..5b5dde93b 100644
--- a/crates/horizon-client-render/src/mesher/leaf_culling.rs
+++ b/crates/horizon-client-render/src/mesher/leaf_culling.rs
@@ -322,6 +322,7 @@ mod tests {
legacy_solid: false,
overlay: leaves,
leaves,
+ pane: false,
opaque_cube: opaque,
blocks_flow: false,
ice: false,
diff --git a/crates/horizon-client-render/src/mesher/visibility_tests.rs b/crates/horizon-client-render/src/mesher/visibility_tests.rs
index 006419893..c1952c483 100644
--- a/crates/horizon-client-render/src/mesher/visibility_tests.rs
+++ b/crates/horizon-client-render/src/mesher/visibility_tests.rs
@@ -88,6 +88,7 @@ fn info(solid: bool) -> Info {
legacy_solid: false,
overlay: false,
leaves: false,
+ pane: false,
opaque_cube: solid,
blocks_flow: false,
ice: false,