Server clients: primed TNT falls and burns its fuse by itself between updates

PrimedTnt keeps Entity's NO_OP InterpolationHandler and ticks on a client
too: a position packet puts it there at once, its own tick moves it on
(gravity, collisions, bounces, drag) and burns the fuse down, and a client
discards it when the fuse runs out. Horizon interpolated it towards each
update instead, so it trailed about two ticks behind the server.

lan_e2e's falling check now drops primed TNT too and checks that the
guest has it exactly where its fall from rest puts it for the fuse the
server sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-25 02:57:26 +02:00
parent fe253fe534
commit 1fa46979c8
4 changed files with 64 additions and 20 deletions
+13 -6
View File
@@ -1465,10 +1465,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;
@@ -1479,6 +1479,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));
@@ -2974,14 +2979,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()
@@ -181,10 +181,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.
+1 -1
View File
@@ -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<'_>,
+35 -9
View File
@@ -228,9 +228,10 @@ address. The script then checks, from both sides, what a guest's game used to ge
- villagers: the guest sees each villager's and zombie villager's type, profession and level as the
host has them, and an unemployed villager that takes a composter becomes a farmer on
the guest too (the guest used to draw every villager as an unemployed plains one).
- 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.
Each check is reported on its own (a failing one doesn't stop the others) and the screenshots of
both sides go to --out (host-*.png, guest-*.png).
@@ -5500,10 +5501,11 @@ CHECK_FNS.update(villagers=check_villagers)
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'
@@ -5512,7 +5514,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']
@@ -5520,8 +5525,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:
@@ -5533,7 +5542,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']