From a4ccf205f7872362bb53b9ffd40f038ca8ce5793 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 19:21:09 +0100 Subject: [PATCH] Throw what /give cannot fit from the player's eyes, for that player only --- crates/horizon-client/src/entities.rs | 9 ++++++- crates/horizon-client/src/entities/fluids.rs | 1 + crates/horizon-client/src/entity_nbt.rs | 7 +++++ crates/horizon-client/src/game.rs | 5 +++- crates/horizon-client/src/game/commands.rs | 26 +++++++++++++++++-- crates/horizon-client/src/game/lan_actions.rs | 11 ++++++-- crates/horizon-client/src/game/machines.rs | 1 + crates/horizon-client/src/game/remote.rs | 1 + 8 files changed, 55 insertions(+), 6 deletions(-) diff --git a/crates/horizon-client/src/entities.rs b/crates/horizon-client/src/entities.rs index 69e053411..ce12558c0 100644 --- a/crates/horizon-client/src/entities.rs +++ b/crates/horizon-client/src/entities.rs @@ -19,6 +19,8 @@ pub struct ItemEntity { pub id: u32, pub stack: ItemStack, pub thrower: Option<[i32; 4]>, + /// `ItemEntity.target`: the only player who may pick the item up. + pub target: Option<[i32; 4]>, pub position: Vec3, pub previous: Vec3, pub velocity: Vec3, @@ -346,7 +348,10 @@ pub fn merge_with_neighbours( } // ItemEntity.areMergable: both fit one stack of the same item and components. let (this, other) = (&items[i].stack, &items[j].stack); - if this.count + other.count > max_stack(other) || !this.same_item_same_components(other) { + if items[i].target != items[j].target + || this.count + other.count > max_stack(other) + || !this.same_item_same_components(other) + { continue; } let (to, from) = if other.count < this.count { @@ -874,6 +879,7 @@ mod fire_environment_tests { let make = |id: &str| ItemEntity { id: 1, thrower: None, + target: None, stack: ItemStack { item: std::sync::Arc::from(id), count: 1, @@ -970,6 +976,7 @@ mod merge_tests { ItemEntity { id: 0, thrower: None, + target: None, stack: ItemStack { item: std::sync::Arc::from(id), count, diff --git a/crates/horizon-client/src/entities/fluids.rs b/crates/horizon-client/src/entities/fluids.rs index fffa0ae2b..3b3dffa99 100644 --- a/crates/horizon-client/src/entities/fluids.rs +++ b/crates/horizon-client/src/entities/fluids.rs @@ -189,6 +189,7 @@ mod tests { extra: None, }, thrower: None, + target: None, position: at, previous: at, velocity: Vec3::ZERO, diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs index 7f3565067..c5115baac 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -967,6 +967,11 @@ pub fn item_entity_to_nbt(e: &ItemEntity, uuid: [i32; 4], raw: Option<&Tag>) -> } else if let Tag::Compound(map) = &mut tag { map.remove(&"Thrower".into()); } + if let Some(target) = e.target { + put(&mut tag, "Owner", Tag::IntArray(target.to_vec())); + } else if let Tag::Compound(map) = &mut tag { + map.remove(&"Owner".into()); + } tag } pub fn item_entity_from_nbt(tag: &Tag, id: u32, bob_offset: f32) -> Option { @@ -978,6 +983,7 @@ pub fn item_entity_from_nbt(tag: &Tag, id: u32, bob_offset: f32) -> Option { health: 5, fire_ticks: 0, thrower: None, + target: None, id: self.next_entity, stack, position: p, @@ -2417,6 +2418,7 @@ impl Game<'_> { ], ); let feet = [p.position.x, p.position.y, p.position.z]; + let own = self.level.ensure_player_uuid(); let mut kept = Vec::with_capacity(items.len()); for mut item in items { let b = item.bounds(); @@ -2426,7 +2428,8 @@ impl Game<'_> { && b.max_position().y > min[1] && b.min_position().z < max[2] && b.max_position().z > min[2]; - if touching && item.pickup_delay == 0 { + // ItemEntity.playerTouch: no pickup delay, and the target (if any) is this player. + if touching && item.pickup_delay == 0 && item.target.is_none_or(|t| t == own) { let before = item.stack.count; let kind = item.stack.item.clone(); match self.give(item.stack.clone()) { diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index 8f934ad8a..2988996d1 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -1042,6 +1042,17 @@ impl Game<'_> { // An air stack is empty: nothing is given (but the message still is). let empty = id == "minecraft:air"; for &t in targets.iter().filter(|_| !empty) { + // The player's UUID, which an item they could not hold is set to. + let conn = match t { + Target::Guest(conn) => Some(conn), + _ => self.lan_acting, + }; + let uuid = match conn { + Some(conn) => self + .command_guest(conn) + .map(|g| horizon_client::lan::playerdata::uuid_ints(g.uuid)), + None => Some(self.level.ensure_player_uuid()), + }; self.for_player(t, |g| { let mut remaining = count; while remaining > 0 { @@ -1058,8 +1069,19 @@ impl Game<'_> { .target_position(Target::Player) .unwrap_or(g.source_position()); if let Some(rest) = left { - // Inventory full: drop the rest at the player's feet without pickup delay. - g.spawn_item(rest, [p[0], p[1] + 1.32, p[2]], [0.0, 0.0, 0.0], 0); + // Inventory full: Player.createItemStackToDrop (thrown from + // the eyes), then setNoPickUpDelay and setTarget(player). + let eye = g.eye_position().unwrap_or([ + p[0], + p[1] + g.target_eye_height(Target::Player), + p[2], + ]); + g.throw_from_eyes(rest, eye); + if let Some(item) = g.dropped.last_mut() { + item.thrower = None; + item.pickup_delay = 0; + item.target = uuid; + } } else { let r = &mut g.world.random; let pitch = ((r.next_float() - r.next_float()) * 0.7 + 1.0) * 2.0; diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 43bb573dc..d0bd8e670 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -2569,9 +2569,15 @@ impl Game<'_> { /// Dropped items touching a guest go into their inventory. fn guest_pickups(&mut self, host: &mut LanHost, gi: usize) { - let (conn, mode, position, id) = { + let (conn, mode, position, id, uuid) = { let g = &host.hub.guests[gi]; - (g.conn, g.game_mode, g.position, g.entity_id) + ( + g.conn, + g.game_mode, + g.position, + g.entity_id, + horizon_client::lan::playerdata::uuid_ints(g.uuid), + ) }; if mode == SPECTATOR || self.dropped.is_empty() { return; @@ -2582,6 +2588,7 @@ impl Game<'_> { .enumerate() .filter(|(_, d)| { d.pickup_delay == 0 + && d.target.is_none_or(|t| t == uuid) && (d.position.x - position[0]).abs() < 1.5 && (d.position.z - position[2]).abs() < 1.5 && d.position.y > position[1] - 0.6 diff --git a/crates/horizon-client/src/game/machines.rs b/crates/horizon-client/src/game/machines.rs index bb936744b..94d9790d4 100644 --- a/crates/horizon-client/src/game/machines.rs +++ b/crates/horizon-client/src/game/machines.rs @@ -955,6 +955,7 @@ mod item_column_tests { id, stack: ItemStack::new("minecraft:stone", 1), thrower: None, + target: None, position: at, previous: at, velocity: Vec3::ZERO, diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 3cfbd15e3..5b9bc7ff7 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -2980,6 +2980,7 @@ impl Game<'_> { health: 5, fire_ticks: 0, thrower: None, + target: None, id: id as u32, stack, position: at,