Merge pull request #1922 from rdbtCVS/t3/fix-crop-planting-harvesting
🤖 Agent: Thanks rdbt! Matches ServerPlayerGameMode.handleBlockBreakAction: an instant survival START never leaves a block being destroyed, so no repeated hit sounds and a replanted crop isn't broken again. It now includes #1966's sound regression. Tested together with the other wave 1 contributor PRs on current main: fmt, clippy -D warnings and the horizon-client tests (1,120 lib tests and the rest) pass; the 114 harnesses the batch affects pass; lan_e2e anvil, grindstone, replant, instant_digging, digging, frames and leads pass with the host in-frame and on its server thread.
This commit is contained in:
@@ -1808,14 +1808,13 @@ impl Game<'_> {
|
||||
g.use_delay -= 1;
|
||||
}
|
||||
});
|
||||
// ServerPlayerGameMode.handleBlockBreakAction: a creative
|
||||
// player's START breaks the block once (destroyAndAck) and
|
||||
// leaves nothing being destroyed; its client sends no STOP.
|
||||
// Kept, the dig broke whatever was put there next, every
|
||||
// destroy delay, for as long as the player broke nothing else.
|
||||
// ServerPlayerGameMode.handleBlockBreakAction: creative and
|
||||
// instant survival STARTs finish without a STOP from the client.
|
||||
// tick_mining clears mining on completion; forget the START too,
|
||||
// so a flower or crop planted here later is not broken again.
|
||||
if digging.is_some()
|
||||
&& host.hub.guests[gi].creative()
|
||||
&& let Some(play) = host.play.get_mut(&conn)
|
||||
&& (host.hub.guests[gi].creative() || play.mining.is_none())
|
||||
{
|
||||
play.digging = None;
|
||||
}
|
||||
|
||||
@@ -250,6 +250,9 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
- 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).
|
||||
- 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).
|
||||
|
||||
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).
|
||||
@@ -5396,6 +5399,42 @@ CHECKS += ['digging']
|
||||
CHECK_FNS.update(digging=check_digging)
|
||||
|
||||
|
||||
def check_instant_digging(host, guest, out):
|
||||
"""#1908: an instant survival START has no STOP. ServerPlayerGameMode.tick
|
||||
forgets a dig once its block is air; it must neither hit air nor break a replacement.
|
||||
Exercise the in-frame host and network guest (both are clients with --server-thread).
|
||||
"""
|
||||
result = {}
|
||||
for label, player in (('host', host), ('guest', guest)):
|
||||
x, y, z = (int(v // 1) for v in pos_of(player))
|
||||
cell = (x, y + 1, z + 2)
|
||||
player('command', command='gamemode survival')
|
||||
player('command', command='clear @s')
|
||||
host('command', command=f'fill {x - 1} {y} {z + 1} {x + 1} {y + 3} {z + 4} minecraft:air')
|
||||
host('command', command=f'setblock {x} {y} {z + 2} minecraft:sand')
|
||||
host('command', command=f'setblock {cell[0]} {cell[1]} {cell[2]} minecraft:dead_bush')
|
||||
player.wait(10)
|
||||
before = heard(player, 'minecraft:block.stone.hit')
|
||||
player.raw('look-at', x + 0.5, y + 1.4, z + 2.5)
|
||||
player.raw('mouse', 'left', 'click')
|
||||
player.wait(20)
|
||||
broken = host.raw('block', *cell).get('block')
|
||||
hits = heard(player, 'minecraft:block.stone.hit') - before
|
||||
host('command', command=f'setblock {cell[0]} {cell[1]} {cell[2]} minecraft:dead_bush')
|
||||
player.wait(20)
|
||||
replacement = host.raw('block', *cell).get('block')
|
||||
result[label] = {'broken': broken, 'stone_hits': hits, 'replacement': replacement}
|
||||
assert broken == 'minecraft:air', f'{label}: the bush did not break: {result}'
|
||||
assert hits == 0, f'{label}: hitting air after an instant break: {result}'
|
||||
assert replacement == 'minecraft:dead_bush', f'{label}: the server kept digging: {result}'
|
||||
host('command', command=f'setblock {cell[0]} {cell[1]} {cell[2]} minecraft:air')
|
||||
return result
|
||||
|
||||
|
||||
CHECKS += ['instant_digging']
|
||||
CHECK_FNS.update(instant_digging=check_instant_digging)
|
||||
|
||||
|
||||
def check_vehicles(host, guest, out):
|
||||
"""The host and the guest each (#1551):
|
||||
- in creative, break a block and have it put back: the server's dig ends with the break
|
||||
@@ -6398,5 +6437,71 @@ CHECKS += ['sprint-fov']
|
||||
CHECK_FNS['sprint-fov'] = check_sprint_fov
|
||||
|
||||
|
||||
def check_replant(host, guest, out):
|
||||
"""Instant breaks leave no server dig that can destroy a replacement (#1880).
|
||||
|
||||
ServerPlayerGameMode.handleBlockBreakAction's insta-mine branch finishes on
|
||||
START; MultiPlayerGameMode sends no STOP or ABORT when attack is released.
|
||||
Exercise actual flower placement and seed planting after a short click.
|
||||
"""
|
||||
spots = apart(host, guest)
|
||||
seen = {}
|
||||
host('command', command='gamerule random_tick_speed 0')
|
||||
try:
|
||||
for label, player in (('host', host), ('guest', guest)):
|
||||
x, y, z = spots[label]
|
||||
cell = (x, y, z + 2)
|
||||
|
||||
def observe(block):
|
||||
# The integrated host is itself a client: wait for both views.
|
||||
for _ in range(40):
|
||||
blocks = [g.raw('block', *cell).get('block') for g in (host, guest)]
|
||||
if blocks == [f'minecraft:{block}'] * 2:
|
||||
return blocks
|
||||
host.wait(2)
|
||||
raise AssertionError(f'{label} expected {block} on both clients: {blocks}')
|
||||
|
||||
for mode, block, item, soil in (
|
||||
('survival', 'dandelion', 'dandelion', 'dirt'),
|
||||
('survival', 'wheat', 'wheat_seeds', 'farmland[moisture=7]'),
|
||||
('survival', 'carrots', 'carrot', 'farmland[moisture=7]'),
|
||||
('creative', 'dandelion', 'dandelion', 'dirt'),
|
||||
):
|
||||
player('command', command=f'gamemode {mode}')
|
||||
player('command', command='clear @s')
|
||||
player('command', command=f'item replace entity @s weapon.mainhand with minecraft:{item} 8')
|
||||
player('command', command=f'setblock {x} {y - 1} {z + 2} minecraft:{soil}')
|
||||
player('command', command=f'setblock {x} {y} {z + 2} minecraft:{block}')
|
||||
player.wait(5)
|
||||
observe(block)
|
||||
# Flowers' narrow outlines have a position-dependent offset.
|
||||
for dx in (0.0, -0.2, 0.2):
|
||||
player.raw('look-at', x + 0.5 + dx, y + (0.3 if block == 'dandelion' else 0.1), z + 2.5)
|
||||
target = player('looking_at').get('block') or {}
|
||||
if target.get('pos') == list(cell):
|
||||
break
|
||||
assert target.get('pos') == list(cell), f'{label} does not aim at {block}: {target}'
|
||||
player.raw('mouse', 'left', 'click')
|
||||
player.wait(5)
|
||||
observe('air')
|
||||
# Keep aiming at the supporting soil and use the held flower/seeds.
|
||||
player.raw('mouse', 'right', 'click')
|
||||
player.wait(3)
|
||||
observe(block)
|
||||
player.wait(20) # past the stale dig's five-tick destroy delay
|
||||
key = f'{label} {mode} {block}'
|
||||
seen[key] = [g.raw('block', *cell).get('block') for g in (host, guest)]
|
||||
player.shot(out, f'replant-{mode}-{block}')
|
||||
assert seen[key] == [f'minecraft:{block}'] * 2, f'{key}: {seen}'
|
||||
player('command', command=f'setblock {x} {y} {z + 2} minecraft:air')
|
||||
finally:
|
||||
host('command', command='gamerule random_tick_speed 3')
|
||||
return seen
|
||||
|
||||
|
||||
CHECKS += ['replant']
|
||||
CHECK_FNS['replant'] = check_replant
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user