LAN and dedicated servers wait for the player's client to finish breaking a block
ServerPlayerGameMode breaks a digging player's block only when the player's client says it is done (STOP_DESTROY_BLOCK, or the delayed destroy), or at once when it is instant. The host ran the guest's tick_mining with its own count and broke the block when that reached 1. A guest whose client ran even a tick behind lost the block before it predicted the break: no destroy particles, no break sound, and the dropped item could appear before the block vanished. lan_e2e's new digging check holds attack across six oak logs and hears six breaks, then stalls the guest for a second halfway through stone: the stone is still there on both sides when it resumes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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)?;
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user