diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 6184f1626..b1777eba8 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -3803,7 +3803,12 @@ impl Game<'_> { } self.crack_particle(crack.0, crack.1, state); let m = self.mining.as_mut().ok_or("mining")?; - if m.progress >= 1.0 { + // ServerPlayerGameMode breaks a player's block at once only when it is instant (START's + // insta-mine); otherwise it waits for the client's STOP_DESTROY_BLOCK + // (`guest_stop_digging`), never breaking it on its own count. Breaking it here would + // take the block from under the player's crack before the player's client predicts the + // break, so it gets neither particles nor sound. + if m.progress >= 1.0 && (self.lan_acting.is_none() || m.ticks == 1) { let pos = m.pos; self.mining = None; self.break_block(pos)?; diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 994636066..f69081945 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -4521,5 +4521,73 @@ CHECKS += ['totem'] CHECK_FNS.update(totem=check_totem) +def check_digging(host, guest, out): + """The server breaks a block a player digs only once that player's client is done + (ServerPlayerGameMode: STOP_DESTROY_BLOCK, or the delayed destroy), never on its own count, so + the player's client always breaks it first, with its particles and sound. The guest holds + attack across a wall of six oak logs with a copper axe and hears each one break; then it digs + stone with a wooden pickaxe and its game stalls for a second halfway: the stone is still there + on both sides when it resumes, and the guest's own crack finishes it.""" + gx, gy, gz = (int(v // 1) for v in pos_of(guest)) + x, y, z = gx + 3, gy, gz + 4 + heard = lambda sound: guest('status')['heard'].get(sound, 0) + at = lambda b: (f'{b[0] + 0.02:.2f}', f'{b[1] + 0.5:.2f}', f'{b[2] + 0.5:.2f}') + guest('command', command='gamemode survival') + guest('command', command='item replace entity @s weapon.mainhand with minecraft:copper_axe') + host('command', command=f'fill {x - 2} {y - 1} {z - 2} {x + 4} {y + 3} {z + 2} minecraft:air') + host('command', command=f'fill {x - 2} {y - 1} {z - 2} {x + 4} {y - 1} {z + 2} minecraft:stone') + host('command', command=f'fill {x + 2} {y} {z - 1} {x + 2} {y + 1} {z + 1} minecraft:oak_log') + guest('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}') + guest.wait(30) + logs = [(x + 2, y + dy, z + dz) for dz in (-1, 0, 1) for dy in (0, 1)] + before = heard('minecraft:block.wood.break') + guest.raw('look-at', *at(logs[0])) + guest.raw('mouse', 'left', 'down') + left = list(logs) + deadline = time.time() + 20 + while left and time.time() < deadline: + if guest.raw('block', *left[0]).get('block') != 'minecraft:oak_log': + left.pop(0) + if left: + guest.raw('look-at', *at(left[0])) + guest.raw('mouse', 'left', 'up') + guest.wait(10) + seen = {'logs_left': left, 'log_breaks_heard': heard('minecraft:block.wood.break') - before} + + # Stone with a wooden pickaxe: 23 ticks. The guest stalls for a second after about 8. + stone = (x + 2, y, z) + guest('command', command='item replace entity @s weapon.mainhand with minecraft:wooden_pickaxe') + host('command', command=f'setblock {stone[0]} {stone[1]} {stone[2]} minecraft:stone') + guest.wait(10) + before = heard('minecraft:block.stone.break') + guest.raw('look-at', *at(stone)) + guest.raw('mouse', 'left', 'down') + time.sleep(0.4) + os.kill(guest.pid, signal.SIGSTOP) + try: + time.sleep(1.0) + finally: + os.kill(guest.pid, signal.SIGCONT) + resumed = {'guest': guest.raw('block', *stone).get('block'), 'server': host.raw('block', *stone).get('block'), + 'mining': guest('state').get('mining')} + # Let go once it breaks: past it the crosshair reaches the floor. + deadline = time.time() + 5 + while guest.raw('block', *stone).get('block') == 'minecraft:stone' and time.time() < deadline: + pass + guest.raw('mouse', 'left', 'up') + guest.wait(10) + seen.update(resumed=resumed, stone_after=host.raw('block', *stone).get('block'), + stone_breaks_heard=heard('minecraft:block.stone.break') - before) + guest.shot(out, 'digging') + assert not left and seen['log_breaks_heard'] == 6, f'the server broke logs before the guest did: {seen}' + assert resumed['guest'] == resumed['server'] == 'minecraft:stone', f'the server broke the stone while the guest stalled: {seen}' + assert seen['stone_after'] == 'minecraft:air' and seen['stone_breaks_heard'] == 1, f'the guest did not break the stone: {seen}' + return seen + + +CHECKS += ['digging'] +CHECK_FNS.update(digging=check_digging) + + if __name__ == '__main__': main()