Merge pull request #1513 from ludovic111/fix/st-cursor-close

This commit is contained in:
Ludovic Marie
2026-10-24 07:26:18 +02:00
committed by GitHub
2 changed files with 53 additions and 12 deletions
+14 -12
View File
@@ -1059,20 +1059,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());
@@ -1088,10 +1082,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),
@@ -1238,6 +1229,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
@@ -220,6 +220,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).
@@ -5138,6 +5140,43 @@ 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)
def check_digging(host, guest, out):
"""The server breaks a block a player digs only once that player's client is done
(ServerPlayerGameMode: STOP_DESTROY_BLOCK, or the delayed destroy), never on its own count, so