From 489b5a4ffa038341dccc66c8d2bfa27994007068 Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Sun, 25 Oct 2026 03:31:36 +0000 Subject: [PATCH] Trading: keep Hero discounts for server players Preserve the Hero effect captured by the guest's merchant session and cover discounted prices and payments for both single-player modes. Fixes #1365 Co-Authored-By: OpenCode (gpt-6.1-sol) --- crates/horizon-client/src/game/lan_trading.rs | 5 +- tools/lan_e2e.py | 72 +++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/game/lan_trading.rs b/crates/horizon-client/src/game/lan_trading.rs index 83aafecc2..1bec9809d 100644 --- a/crates/horizon-client/src/game/lan_trading.rs +++ b/crates/horizon-client/src/game/lan_trading.rs @@ -48,10 +48,9 @@ impl Game<'_> { if let Some(id) = state.mob && state.session.villager { - // startTrading with the guest's reputation (their effects are - // not modelled on the host: no Hero of the Village). + // startTrading with the guest's reputation. The session already + // captured their Hero effect while they acted as the player. state.session.reputation = self.villager_reputation_of(id, uuid); - state.session.hero = None; state.session.update_special_prices(); } let title = self.merchant_display_name(&state); diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index a0fe0e181..9a6576888 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -228,6 +228,8 @@ address. The script then checks, from both sides, what a guest's game used to ge - villagers: the guest sees each villager's and zombie villager's type, profession and level as the host has them, and an unemployed villager that takes a composter becomes a farmer on the guest too (the guest used to draw every villager as an unemployed plains one). +- hero-trading: the host and the guest each trade 20 wheat for an emerald, paying 14 with Hero I + and 12 with Hero III; clearing the effect restores the ordinary price (#1365). - 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). @@ -5440,6 +5442,76 @@ CHECKS += ['knockback'] CHECK_FNS.update(knockback=check_knockback) +def check_hero_trading(host, guest, out): + """Villager.updateSpecialPrices keeps the trading player's Hero effect: the offer sent to the + client and the server's payment consumption agree, independently of the other player's effect.""" + x, y, z = (int(v // 1) for v in pos_of(host)) + tag = 'hero_trade' + seen = {} + cases = [('ordinary', None, 20), ('hero-i', 0, 14), ('hero-iii', 2, 12), ('cleared', None, 20)] + try: + host('command', command=f'fill {x - 4} {y - 1} {z - 2} {x + 4} {y - 1} {z + 2} minecraft:stone') + host('command', command=f'fill {x - 4} {y} {z - 2} {x + 4} {y + 3} {z + 2} minecraft:air') + for game, other in ((host, guest), (guest, host)): + back_to_game(game) + back_to_game(other) + other('command', command='effect clear @s') + other('command', command='effect give @s minecraft:hero_of_the_village 600 4 true') + other('command', command=f'tp @s {x - 3.5} {y} {z + 0.5}') + game('command', command='gamemode survival') + game('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}') + for label, amplifier, price in cases: + game('command', command='effect clear @s') + if amplifier is not None: + game('command', command=f'effect give @s minecraft:hero_of_the_village 600 {amplifier} true') + game('command', command='clear @s') + game('command', command='give @s minecraft:wheat 20') + # A fresh, fixed offer avoids reputation, demand and level-ups between cases. + host('command', command=f'summon minecraft:villager {x + 2.5} {y} {z + 0.5} {{Tags:["{tag}"],' + 'NoAI:1b,PersistenceRequired:1b,Xp:1,VillagerData:{type:"minecraft:plains",' + 'profession:"minecraft:farmer",level:1},Offers:{Recipes:[{buy:{id:"minecraft:wheat",count:20},' + 'sell:{id:"minecraft:emerald",count:1},maxUses:16,uses:0,xp:0,priceMultiplier:0f,demand:0}]}}') + game.wait(20) + villager = next(e['id'] for e in game.raw('entities', 8, 'minecraft:villager')['entities'] + if math.dist(e['pos'], [x + 2.5, y, z + 0.5]) < 0.5) + game.raw('interact-entity', villager) + game.raw('wait-for', 'screen', 'station', '--timeout', 10) + assert game('screen')['station'] == 'Merchant', f'{game.name}-{label}: no merchant screen' + # The first offer button is 50 pixels left of the usual menu origin. Selecting it + # sends SelectTrade on a client; taking the result uses the authoritative menu. + game.raw('click-gui', -1, 28) + game.wait(10) + assert station_slots(game).get(650) == ('minecraft:emerald', 1), f'{game.name}-{label}: no result' + game.shot(out, f'hero-trading-{label}') + game.raw('click-slot', 650, 'shift') + game.wait(10) + game.raw('key', 'esc', 'tap') + game.wait(10) + offer = server_reply(game, f'data get entity @e[type=minecraft:villager,tag={tag},limit=1] ' + 'Offers.Recipes[0]', 'following entity data') + special = re.search(r'specialPrice"?\s*:\s*(-?\d+)', offer) + case = {'price': 20 + (int(special[1]) if special else 0), + 'server': {item: server_count(game, item) for item in ('wheat', 'emerald')}, + 'hero': 'hero_of_the_village' in effect_ids(game)} + seen[f'{game.name}-{label}'] = case + want = {'price': price, 'server': {'wheat': 20 - price, 'emerald': 1}, + 'hero': amplifier is not None} + assert case == want, f'{game.name}-{label}: expected {want}, got {case}' + host('command', command=f'kill @e[tag={tag}]') + game.wait(5) + finally: + for game in (host, guest): + back_to_game(game) + game('command', command='effect clear @s') + game('command', command='clear @s') + host('command', command=f'kill @e[tag={tag}]') + return seen + + +CHECKS += ['hero-trading'] +CHECK_FNS.update({'hero-trading': check_hero_trading}) + + def check_villagers(host, guest, out): """Villager.DATA_VILLAGER_DATA and ZombieVillager's reach the guest: summoned villagers show their type, profession and level, and an unemployed villager that takes a composter placed