LAN guest: a use packet uses the item alone

ServerGamePacketListenerImpl.handleUseItem takes the client's rotation and
uses the held item, nothing else. The host ran the whole right click, with
the block the guest had looked at before: a guest that turned from an
ender chest to a double chest could get the ender chest opened again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-16 10:58:09 +02:00
parent 257b5e9f2d
commit bc0cd9cc84
2 changed files with 17 additions and 7 deletions
+12 -7
View File
@@ -1017,6 +1017,9 @@ struct Game<'a> {
saved_for_exit: bool,
/// The block a guest is acting on (game/lan_actions.rs).
forced_hit: Option<Hit>,
/// A guest's `ServerboundUseItemPacket`: the held item alone, no block
/// or entity (`ServerGamePacketListenerImpl.handleUseItem`).
lan_item_only: bool,
/// Level events of this tick for the guests, and the guest acting now.
lan_events: Vec<(i32, [i32; 3], i32, Option<u32>)>,
/// Block events (position, b0, b1, state) and entity events (id, event,
@@ -2350,17 +2353,18 @@ impl Game<'_> {
{
return Ok(Some(Hand::Main));
}
if self.interact_frame()
|| self.interact_armor_stand()
|| self.interact_boat()
|| self.interact_cart()
|| self.interact_mob()?
|| self.interact_knot()
if !self.lan_item_only
&& (self.interact_frame()
|| self.interact_armor_stand()
|| self.interact_boat()
|| self.interact_cart()
|| self.interact_mob()?
|| self.interact_knot())
{
return Ok(Some(Hand::Main));
}
// An EntityHitResult may fall through to Item.use, never to useItemOn.
let block_hit = if self.entity_targeted() {
let block_hit = if self.lan_item_only || self.entity_targeted() {
None
} else {
self.pick()
@@ -10169,6 +10173,7 @@ pub fn run() -> Result<()> {
text_selection: Default::default(),
saved_for_exit: false,
forced_hit: None,
lan_item_only: false,
lan_events: Vec::new(),
lan_block_events: Vec::new(),
lan_entity_events: Vec::new(),
@@ -441,8 +441,13 @@ impl Game<'_> {
if spectator {
return;
}
// handleUseItem: the client's rotation, then the item alone. What it
// looked at a moment ago (a block, a mob) is UseItemOn's or Interact's.
self.as_guest(host, conn, |g| {
(g.yaw, g.pitch) = (p.yaw, p.pitch);
g.lan_item_only = true;
let _ = g.use_item();
g.lan_item_only = false;
});
}
S::Attack(p) => self.guest_attack(host, conn, p.id),