diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 5c05ad024..cf5bac65e 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -1416,10 +1416,10 @@ impl Game<'_> { if let Some(p) = r.pending_items.get_mut(&id) { p.0 = position; } - // ItemEntity and FallingBlockEntity keep Entity's NO_OP - // InterpolationHandler: moveOrInterpolateTo puts them there at - // once, and their own tick moves them on between the server's - // updates (`tick_remote_entities`). + // ItemEntity, FallingBlockEntity and PrimedTnt keep Entity's + // NO_OP InterpolationHandler: moveOrInterpolateTo puts them there + // at once, and their own tick moves them on between the server's + // updates (`tick_remote_entities`, `tick_remote_projectiles`). let at = Vec3::new(position[0], position[1], position[2]); if let Some(d) = self.dropped.iter_mut().find(|d| d.id == id as u32) { d.position = at; @@ -1430,6 +1430,11 @@ impl Game<'_> { f.position = at; return; } + if let Some(t) = self.tnts.iter_mut().find(|t| t.id == id as u32) { + t.position = at; + t.on_ground = on_ground; + return; + } // AbstractInterpolationHandler.interpolateTo: without a rotation, // the one it was heading for. let rotation = rotation.or_else(|| r.lerps.get(&id).and_then(|l| l.rotation)); @@ -2926,14 +2931,16 @@ impl Game<'_> { }); } /// `Entity.lerpMotion` (and `recreateFromPacket`'s motion) for the - /// entities whose own tick moves them on a client: dropped items and - /// falling blocks. + /// entities whose own tick moves them on a client: dropped items, falling + /// blocks and primed TNT. fn remote_motion(&mut self, id: i32, velocity: [f64; 3]) { let v = Vec3::new(velocity[0], velocity[1], velocity[2]); if let Some(d) = self.dropped.iter_mut().find(|d| d.id == id as u32) { d.velocity = v; } else if let Some(f) = self.falling.iter_mut().find(|f| f.id == id as u32) { f.velocity = v; + } else if let Some(t) = self.tnts.iter_mut().find(|t| t.id == id as u32) { + t.velocity = v; } else if let Some(p) = self .remote .as_mut() diff --git a/crates/horizon-client/src/game/remote_projectiles.rs b/crates/horizon-client/src/game/remote_projectiles.rs index 5c494b9ae..3fade3165 100644 --- a/crates/horizon-client/src/game/remote_projectiles.rs +++ b/crates/horizon-client/src/game/remote_projectiles.rs @@ -220,10 +220,21 @@ impl Game<'_> { /// One tick of interpolation, as `tick_remote_objects`. pub(super) fn tick_remote_projectiles(&mut self, mut step: impl FnMut(u32, Vec3) -> Vec3) { - for t in &mut self.tnts { - t.previous = t.position; - t.position = step(t.id, t.position); - } + // PrimedTnt.tick runs on a client too: it falls, bounces and burns its + // fuse down (the swell and flash follow it) between the server's + // updates (every 10 ticks), and a client discards it when the fuse + // runs out; only the server explodes it. + let (world, collision, assets, facts) = ( + &self.world, + self.collision, + &self.pack.assets, + self.res.facts(), + ); + self.tnts.retain_mut(|t| { + // A fluid lookup that fails leaves it where its move put it. + let _ = t.tick(world, collision, assets, facts); + t.fuse > 0 + }); // FallingBlockEntity.tick runs on a client too: the block falls by // itself between the server's updates (every 20 ticks), then waits // where it lands for the server to place it and remove it. diff --git a/crates/horizon-client/src/game/tnt.rs b/crates/horizon-client/src/game/tnt.rs index fddc02125..6bd2ae956 100644 --- a/crates/horizon-client/src/game/tnt.rs +++ b/crates/horizon-client/src/game/tnt.rs @@ -33,7 +33,7 @@ impl PrimedTnt { ), ) } - fn tick( + pub(super) fn tick( &mut self, world: &horizon_client::world::World, collision: &horizon_world::block_collision::BlockCollisionRegistry<'_>, diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 4d89a374f..3bb94744e 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -247,9 +247,10 @@ address. The script then checks, from both sides, what a guest's game used to ge sends each target its packet). - hero-trading: the host and the guest each trade 20 wheat for an emerald, paying 14 with Hero I and 12 with Hero III; clearing the effect restores the ordinary price (#1365). -- falling: an item and a falling block the host summons high up fall smoothly on the guest, a - little further every tick between the server's updates (every 20 ticks), as their own - client tick moves them (they used to hang, then jump down once a second, #1568). +- falling: an item, a falling block and primed TNT the host summons high up fall smoothly on the + guest, a little further every tick between the server's updates (every 20 ticks, 10 for + TNT), as their own client tick moves them (they used to hang, then jump down once a + second, #1568), and the TNT's fuse burns down on the guest too. - instant_digging: an instant survival break leaves no repeated stone hit sounds or stale server dig (#1908). - replant: flowers and crops replanted after a short harvest click stay planted for both players; the server forgets the completed instant break (#1880). @@ -6186,10 +6187,11 @@ CHECK_FNS.update(large_chest=check_large_chest) def check_falling(host, guest, out): - """ItemEntity and FallingBlockEntity tick on a client too (gravity, collisions, drag), and their - position packets snap them (Entity's NO_OP InterpolationHandler). The server sends an item's - and a falling block's position every 20 ticks, so between two updates the guest's own tick is - what moves them: sampled every 2 ticks over the first 16, both are lower nearly every time.""" + """ItemEntity, FallingBlockEntity and PrimedTnt tick on a client too (gravity, collisions, drag), + and their position packets snap them (Entity's NO_OP InterpolationHandler). The server sends an + item's and a falling block's position every 20 ticks and TNT's every 10, so between two updates + the guest's own tick is what moves them: sampled every 2 ticks over the first 16, all three are + lower nearly every time. The TNT's fuse (sent once, at spawn) counts down on the guest too.""" x, y, z = (int(v // 1) for v in pos_of(guest)) top = y + 30 tag = 'falling_e2e' @@ -6198,7 +6200,10 @@ def check_falling(host, guest, out): f'{{Tags:["{tag}"],Item:{{id:"minecraft:diamond",count:1}},PickupDelay:32767}}') host('command', command=f'summon minecraft:falling_block {x + 2.5} {top} {z - 0.5} ' f'{{Tags:["{tag}"],BlockState:{{Name:"minecraft:sand"}},DropItem:0b}}') - heights = {'item': [], 'falling block': []} + # Horizon's selectors don't see primed TNT yet: its fuse ends it in the air, 19 blocks down. + host('command', command=f'summon minecraft:tnt {x + 4.5} {top} {z + 0.5} {{fuse:34s}}') + heights = {'item': [], 'falling block': [], 'primed tnt': []} + fuses = [] try: for _ in range(8): items = [e['pos'][1] for e in guest.raw('entities', 48, 'minecraft:item')['entities'] @@ -6206,8 +6211,12 @@ def check_falling(host, guest, out): blocks = [o['position'][1] for o in guest('status')['projectiles'] if o.get('kind') == 'minecraft:falling_block' and abs(o['position'][0] - x - 2.5) < 0.5 and abs(o['position'][2] - z + 0.5) < 0.5] + tnts = [o for o in guest('status')['projectiles'] if o.get('kind') == 'minecraft:tnt' + and abs(o['position'][0] - x - 4.5) < 0.5 and abs(o['position'][2] - z - 0.5) < 0.5] heights['item'].append(items[0] if items else None) heights['falling block'].append(blocks[0] if blocks else None) + heights['primed tnt'].append(tnts[0]['position'][1] if tnts else None) + fuses.append(tnts[0]['fuse'] if tnts else None) guest.wait(2) guest.shot(out, 'falling') finally: @@ -6219,7 +6228,24 @@ def check_falling(host, guest, out): drops = sum(b < a for a, b in zip(seen, seen[1:])) # A tick or two can pass between two samples with no move; never most of them. assert drops >= len(seen) - 2, f'the {name} fell in {drops} of {len(seen) - 1} samples: {heights}' - return heights + # The server sends the TNT's fuse with each move, so each sample says how many ticks it has + # fallen from rest: snapped to the server's place and ticking on, the guest has it exactly + # there (it used to trail two ticks behind, interpolating towards each update). + fell = [(h, 34 - f) for h, f in zip(heights['primed tnt'], fuses) if f is not None] + assert fell and fell[-1][1] > fell[0][1], f'the TNT\'s fuse on the guest: {fuses}' + off = max(abs(h - tnt_fall(top, n)) for h, n in fell) + assert off < 0.01, f'the guest\'s TNT is {off:.3f} off its fall (height, ticks): {fell}' + return {**heights, 'fuse': fuses} + + +def tnt_fall(top, ticks): + """PrimedTnt.tick in open air from rest: its height after `ticks` ticks.""" + y, v = top, 0.0 + for _ in range(ticks): + v -= 0.04 + y += v + v *= 0.98 + return y CHECKS += ['falling']