Closing a menu puts a server's player's cursor stack back into their inventory

AbstractContainerMenu.removed hands the stack a closing player holds on the
cursor to placeItemBackInInventory (dropped only what doesn't fit, or for a
player who left), and broadcastChanges then empties the client's cursor. The
LAN host threw it out at the player's eyes instead, for the inventory and
every container, crafting, station, mount and merchant menu, and the client
kept showing a copy on its cursor (#1283).

The three ContainerClose arms now place it back through lan_place_back and
send the inventory, carried stack included.

tools/lan_e2e.py gains a cursor check: each player picks up a stack in their
inventory and closes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-23 23:04:53 +02:00
parent f96101cd47
commit c6ed3112e7
2 changed files with 53 additions and 12 deletions
+14 -12
View File
@@ -1051,20 +1051,14 @@ impl Game<'_> {
S::SetBeacon(p) => self.lan_station_beacon(host, conn, p.primary, p.secondary),
S::SelectTrade(p) => self.lan_select_trade(host, conn, p.item),
S::ContainerClose(p) if self.lan_merchant_closed(host, conn, Some(p.container)) => {
let g = &mut host.hub.guests[gi];
if let Some(c) = g.carried.take() {
self.drop_guest_items(host, gi, vec![c]);
}
self.guest_carried_back(host, gi);
}
S::ContainerClose(p)
if self.lan_crafting_closed(host, conn, Some(p.container))
|| self.lan_station_closed(host, conn, Some(p.container))
|| self.lan_mount_closed(host, conn, Some(p.container)) =>
{
let g = &mut host.hub.guests[gi];
if let Some(c) = g.carried.take() {
self.drop_guest_items(host, gi, vec![c]);
}
self.guest_carried_back(host, gi);
}
S::ContainerClick(p) => {
let rules = ItemRules(self.res.items());
@@ -1080,10 +1074,7 @@ impl Game<'_> {
self.guest_container_closed(host, conn);
}
host.hub.container_closed(conn, p.container);
let g = &mut host.hub.guests[gi];
if let Some(c) = g.carried.take() {
self.drop_guest_items(host, gi, vec![c]);
}
self.guest_carried_back(host, gi);
}
S::ChatCommand(c) => self.guest_chat_command(host, conn, &c.command),
S::ChatCommandSigned(p) => self.guest_signed_command(host, conn, p),
@@ -1230,6 +1221,17 @@ impl Game<'_> {
Some(out)
}
/// `AbstractContainerMenu.removed`: what a closing player held on the
/// cursor goes back into their inventory (`placeItemBackInInventory`,
/// dropped only if it doesn't fit), and their client's cursor empties
/// with the inventory it is sent.
fn guest_carried_back(&mut self, host: &mut LanHost, gi: usize) {
if let Some(c) = host.hub.guests[gi].carried.take() {
self.lan_place_back(host, gi, vec![c]);
host.hub.send_inventory(gi);
}
}
pub(super) fn drop_guest_items(&mut self, host: &LanHost, gi: usize, stacks: Vec<ItemStack>) {
let g = &host.hub.guests[gi];
let eye = [
+39
View File
@@ -212,6 +212,8 @@ address. The script then checks, from both sides, what a guest's game used to ge
(diving): their own client decides it (#1278, #1296, #1303).
- strikes: a bolt strikes the host and the guest standing in water and hurts them, and a cave
spider's bite poisons them (#1480, #1484).
- cursor: the host and the guest each close their inventory with a stack on the cursor: it
goes back into their inventory, none is thrown and the cursor is empty (#1283).
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).
@@ -4985,5 +4987,42 @@ CHECKS += ['strikes']
CHECK_FNS.update(strikes=check_strikes)
def check_cursor(host, guest, out):
"""Closing the inventory with a stack on the cursor puts it back into the player's inventory
(AbstractContainerMenu.removed, placeItemBackInInventory) and empties the cursor, for each
player: nothing is thrown out and no copy stays on the cursor (#1283)."""
seen = {}
try:
for game in (host, guest):
game('command', command='clear @s')
host('command', command='kill @e[type=minecraft:item]')
game('command', command='item replace entity @s hotbar.0 with minecraft:diamond 7')
game.wait(10)
game.raw('open-inventory')
game.raw('wait-for', 'screen', 'inventory', '--timeout', 10)
game.raw('click-slot', 0)
game.wait(5)
held = (game('inventory').get('carried') or {}).get('count')
game.raw('key', 'esc', 'tap')
game.wait(40)
inv = game('inventory')
seen[game.name] = {'held': held, 'carried': inv.get('carried'),
'client': inv['counts'].get('minecraft:diamond', 0),
'server': server_count(game, 'diamond'),
'thrown': len(game.raw('entities', 8, 'minecraft:item')['entities'])}
finally:
for game in (host, guest):
back_to_game(game)
game('command', command='clear @s')
host('command', command='kill @e[type=minecraft:item]')
for name, s in seen.items():
assert s == {'held': 7, 'carried': None, 'client': 7, 'server': 7, 'thrown': 0}, f'{name}: {seen}'
return seen
CHECKS += ['cursor']
CHECK_FNS.update(cursor=check_cursor)
if __name__ == '__main__':
main()