diff --git a/crates/horizon-client/src/entities.rs b/crates/horizon-client/src/entities.rs index 3039e1611..2c3488f5d 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, @@ -355,7 +357,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 { @@ -951,6 +956,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, @@ -1047,6 +1053,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 d3cda6c3a..a2d1bef82 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -1360,6 +1360,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 { @@ -1371,6 +1376,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, @@ -2730,6 +2731,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(); @@ -2739,7 +2741,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 21153f03e..ea628917e 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -1162,6 +1162,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 { @@ -1178,8 +1189,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, false); + 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 7f0a06a03..80b1b74cf 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -2879,9 +2879,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; @@ -2892,6 +2898,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 0abf36a73..f9a208a7f 100644 --- a/crates/horizon-client/src/game/machines.rs +++ b/crates/horizon-client/src/game/machines.rs @@ -1189,6 +1189,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 c14c11e49..097ecaf77 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -3313,6 +3313,7 @@ impl Game<'_> { health: 5, fire_ticks: 0, thrower: None, + target: None, id: id as u32, stack, position: at,