c4d6b34172
On a server or a world open to LAN, a player saw only their own crack. The server sent each new stage to the others (ClientboundBlockDestruction), but a client of a server ignored the packet, and the host of a LAN world neither drew its guests' cracks nor sent its own to them. Vanilla keeps the cracks per breaker (ClientLevel.destroyBlockProgress: a progress outside 0..9 removes it, 400 ticks without news drops it) and draws, within 32 blocks, the furthest one on each block (LevelExtractor.extractBlockDestroyAnimation). Horizon now does the same: a client of a server takes the packet, a LAN host records its guests' stages and sends its own (each new stage, then -1 when it stops), and every crack is drawn with its own stage. A guest's crack also goes when the block it digs is gone before its STOP_DESTROY_BLOCK (its own tick broke it), as ServerPlayerGameMode.tick clears it on air: the others kept its last stage for 400 ticks. Each crack vertex carries its stage sprite's atlas origin in its light bytes (the crumbling pass is unlit); the shader keeps the shared sprite size. lan_e2e `cracks`: each side watches the block the other mines and sees its crack grow; no crack is left once the blocks break. The screenshots from both sides show the cracks. Fixes #1096 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
2.9 KiB
Rust
79 lines
2.9 KiB
Rust
//! Headless transport for real model-shaped breaking overlays.
|
|
use horizon_client::{
|
|
assets::Assets,
|
|
blocks::{BlockFacts, RenderShape},
|
|
breaking,
|
|
mesher::MeshTables,
|
|
models,
|
|
};
|
|
use horizon_core::position::BlockPos;
|
|
use horizon_world::registry::BlockStateId;
|
|
use serde_json::{Value, json};
|
|
use std::{
|
|
fs,
|
|
io::{BufRead, BufReader, BufWriter, Write},
|
|
path::Path,
|
|
};
|
|
/// The stage sprite origin the cracks carry (the oracle compares the geometry and UVs only).
|
|
const STAGE: [f32; 2] = [0.25, 0.5];
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let args: Vec<_> = std::env::args().collect();
|
|
let root = Path::new(&args[1]);
|
|
let assets = Assets::load(root)?;
|
|
let render = assets.reload(root)?;
|
|
let facts = BlockFacts::load(root, assets.registry)?;
|
|
let tables = MeshTables::new(
|
|
&assets,
|
|
&render,
|
|
&facts,
|
|
models::load_visibility(root, assets.registry)?,
|
|
)?;
|
|
let mut output = BufWriter::new(fs::File::create(&args[3])?);
|
|
for line in BufReader::new(fs::File::open(&args[2])?).lines() {
|
|
let row: Value = serde_json::from_str(&line?)?;
|
|
let state = BlockStateId(row["state"].as_u64().unwrap() as u32);
|
|
let p: [i32; 3] = serde_json::from_value(row["pos"].clone())?;
|
|
let camera: [f64; 3] = serde_json::from_value(row["camera"].clone())?;
|
|
let mut vertices = Vec::new();
|
|
let mut translucent = false;
|
|
if facts.get(state).render_shape == RenderShape::Model {
|
|
let models = render
|
|
.model_catalog
|
|
.collect(state, BlockPos::new(p[0], p[1], p[2]))?;
|
|
let offset = tables.offset(state, p[0], p[2]).unwrap_or([0.0; 3]);
|
|
let origin = (glam::DVec3::new(f64::from(p[0]), f64::from(p[1]), f64::from(p[2]))
|
|
- glam::DVec3::from(camera))
|
|
.as_vec3()
|
|
+ glam::DVec3::from(offset).as_vec3();
|
|
translucent = models
|
|
.iter()
|
|
.any(|(_, m)| m.faces.iter().any(|f| f.translucent));
|
|
for (_, m) in models {
|
|
breaking::geometry(m, origin, translucent, STAGE, &mut vertices);
|
|
}
|
|
}
|
|
let quads: Vec<_> = vertices
|
|
.as_chunks::<4>()
|
|
.0
|
|
.iter()
|
|
.map(|q| {
|
|
q.iter()
|
|
.map(|v| {
|
|
assert_eq!(v.color, 0xffff_ffff);
|
|
assert_eq!(v.light, breaking::stage_light(STAGE));
|
|
assert_eq!(v.layer, if translucent { 12 } else { 11 });
|
|
[v.pos[0], v.pos[1], v.pos[2], v.uv[0], v.uv[1]]
|
|
})
|
|
.collect::<Vec<_>>()
|
|
})
|
|
.collect();
|
|
serde_json::to_writer(
|
|
&mut output,
|
|
&json!({"case":row["case"],"translucent":translucent,"quads":quads}),
|
|
)?;
|
|
output.write_all(&[10])?;
|
|
}
|
|
output.flush()?;
|
|
Ok(())
|
|
}
|