Merge feat/modbrowser-java-launcher (now with main) into feat/modbrowser-e2e-harness

No conflicts: carries the stack's merge of origin/main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-23 01:08:32 +02:00
179 changed files with 9170 additions and 5894 deletions
+46 -2
View File
@@ -10,7 +10,8 @@ the options scenario reads and sets options.txt values by key; the events scenar
states (wait-for) and reads the event log; the consume scenario eats and drinks consumables (a
golden apple, milk, honey, chorus fruit) and checks their effects, remainders and teleport; the
pick scenario middle-clicks slots (AbstractContainerScreen's cloning): a full stack in creative, from
the hotbar and from an item tab, and nothing in survival.
the hotbar and from an item tab, and nothing in survival; the suggestions scenario checks
slash-command Tab completion on single player's connected client after a fresh launch.
python3 tools/agent_control_e2e.py # both modes
python3 tools/agent_control_e2e.py --mode mcp # one of them
@@ -45,6 +46,7 @@ LOG_KINDS = ['oak_log', 'birch_log', 'spruce_log', 'jungle_log', 'acacia_log', '
'mangrove_log', 'cherry_log']
# Positional arguments of the commands the scenario uses, for the CLI.
POSITIONAL = {
'key': ['key', 'action'],
'goto': ['x', 'y', 'z'], 'break': ['x', 'y', 'z'], 'place': ['x', 'y', 'z'], 'block': ['x', 'y', 'z'],
'find_block': ['block', 'radius'], 'entities': ['radius', 'type'], 'click_slot': ['slot'],
'click_button': ['label'], 'type': ['text'], 'wait': ['ticks'], 'wait_ready': ['seconds'],
@@ -522,8 +524,50 @@ def pick_scenario(d, out):
return {'cloned': shown['item']}
def suggestions_scenario(d, out):
# Start from the title screen: single player's client joins through memory,
# without opening a server world and building its command registries.
d('click', id='singleplayer')
if 'game' not in widgets(d):
d('click', id='create-new-world')
d('type', field='name', replace=True, text='Suggestions')
d('click', id='game-mode') # survival -> hardcore -> creative (commands on)
d('click', id='game-mode')
d('type', field='seed', text='5')
d('click', id='world')
d('click', id='world-type') # superflat: this checks chat, without a spawn search
d('click', id='create-new-world')
d('wait_for', condition='loaded', timeout=400)
d('wait_ready', seconds=400)
cases = [
('/giv', '/give'),
('/fill ^', '/fill ^ ^'),
('/give @s diamond_sw', '/give @s minecraft:diamond_sword'),
('/setblock ~ ~ ~ diamond_blo', '/setblock ~ ~ ~ minecraft:diamond_block'),
('/fill ~ ~ ~ ~1 ~1 ~1 diamond_blo', '/fill ~ ~ ~ ~1 ~1 ~1 minecraft:diamond_block'),
('/setblock ~ ~ ~ oak_stairs[fa', '/setblock ~ ~ ~ oak_stairs[facing='),
('/clear @s diamond_sw', '/clear @s minecraft:diamond_sword'),
('/execute run give @s diamond_sw', '/execute run give @s minecraft:diamond_sword'),
]
for text, expected in cases:
d('key', key='t', action='tap')
d('type', text=text)
if text == '/give @s diamond_sw':
shot = d('screenshot', path=str((out / f'{d.name}-suggestions.png').resolve()))
if '_image' in shot:
(out / f'{d.name}-suggestions.png').write_bytes(shot['_image'])
d('key', key='tab', action='tap')
actual = d('screen')['chat_input']
assert actual == expected, (text, expected, actual)
d('key', key='esc', action='tap')
if d('screen')['screen'] == 'chat': # Escape first dismisses suggestions
d('key', key='esc', action='tap')
return {'completions': len(cases)}
SCENARIOS = {'survival': scenario, 'ui': ui_scenario, 'options': options_scenario, 'events': events_scenario,
'consume': consume_scenario, 'pick': pick_scenario}
'consume': consume_scenario, 'pick': pick_scenario, 'suggestions': suggestions_scenario}
def run(mode, ctl, out, resources, which='survival'):
+259 -2
View File
@@ -114,6 +114,17 @@ address. The script then checks, from both sides, what a guest's game used to ge
server's game time after the guest's game stalls for a few seconds (#848).
- growth: far from the host, the chunks around the guest tick (#890): water placed there flows
and wheat on farmland grows (random ticks), however the host runs its world.
- ladder: the guest climbs down ten blocks of ladder and lands unhurt: the server resets its fall
distance on a ladder every tick, as LivingEntity.handleOnClimbable does (#1255).
- boats: the host (single player, on its server thread or not) and the guest each right-click a
boat on water and ride it, paddle it forward (the other side sees it move), sneak out,
and break it with their fists (#1222).
- minecarts: the host and the guest each get into a minecart on rails, sneak out beside it, and break
it (#1222).
- frames: the host and the guest each put a diamond in an item frame and turn it, and put a
helmet on an armor stand and take it back (#1222).
- 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).
- flight: a player in creative double-taps jump and flies, stays up, and stops flying in survival:
the guest, and on the server thread the host's window too, take what may fly from the
server's abilities (ClientPacketListener.handlePlayerAbilities).
@@ -155,7 +166,7 @@ ROOT = Path(__file__).resolve().parents[1]
GUEST_NAME = 'Guest'
# The host plays single player on its server thread (--server-thread).
SERVER_THREAD = False
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight']
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'lightning']
class Game:
@@ -2279,6 +2290,252 @@ def check_flight(host, guest, out):
return seen
def check_ladder(host, guest, out):
"""#1255: climbing down a ladder doesn't hurt where the guest lands."""
x, y, z = (int(v // 1) for v in pos_of(guest))
lx, lz = x + 6, z
guest('command', command='gamemode survival')
guest('command', command=f'fill {lx - 2} {y} {lz - 2} {lx + 2} {y + 12} {lz + 2} minecraft:air')
guest('command', command=f'fill {lx - 2} {y - 1} {lz - 2} {lx + 2} {y - 1} {lz + 2} minecraft:stone')
guest('command', command=f'fill {lx} {y} {lz + 1} {lx} {y + 10} {lz + 1} minecraft:stone')
guest('command', command=f'fill {lx} {y} {lz} {lx} {y + 10} {lz} minecraft:ladder[facing=north]')
guest.wait(10)
try:
before = remote(guest)['health']
# No input on a ladder: the guest slides down at 0.15 a tick (LivingEntity.handleOnClimbable).
guest('command', command=f'tp @s {lx + 0.5} {y + 10} {lz + 0.4} 0 0')
for _ in range(40):
guest.wait(5)
if pos_of(guest)[1] < y + 0.01:
break
guest.wait(20)
landed, after = pos_of(guest), remote(guest)['health']
assert landed[1] < y + 0.01, f'the guest stayed on the ladder at {landed}'
assert after >= before, f'climbing down ten blocks of ladder took the guest from {before} to {after} health'
return {'landed': landed, 'health': after}
finally:
guest('command', command=f'fill {lx} {y} {lz} {lx} {y + 10} {lz + 1} minecraft:air')
guest('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}')
def apart(host, guest):
"""The host where it stands and the guest 12 blocks east, each on a stone floor with room
around: neither stands in the other's way (a ray from inside a player's box hits that player)."""
x, y, z = (int(v // 1) for v in pos_of(host))
spots = {}
for label, player, dx in (('host', host, 0), ('guest', guest, 12)):
px = x + dx
host('command', command=f'fill {px - 3} {y - 1} {z - 3} {px + 4} {y - 1} {z + 6} minecraft:stone')
host('command', command=f'fill {px - 3} {y} {z - 3} {px + 4} {y + 3} {z + 6} minecraft:air')
player('command', command=f'tp @s {px + 0.5} {y} {z + 0.5} 0 0')
spots[label] = (px, y, z)
host.wait(10)
guest.wait(10)
return spots
def board(player, kind, at):
"""Right-click the `kind` object near `at` and check `player` rides it."""
found = [o for o in player('status')['objects'] if o['kind'].endswith(kind)
and abs(o['position'][0] - at[0]) < 2 and abs(o['position'][2] - at[2]) < 2]
assert found, f'no {kind} near {at}'
vehicle = found[0]
vp = vehicle['position']
player.raw('look-at', f'{vp[0]:.2f}', f'{vp[1] + 0.3:.2f}', f'{vp[2]:.2f}')
player.raw('mouse', 'right', 'click')
player.wait(10)
riding = player('status').get('riding')
assert riding == vehicle['id'], f'right-clicking the {kind} {vehicle["id"]}: riding {riding}'
return vehicle
def leave_vehicle(player, kind):
player.raw('key', 'shift', 'down')
player.wait(10)
player.raw('key', 'shift', 'up')
player.wait(10)
riding = player('status').get('riding')
assert riding is None, f'sneaking out of the {kind}: riding {riding}'
def break_vehicle(player, vehicle_id, kind):
"""Hit it with fists until it breaks: VehicleEntity.tick takes 1 off its damage every tick."""
for _ in range(10):
here = [o for o in player('status')['objects'] if o['id'] == vehicle_id]
if not here:
return
vp = here[0]['position']
player.raw('look-at', f'{vp[0]:.2f}', f'{vp[1] + 0.3:.2f}', f'{vp[2]:.2f}')
player.raw('mouse', 'left', 'click')
player.wait(2)
raise AssertionError(f'ten hits left the {kind} in place')
def check_boats(host, guest, out):
"""#1222: the host (single player, on its server thread or not) and the guest each board a boat
on water with a right click, paddle it forward (the other side sees it move), sneak out, and
break it with their fists."""
result = {}
spots = apart(host, guest)
for label, player, other in (('host', host, guest), ('guest', guest, host)):
x, y, z = spots[label]
bx = x + 3
player('command', command='gamemode survival')
# A pool ten blocks long in a stone basin (the world may float), with a path beside it to
# walk back to the boat.
player('command', command=f'fill {bx - 3} {y} {z - 2} {bx + 2} {y + 3} {z + 10} minecraft:air')
player('command', command=f'fill {bx - 3} {y - 2} {z - 2} {bx + 2} {y - 1} {z + 10} minecraft:stone')
player('command', command=f'fill {bx - 1} {y - 1} {z - 1} {bx + 1} {y - 1} {z + 9} minecraft:water')
player('command', command=f'summon minecraft:oak_boat {bx + 0.5} {y - 0.1} {z + 0.5}')
player.wait(30)
try:
boat = board(player, 'oak_boat', (bx + 0.5, y, z + 0.5))
start = boat['position']
# The summoned boat faces south: forward paddles it along the pool.
player.raw('key', 'w', 'down')
player.wait(30)
player.raw('key', 'w', 'up')
player.wait(20)
mine = [o for o in player('status')['objects'] if o['id'] == boat['id']]
assert mine, f'the {label} lost its boat'
moved = math.dist(start, mine[0]['position'])
assert moved > 0.5, f'paddling forward moved the {label}\'s boat {moved:.2f} blocks'
# The other side sees the boat where its rider took it (the server accepted its moves).
theirs = [o for o in objects_near(other, mine[0]['position'], 'objects')
if o['kind'].endswith('oak_boat')]
assert theirs, f'the other side sees no boat near the {label}\'s'
far = min(math.dist(o['position'], mine[0]['position']) for o in theirs)
assert far < 1.0, f'the other side sees the {label}\'s boat {far:.2f} blocks off'
leave_vehicle(player, 'boat')
player('command', command=f'tp @s {bx - 1.5} {y} {mine[0]["position"][2]:.2f}')
player.wait(5)
break_vehicle(player, boat['id'], 'boat')
result[label] = {'boat': boat['id'], 'paddled': round(moved, 2), 'broken': True}
finally:
player('command', command=f'kill @e[type=minecraft:oak_boat,x={bx},y={y},z={z + 4},distance=..10]')
player('command', command=f'fill {bx - 1} {y - 1} {z - 1} {bx + 1} {y - 1} {z + 9} minecraft:stone')
player('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}')
player.wait(5)
return result
def check_minecarts(host, guest, out):
"""#1222: the host and the guest each get into a minecart on rails with a right click, sneak out
beside it, and break it with their fists."""
result = {}
spots = apart(host, guest)
for label, player in (('host', host), ('guest', guest)):
x, y, z = spots[label]
cx = x + 3
player('command', command='gamemode survival')
player('command', command=f'fill {cx - 2} {y} {z - 2} {cx + 2} {y + 3} {z + 6} minecraft:air')
player('command', command=f'fill {cx - 2} {y - 1} {z - 2} {cx + 2} {y - 1} {z + 6} minecraft:stone')
player('command', command=f'fill {cx} {y} {z} {cx} {y} {z + 4} minecraft:rail')
player('command', command=f'summon minecraft:minecart {cx + 0.5} {y} {z + 0.5}')
player.wait(30)
try:
cart = board(player, 'minecart', (cx + 0.5, y, z + 0.5))
seated = pos_of(player)
assert abs(seated[0] - (cx + 0.5)) < 0.6, f'the {label} sits at {seated}, not in the cart'
leave_vehicle(player, 'minecart')
out_at = pos_of(player)
assert math.dist(out_at, seated) > 0.3, f'the {label} stayed in its seat at {out_at}'
player.wait(5)
break_vehicle(player, cart['id'], 'minecart')
result[label] = {'cart': cart['id'], 'out_at': [round(v, 2) for v in out_at], 'broken': True}
finally:
player('command', command=f'kill @e[type=minecraft:minecart,x={cx},y={y},z={z},distance=..8]')
player('command', command=f'kill @e[type=minecraft:item,x={cx},y={y},z={z},distance=..8]')
player('command', command=f'fill {cx} {y} {z} {cx} {y} {z + 4} minecraft:air')
player('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}')
player.wait(5)
return result
def check_frames(host, guest, out):
"""#1222: the host and the guest each put a diamond in an item frame and turn it, and put a
helmet on an armor stand and take it back, with right clicks."""
result = {}
spots = apart(host, guest)
for label, player, other in (('host', host, guest), ('guest', guest, host)):
x, y, z = spots[label]
player('command', command='gamemode survival')
# Within a survival player's 3 blocks of reach: a frame on a wall, an armor stand beside it.
player('command', command=f'fill {x - 2} {y} {z + 1} {x + 2} {y + 2} {z + 2} minecraft:air')
player('command', command=f'fill {x - 2} {y} {z + 3} {x + 2} {y + 2} {z + 3} minecraft:stone')
player('command', command=f'summon minecraft:item_frame {x + 0.5} {y + 1.5} {z + 2.97} '
f'{{block_pos:[I;{x},{y + 1},{z + 2}],Facing:2b}}')
player('command', command=f'summon minecraft:armor_stand {x - 1.5} {y} {z + 1.5}')
player('command', command='clear @s')
player('command', command='item replace entity @s weapon.mainhand with minecraft:diamond')
player.wait(30)
try:
frame = [o for o in player('status')['objects'] if o['kind'].endswith('item_frame')
and o['position'] == [x, y + 1, z + 2]]
assert frame, f'the {label} sees no item frame at {[x, y + 1, z + 2]}'
player.raw('look-at', f'{x + 0.5:.2f}', f'{y + 1.5:.2f}', f'{z + 2.95:.2f}')
player.raw('mouse', 'right', 'click')
player.wait(10)
player.raw('mouse', 'right', 'click')
player.wait(10)
frame = [o for o in player('status')['objects'] if o['id'] == frame[0]['id']][0]
assert frame['item'] == 'minecraft:diamond', f'the {label}\'s frame holds {frame["item"]}'
assert frame['rotation'] == 1, f'the {label}\'s frame turned to {frame["rotation"]}'
theirs = [o for o in other('status')['objects'] if o['kind'].endswith('item_frame')
and o['position'] == [x, y + 1, z + 2]]
assert theirs and theirs[0]['item'] == 'minecraft:diamond' and theirs[0]['rotation'] == 1, \
f'the other side sees the {label}\'s frame as {theirs}'
player('command', command='item replace entity @s weapon.mainhand with minecraft:iron_helmet')
player.wait(5)
stand = [o for o in player('status')['objects'] if o['kind'] == 'minecraft:armor_stand'
and abs(o['position'][0] - (x - 1.5)) < 0.5 and abs(o['position'][2] - (z + 1.5)) < 0.5]
assert stand, f'the {label} sees no armor stand'
player.raw('look-at', f'{x - 1.5:.2f}', f'{y + 1.7:.2f}', f'{z + 1.5:.2f}')
player.raw('mouse', 'right', 'click')
player.wait(10)
worn = [o for o in player('status')['objects'] if o['id'] == stand[0]['id']][0]['equipment']
assert 'minecraft:iron_helmet' in worn, f'the {label}\'s armor stand wears {worn}'
player.raw('look-at', f'{x - 1.5:.2f}', f'{y + 1.7:.2f}', f'{z + 1.5:.2f}')
player.raw('mouse', 'right', 'click')
player.wait(10)
worn = [o for o in player('status')['objects'] if o['id'] == stand[0]['id']][0]['equipment']
assert 'minecraft:iron_helmet' not in worn, f'taking the helmet back left {worn}'
result[label] = {'frame': 'diamond, turned', 'stand': 'helmet on and off'}
finally:
player('command', command=f'kill @e[type=!minecraft:player,x={x - 3},y={y - 1},z={z},dx=6,dy=4,dz=6]')
player('command', command=f'fill {x - 2} {y} {z + 3} {x + 2} {y + 2} {z + 3} minecraft:air')
player('command', command='clear @s')
return result
def check_lightning(host, guest, out):
"""A bolt summoned beside each player: both sides get the bolt entity and flash the sky (the
host's window too on its server thread, FEATURES 4z(f))."""
result = {}
for label, player in (('host', host), ('guest', guest)):
x, y, z = (int(v // 1) for v in pos_of(player))
before = {g.name: g('status')['lightning'] for g in (host, guest)}
# No fire where it strikes: on stone with nothing around.
player('command', command=f'fill {x + 4} {y - 1} {z - 2} {x + 8} {y - 1} {z + 2} minecraft:stone')
player('command', command=f'fill {x + 4} {y} {z - 2} {x + 8} {y + 3} {z + 2} minecraft:air')
player('command', command=f'summon minecraft:lightning_bolt {x + 6.5} {y} {z + 0.5}')
seen = {}
for _ in range(40):
player.wait(1)
seen = {g.name: g('status')['lightning'] for g in (host, guest)}
if all(seen[n]['struck'] > before[n]['struck'] and seen[n]['flashes'] > before[n]['flashes']
for n in seen):
break
player('command', command=f'fill {x + 4} {y} {z - 2} {x + 8} {y + 3} {z + 2} minecraft:air')
for n in seen:
assert seen[n]['struck'] > before[n]['struck'], f"{label}'s bolt: the {n} got no bolt ({seen[n]})"
assert seen[n]['flashes'] > before[n]['flashes'], f"{label}'s bolt: the {n}'s sky didn't flash ({seen[n]})"
result[label] = {n: {'bolts': seen[n]['struck'] - before[n]['struck'],
'flashes': seen[n]['flashes'] - before[n]['flashes']} for n in seen}
return result
def check_growth(host, guest, out):
"""Block ticks near a guest 1000 blocks from the host: only the guest's tickets tick them."""
x0, y0, z0 = pos_of(guest)
@@ -2591,7 +2848,7 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
'xp': check_xp, 'objects': check_objects, 'projectiles': check_projectiles, 'blast': check_blast,
'light': check_light, 'plates': check_plates,
'swings': check_swings, 'cracks': check_cracks,
'time': check_time, 'growth': check_growth, 'flight': check_flight, 'fireball': check_fireball, 'deflect': check_deflect, 'barter': check_barter, 'worn': check_worn, 'kills': check_kills, 'arrows': check_arrows, 'predict': check_predict}
'time': check_time, 'growth': check_growth, 'flight': check_flight, 'fireball': check_fireball, 'deflect': check_deflect, 'barter': check_barter, 'worn': check_worn, 'kills': check_kills, 'arrows': check_arrows, 'predict': check_predict, 'ladder': check_ladder, 'boats': check_boats, 'minecarts': check_minecarts, 'frames': check_frames, 'lightning': check_lightning}
def run(ctl, out, resources, checks):
+10
View File
@@ -69,6 +69,16 @@ def cases(count):
'history': rng.sample(HISTORY, rng.randint(0, len(HISTORY))), 'autoSuggest': rng.random() < 0.85,
'chatOnly': rng.random() < 0.7, 'opacity': rng.choice([0.0, 0.5, 1.0]), 'actions': actions,
'mouse': list(mouse), 'blink': rng.choice([0, 100, 400, 650])})
# Always exercise registry-backed suggestions and their replacement ranges,
# before and after Tab, including the redirect through execute's root.
for text in ['/give @s diamond_sw', '/setblock ~ ~ ~ sto', '/fill ~ ~ ~ ~1 ~1 ~1 sto',
'/setblock ~ ~ ~ oak_stairs[fa', '/clear @s diamond_sw',
'/execute run give @s diamond_sw', '/fill ']:
for keys in [[], ['tab'], ['tab', 'tab', 'shift+tab']]:
out.append({'width': 640, 'height': 360, 'initial': '', 'history': [], 'autoSuggest': True,
'chatOnly': True, 'opacity': 0.5, 'mouse': [0, 0], 'blink': 0,
'actions': [{'type': 'type', 'text': text}]
+ [{'type': 'key', 'key': key} for key in keys]})
return out
+2 -1
View File
@@ -67,6 +67,7 @@ if __name__ == '__main__':
'firework-tooltip-parity', 'VanillaFireworkTooltipOracle', 'firework_tooltip_fixture', cases,
'Firework rocket and star tooltip lines: flight duration, explosions (counted runs), colours, fade, trail, '
'twinkle, defaults and tooltip_display',
sources=[lab.ROOT / 'crates/horizon-client/src/item_tooltip.rs', lab.ROOT / 'crates/horizon-client/src/item_data.rs',
sources=[lab.ROOT / 'crates/horizon-client/src/enchant.rs',
lab.ROOT / 'crates/horizon-client/src/item_tooltip.rs', lab.ROOT / 'crates/horizon-client/src/item_data.rs',
lab.ROOT / 'crates/horizon-client/src/particles.rs'],
expected_lines=COUNT)
+6
View File
@@ -69,6 +69,12 @@ def block_hit(pos, face=1):
def scenarios():
stone = {TARGETS[0]: 'minecraft:stone', TARGETS[1]: 'minecraft:dirt', TARGETS[2]: 'minecraft:glass'}
# Consecutive instant survival breaks have no destroy delay. Cover both
# zero hardness and a shovel with haste reaching one-tick destroy progress.
for block, main, haste in [('minecraft:short_grass', None, None),
('minecraft:dirt', ['minecraft:diamond_shovel', 1], 9)]:
steps = [step(block_hit(p), ac=int(i == 0), ad=True) for i, p in enumerate(TARGETS)]
yield case(steps + [step()] * 6, main=main, blocks={p: block for p in TARGETS}, haste=haste)
for creative in (False, True):
for main in ITEMS:
# Hold attack on blocks until they break, then on the air behind.
+15 -3
View File
@@ -15,6 +15,9 @@ is off: nothing leaves the machine.
python3 tools/test_friends.py --client target/fast/horizon-client --relay target/fast/horizon-relay
`--server-thread` runs the host's world on its integrated server's own
thread (the window is a client of it, as Open to LAN publishes it).
`--role host|guest` runs one side only (two machines, e.g. over a tailnet):
the host prints the code, the guest takes it with `--code` (`--relay-url`
for a relay elsewhere, `--path relay` to force it). Needs a display on Linux
@@ -86,8 +89,12 @@ class Game:
# Extra words before and after the client (`--xvfb`, `--offscreen`).
prefix = []
extra = []
# The host's world on its server thread (`--server-thread`), else in the window.
server_thread = False
def __init__(self, client, resources, work, name, env):
# Either way explicitly, whatever the game's default.
env = dict(env, HORIZON_SERVER_THREAD='1' if Game.server_thread and name == 'host' else '0')
self.home = work / name
self.home.mkdir()
self.endpoint = self.home / 'c.sock'
@@ -155,7 +162,9 @@ def play_together(host, guest, name, round_index):
# The host moves; the guest sees the host's player there.
hp = host('status')['player']['position']
target = [hp[0] + 3.0, hp[1], hp[2] + 1.0]
host(f'tp {target[0]} {target[1]} {target[2]}')
# The /tp command, not the control socket's local move: on the server thread the window is a
# client, and its server has the last word on where the host stands.
host(f'command tp @s {target[0]} {target[1]} {target[2]}')
guest.wait('status', lambda v: any(math.dist(p, target) < 0.6 for p in v['server']['player_positions']), 20,
'host movement on the guest')
# A block the host places, which the guest sees and then breaks.
@@ -163,8 +172,9 @@ def play_together(host, guest, name, round_index):
feet = [math.floor(gp[0]), math.floor(gp[1]), math.floor(gp[2])]
block = [feet[0] + 2, feet[1] + 1, feet[2]]
# Clear the line of sight (the test terrain has hills), then the block at eye level.
host(f'fill {feet[0] + 1} {feet[1]} {feet[2]} {feet[0] + 1} {feet[1] + 2} {feet[2]} minecraft:air')
host(f'setblock {block[0]} {block[1]} {block[2]} minecraft:gold_block')
# As commands, for the same reason as the /tp above.
host(f'command fill {feet[0] + 1} {feet[1]} {feet[2]} {feet[0] + 1} {feet[1] + 2} {feet[2]} minecraft:air')
host(f'command setblock {block[0]} {block[1]} {block[2]} minecraft:gold_block')
guest.wait(f'getblock {block[0]} {block[1]} {block[2]}', lambda v: v['block'] == 'minecraft:gold_block', 20,
'the host block on the guest')
eye = [gp[0], gp[1] + 1.62, gp[2]]
@@ -343,10 +353,12 @@ def main():
parser.add_argument('--hold', type=float, default=0, help='guest: stay this many seconds before leaving')
parser.add_argument('--baseline', action='store_true', help='first run the same checks over plain LAN')
parser.add_argument('--offscreen', action='store_true', help='run the games without a window')
parser.add_argument('--server-thread', action='store_true', help="the host's world on its server thread")
parser.add_argument('--xvfb', action='store_true', help='run the games under xvfb-run (headless Linux)')
args = parser.parse_args()
Game.prefix = ['xvfb-run', '-a'] if args.xvfb else []
Game.extra = ['--offscreen'] if args.offscreen else []
Game.server_thread = args.server_thread
args.client, args.resources = args.client.resolve(), args.resources.resolve()
# Short: Unix socket paths are limited to about 100 bytes.
with tempfile.TemporaryDirectory(prefix='hzf-', dir='/tmp') as directory:
+6 -4
View File
@@ -2,10 +2,12 @@
"""Compare selected-slot drops with Minecraft.handleKeybinds in all four game modes.
The oracle invokes the unmodified native key handler, consuming real drop-key
clicks. Its controlled dropItem callback removes from the real player Inventory;
other keys are idle and execution stops at the following item-use boundary.
clicks, and MultiPlayerGameMode.dropItem's real prediction and swing dispatch.
Other keys are idle and execution stops at the following item-use boundary.
Checks Q/Ctrl+Q, slots 0/8, empty/single/partial/full stacks and repeated drops.
Packet delivery, item entities, swing animation and statistics are outside scope.
Checks swing attempts and drop packet counts, including packets without swings
for empty slots. Packet delivery, animation ticks, item entities and statistics
are outside scope.
"""
import os
import subprocess
@@ -35,7 +37,7 @@ def main():
subprocess.run(['cargo', 'run', '--quiet', '-p', 'horizon-client', '--example',
'held_drop_fixture'], cwd=lab.ROOT, stdout=out, check=True)
matched = base.compare(build / 'vanilla.txt', build / 'rust.txt')
print(f'Held drop parity passed: {matched} selected-stack/drop-count snapshots match vanilla')
print(f'Held drop parity passed: {matched} inventory/drop/swing/packet snapshots match vanilla')
if __name__ == '__main__':
+1 -1
View File
@@ -113,7 +113,7 @@ def start_client(client, resources, home, endpoint, log, *extra):
str(client), '--resources', str(resources), '--render-distance', '2',
'--test-terrain', '--control-socket', str(endpoint), '--timeout-seconds', '180', *extra,
], cwd=home, env=dict(os.environ, HORIZON_HOME=str(home), HORIZON_NO_AUDIO='1',
HORIZON_MENU_STYLE='classic', HORIZON_PLAYER_NAME=''),
HORIZON_PLAYER_NAME=''),
stdout=log, stderr=subprocess.STDOUT)
+17 -1
View File
@@ -68,6 +68,22 @@ def generate(resources, count, seed):
return cases
def obstruction_cases(resources):
"""Placement failures must not predict a hand swing.
Exercise BlockItem.canPlace's entity-obstruction gate with the same
otherwise valid placements, including partial shapes and two-block items.
"""
facts = json.loads((resources / 'facts.json').read_text())
states = {s[0]: i for i, s in reversed(list(enumerate(facts['states'])))}
stone = states['minecraft:stone']
for item in ['minecraft:stone', 'minecraft:oak_slab', 'minecraft:oak_stairs',
'minecraft:oak_door', 'minecraft:torch']:
for obstructed in [False, True]:
yield dict(seed=0, item=item, pos=[0, 0, 0], face=1, hit=[0.5, 1.0, 0.5],
yaw=0, pitch=45, sneak=False, cells=[[0, 0, 0, stone]], obstructed=obstructed)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--count', type=int, default=20000)
@@ -77,7 +93,7 @@ def main():
resources = lab.LOCAL / 'horizon-client' / lock['minecraft']['version']
work = lab.LOCAL / 'level-place-parity'
work.mkdir(parents=True, exist_ok=True)
cases = generate(resources, args.count, args.seed)
cases = list(obstruction_cases(resources)) + generate(resources, args.count, args.seed)
(work / 'cases.jsonl').write_text(''.join(json.dumps(case) + '\n' for case in cases))
classes = work / 'classes'
classes.mkdir(exist_ok=True)
+2 -2
View File
@@ -12,8 +12,8 @@ def make_input(build):
rng = random.Random(71)
cases = []
for kind in (0, 1):
for ticks in (0, 1, 511, 512, 131071, 131072, 24000 * 37 + 5, 9_000_000_123):
for x, z in ((0, 0), (1, 0), (0, -1), (3, 7), (-10, 10), (10, -10), (-4, -9), (1_000_003, -2_000_011)):
for ticks in (-9223372036854775808, -1, 0, 1, 511, 512, 131071, 131072, 24000 * 37 + 5, 9_000_000_123, 9223372036854775807):
for x, z in ((0, 0), (1, 0), (0, -1), (3, 7), (-10, 10), (10, -10), (-4, -9), (1_000_003, -2_000_011), (30_000_000, -30_000_000), (2_147_483_631, -2_147_483_632)):
for bottom, top in ((60, 80), (64, 65), (-64, -44), (300, 310)):
light = (rng.randrange(16) << 4) | (rng.randrange(16) << 20)
partial = rng.choice(("0.0", "0.5", "0.999", f"{rng.random():.6f}"))