diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index a229cbdc9..2e551f440 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -1082,6 +1082,8 @@ impl Game<'_> { self.for_player(t, |g| g.teleport_to(Target::Player, pos, rotation)); } Target::Player => { + // ServerPlayer.teleport: removeVehicle before placing the player. + self.stop_riding(); if let Some(p) = self.player.as_mut() { p.position = v; p.velocity = Vec3::new(0.0, 0.0, 0.0); diff --git a/tools/command_exec_corpus.py b/tools/command_exec_corpus.py index 2b2a0afd1..05a245bbc 100644 --- a/tools/command_exec_corpus.py +++ b/tools/command_exec_corpus.py @@ -286,6 +286,36 @@ def entities(): ] +def riding_teleport(): + """Player teleports remove the vehicle, leave it behind and keep the destination (#1473).""" + horse = '@e[tag=tp_horse,limit=1]' + operations = setup( + '/summon minecraft:horse 4.5 220 4.5 {Tame:1b,NoAI:1b,NoGravity:1b,Tags:["tp_horse"]}', + '/summon minecraft:marker 8.5 220 0.5 {Tags:["tp_destination"]}', + ) + for teleport in ('/tp @s 8.5 220 0.5', '/teleport @s ~4 220 ~-4', + '/tp @s @e[tag=tp_destination,limit=1]'): + operations += [ + *setup('/tp @s 4.5 220 4.5'), + cmd(f'/ride @s mount {horse}'), + cmd('/execute on vehicle run say mounted'), + # An invalid destination must not dismount the player. + cmd('/tp @s 30000000 220 0'), + cmd('/execute on vehicle run say still mounted'), + cmd(teleport), + cmd('/execute on vehicle run say still riding after teleport'), + cmd('/data get entity @s Pos'), + cmd(f'/data get entity {horse} Pos'), + {'op': 'tick', 'n': 60}, + cmd('/execute on vehicle run say still riding after ticks'), + cmd('/data get entity @s Pos'), + cmd(f'/data get entity {horse} Pos'), + cmd('/ride @s dismount'), + ] + return operations + setup('/kill @e[tag=tp_horse]', '/kill @e[tag=tp_destination]', + '/tp @s 8.5 230 8.5 0 0') + + def scores(): return [ cmd('/scoreboard objectives add harness dummy'), @@ -975,6 +1005,7 @@ def groups(): ('player state', player_state()), ('blocks and border', world_blocks()), ('entities', entities()), + ('riding teleport', riding_teleport()), ('scores, teams and bossbars', scores()), ('execute', execute()), ('levels', levels()), diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index a0fe0e181..29dd63952 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -156,6 +156,9 @@ address. The script then checks, from both sides, what a guest's game used to ge - riding: the host and the guest each saddle and ride a horse (walk, jump), a pig and a strider (with their sticks), a camel and a donkey, sit on a llama and fly a happy ghast, and get off by sneaking; the other side sees the animal move. +- riding_teleport: the host and the guest each /tp through chat while riding a horse; after 60 + ticks each stays dismounted at the destination and both sides see the horse left + behind. The host also teleports a mounted guest by name. - lightning: a bolt summoned beside the host, then the guest: both sides get the bolt and flash the sky (on its server thread the host's window is a client of it too). - drops: an item lies where the host, then the guest, places a block: it comes out of the block @@ -5499,6 +5502,70 @@ CHECKS += ['villagers'] CHECK_FNS.update(villagers=check_villagers) +def check_riding_teleport(host, guest, out): + """#1473: a chat /tp dismounts each player and leaves the horse behind in both modes; + teleporting another player exercises the guest-target command path too.""" + spots = apart(host, guest) + result = {} + for label, player, source in (('host', host, None), ('guest', guest, None), + ('guest-targeted', guest, host)): + x, y, z = spots['host' if player is host else 'guest'] + horse_at = (x + 0.5, y, z + 2.5) + destination = (x + 3.5, y, z + 5.5) + tag = 'tp_horse' + try: + player('command', command='clear @s') + player('command', command='gamemode survival') + player('command', command=f'tp @s {x + 0.5} {y} {z + 0.5} 0 0') + player('command', command='item replace entity @s weapon.mainhand with minecraft:saddle') + player('command', command=f'summon minecraft:horse {horse_at[0]} {y} {horse_at[2]} ' + f'{{Tame:1b,NoAI:1b,NoGravity:1b,Tags:["{tag}"]}}') + player.wait(5) + horses = [m for m in player.raw('mobs', 16)['near'] + if m['kind'] == 'minecraft:horse' and m['health'] > 0] + horse = next((m for m in horses if math.dist(m['pos'], horse_at) < 0.1), None) + assert horse, f'{label}: no live horse at {horse_at}: {horses}' + player.raw('look-at', horse_at[0], y + 0.8, horse_at[2]) + player.raw('mouse', 'right', 'click') + player.wait(5) + player('command', command='item replace entity @s weapon.mainhand with minecraft:air') + player.wait(2) + player.raw('mouse', 'right', 'click') + player.wait(5) + assert player('status').get('riding') == horse['id'], f'{label}: not riding the horse' + player.shot(out, f'riding-tp-{label}-before') + coordinates = ' '.join(map(str, destination)) + if source is None: + player.raw('key', 't', 'tap') + player.raw('type', f'/tp @s {coordinates}') + player.raw('key', 'enter', 'tap') + else: + source('command', command=f'tp {GUEST_NAME} {coordinates}') + player.wait(60) + player.shot(out, f'riding-tp-{label}-after') + seen = {'riding': player('status').get('riding'), 'client': pos_of(player), + 'server': server_player(host, player)['position'], + 'horse': mob_seen(player, horse['id'])['pos'], + 'other_horse': mob_seen(guest if player is host else host, horse['id'])['pos']} + assert seen['riding'] is None, f'{label}: still mounted after /tp: {seen}' + assert all(math.dist(seen[side], destination) < 0.01 for side in ('client', 'server')), \ + f'{label}: /tp did not keep its destination after 60 ticks: {seen}' + assert all(math.dist(seen[side], horse_at) < 0.01 for side in ('horse', 'other_horse')), \ + f'{label}: /tp moved the horse: {seen}' + result[label] = seen + finally: + back_to_game(player) + player('command', command=f'kill @e[tag={tag}]') + player('command', command=f'tp @s {x + 0.5} {y} {z + 0.5} 0 0') + # The next case uses this spot again: let the previous horse's death animation finish. + player.wait(25) + return result + + +CHECKS += ['riding_teleport'] +CHECK_FNS.update(riding_teleport=check_riding_teleport) + + 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