diff --git a/crates/horizon-client/src/enchant.rs b/crates/horizon-client/src/enchant.rs index 42d237c50..6e806712a 100644 --- a/crates/horizon-client/src/enchant.rs +++ b/crates/horizon-client/src/enchant.rs @@ -194,7 +194,11 @@ impl Enchantments { || k.starts_with("potion.") || k.starts_with("container.") || k.starts_with("merchant.") - || k.starts_with("entity.minecraft.villager") + || k.starts_with("entity.minecraft.") + || k.starts_with("gui.recipebook.") + || k.starts_with("gui.togglable_slot") + || k.starts_with("block.minecraft.banner.") + || k.starts_with("recipe.toast.") }) .collect(); let mut list = Vec::new(); diff --git a/crates/horizon-client/src/entity_nbt.rs b/crates/horizon-client/src/entity_nbt.rs index a655c2dcd..239e9a71a 100644 --- a/crates/horizon-client/src/entity_nbt.rs +++ b/crates/horizon-client/src/entity_nbt.rs @@ -205,6 +205,11 @@ pub fn mob_to_nbt(m: &Mob, uuid: [i32; 4], raw: Option<&Tag>) -> Tag { map.insert("Variant".into(), Tag::Int(v)); } map.insert("ChestedHorse".into(), Tag::Byte(i8::from(m.extra.chested))); + if m.extra.chested && !m.extra.items.is_empty() { + map.insert("Items".into(), crate::save::encode_items(&m.extra.items)); + } else { + map.remove(&"Items".into()); + } let mut equipment = Vec::new(); if m.extra.saddled { equipment.push(( @@ -479,6 +484,9 @@ pub fn mob_from_nbt(tag: &Tag, types: &HashMap>, id: u32) - m.extra.variant = (v & 0xFF).clamp(0, 6) as u8; m.extra.variant2 = ((v >> 8) & 0xFF).clamp(0, 4) as u8; m.extra.chested = flag(tag, "ChestedHorse"); + if m.extra.chested { + m.extra.items = crate::save::decode_items(tag.get("Items"), 15); + } let eq = tag.get("equipment"); m.extra.saddled = eq.and_then(|e| e.get("saddle")).is_some(); m.extra.head = eq diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index a252164e2..e74186019 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -33,6 +33,7 @@ mod loom; mod machines; mod maps; mod minecarts; +mod mount_menu; mod mounts; mod music; mod names; @@ -614,6 +615,8 @@ struct Game<'a> { pending_banner: HashMap<[i32; 3], horizon_client::containers::Banner>, /// The recipe book of the open screen (game/recipe_book.rs). recipe_ui: recipe_book::RecipeUi, + /// The horse inventory (game/mount_menu.rs). + mount_menu: mount_menu::MountMenu, /// The player's fishing hook. hook: Option, tridents: Vec, @@ -3042,7 +3045,7 @@ impl Game<'_> { } /// 300.. are the open container's slots. fn slots(&self) -> Vec { - if let Some(v) = self.station_slots() { + if let Some(v) = self.station_slots().or_else(|| self.mount_slots()) { return v; } let mut v: Vec = (0..36).collect(); @@ -3074,6 +3077,7 @@ impl Game<'_> { .station_slot_position(i) .or_else(|| self.machine_slot_position(i)) .or_else(|| self.crafter_slot_position(i)) + .or_else(|| self.mount_slot_position(i)) { return p; } @@ -3128,6 +3132,9 @@ impl Game<'_> { }) } fn slot_mut(&mut self, i: usize) -> &mut Option { + if i >= mount_menu::SADDLE { + return self.mount_slot_mut(i); + } if i >= stations::INPUT { return self.station_slot_mut(i); } @@ -3294,6 +3301,7 @@ impl Game<'_> { | BlockEntity::Lectern(_) | BlockEntity::Banner(_), ) => {} + None if self.mount_active() => self.draw_mount_background(batch, ox, oy), None => { let texture = if self.craft_size == 3 { "gui/container/crafting_table" @@ -3320,7 +3328,7 @@ impl Game<'_> { } } } - if self.container.is_none() && self.craft_size != 3 { + if self.container.is_none() && self.craft_size != 3 && !self.mount_active() { self.draw_inventory_player(batch, ox, oy); } for i in self.slots() { @@ -3366,6 +3374,7 @@ impl Game<'_> { } pub(super) fn close_container(&mut self) { self.close_station(); + self.mount_closed(); self.recipe_ui.reset_screen(); if self.remote.is_some() { return self.remote_close_container(); @@ -3416,6 +3425,9 @@ impl Game<'_> { self.close_cart_container(); } fn click_inventory(&mut self, right: bool) { + if self.mount_click(right) { + return; + } if self.recipe_book_click(right) { return; } @@ -4356,6 +4368,7 @@ impl Game<'_> { fn tick_block_entities(&mut self) -> Result<()> { self.tick_hoppers()?; self.tick_crafters(); + self.tick_mount_menu(); self.tick_jukeboxes(); self.tick_beacons(); // ChestLidController: 0.1 per tick towards open/closed. @@ -6867,12 +6880,15 @@ impl Game<'_> { KeyCode::KeyE => match self.screen { Screen::Playing if self.spectator() => {} Screen::Playing => { - self.screen = if self.creative { - Screen::Creative - } else { - Screen::Inventory - }; - self.capture(false); + // key.inventory while riding a tamed mount opens its inventory. + if !self.open_ridden_mount_menu() { + self.screen = if self.creative { + Screen::Creative + } else { + Screen::Inventory + }; + self.capture(false); + } } Screen::Creative => { if let Some(c) = self.carried.take() { @@ -7737,6 +7753,7 @@ pub fn run() -> Result<()> { pending_shulker: HashMap::new(), pending_banner: HashMap::new(), recipe_ui: Default::default(), + mount_menu: Default::default(), hook: None, tridents: Vec::new(), rockets: Vec::new(), diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index f2cbf245e..c922f5723 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -688,6 +688,10 @@ impl Game<'_> { for item in gear { self.spawn_item(ItemStack::new(item, 1), pos, [0.0, 0.2, 0.0], 10); } + // AbstractChestedHorse.dropEquipment: the chest contents. + for stack in m.extra.items.clone().into_iter().flatten() { + self.spawn_item(stack, pos, [0.0, 0.2, 0.0], 10); + } let worn = if horizon_client::mobs::equine::is_equine(m.species()) { [None, None, None, None] } else { diff --git a/crates/horizon-client/src/game/mount_menu.rs b/crates/horizon-client/src/game/mount_menu.rs new file mode 100644 index 000000000..3e33872cb --- /dev/null +++ b/crates/horizon-client/src/game/mount_menu.rs @@ -0,0 +1,455 @@ +//! The horse inventory (`HorseInventoryMenu`, `HorseInventoryScreen`): the +//! saddle and body armour slots, the 3x5 chest of donkeys and mules and the +//! mount drawn following the cursor. It opens with E while riding a tamed +//! mount or with shift + use on a tamed one. +use super::{Game, Screen}; +use horizon_client::{ + hud::{HudBatch, rgba}, + items::ItemStack, + mobs::{Mob, Species, equine}, +}; + +/// Menu slot ids: the saddle, the body armour and the chest from 710. +pub(super) const SADDLE: usize = 700; +pub(super) const ARMOR: usize = 701; +pub(super) const CHEST: usize = 710; +/// `AbstractChestedHorse.INV_CHEST_COUNT` and `getInventoryColumns`. +const CHEST_SIZE: usize = 15; +const COLUMNS: usize = 5; + +/// The open mount menu: copies of the mount's slots, written back on every change. +#[derive(Default)] +pub(super) struct MountMenu { + open: Option, +} +struct Open { + mob: u32, + species: Species, + columns: usize, + saddle: Option, + armor: Option, + items: Vec>, + /// `shouldRenderSaddleSlot` / `shouldRenderArmorSlot`. + show_saddle: bool, + show_armor: bool, +} + +/// `EntityTypeTags.CAN_WEAR_HORSE_ARMOR`. +fn can_wear_horse_armor(species: Species) -> bool { + matches!(species, Species::Horse | Species::ZombieHorse) +} +/// Whether `item` fits the body slot of the species (`isEquippableInSlot`). +fn body_armor_fits(species: Species, item: &str) -> bool { + can_wear_horse_armor(species) && item.ends_with("_horse_armor") +} + +impl Game<'_> { + /// Whether the mount menu is the open screen. + pub(super) fn mount_active(&self) -> bool { + self.screen == Screen::Inventory && self.mount_menu.open.is_some() + } + fn mount_mob_index(&self, id: u32) -> Option { + self.mobs.iter().position(|m| m.id == id) + } + /// `AbstractHorse.openCustomInventoryScreen` for a tamed adult mount. + pub(super) fn open_mount_menu(&mut self, index: usize) { + let m = &self.mobs[index]; + let species = m.species(); + if !equine::is_equine(species) { + return; + } + let chested = m.extra.chested && matches!(species, Species::Donkey | Species::Mule); + let columns = if chested { COLUMNS } else { 0 }; + let mut items = m.extra.items.clone(); + items.resize(CHEST_SIZE, None); + let show_armor = can_wear_horse_armor(species); + self.mount_menu.open = Some(Open { + mob: m.id, + species, + columns, + saddle: m + .extra + .saddled + .then(|| ItemStack::new("minecraft:saddle", 1)), + armor: m + .extra + .head + .as_deref() + .filter(|_| show_armor) + .map(|i| ItemStack::new(i, 1)), + items, + show_saddle: true, + show_armor, + }); + self.carried = None; + self.station = None; + self.container = None; + self.craft_size = 2; + self.screen = Screen::Inventory; + self.capture(false); + } + /// E while riding a tamed mount opens its inventory instead of the player's. + pub(super) fn open_ridden_mount_menu(&mut self) -> bool { + let Some(id) = self.riding else { + return false; + }; + let Some(index) = self.mount_mob_index(id) else { + return false; + }; + let m = &self.mobs[index]; + if !equine::is_equine(m.species()) || !m.extra.tame || !m.alive() { + return false; + } + self.open_mount_menu(index); + true + } + /// The menu ends when the mount dies or is more than 4 blocks away + /// (`AbstractMountInventoryMenu.stillValid`). + pub(super) fn tick_mount_menu(&mut self) { + let Some(open) = self.mount_menu.open.as_ref() else { + return; + }; + let valid = self.mount_mob_index(open.mob).is_some_and(|i| { + let m = &self.mobs[i]; + let c = m.center(); + m.alive() + && self.eye_position().is_some_and(|e| { + let d = (e[0] - c[0]).powi(2) + (e[1] - c[1]).powi(2) + (e[2] - c[2]).powi(2); + d <= 16.0 + 4.0 + }) + }); + if !valid { + self.close_container(); + self.screen = Screen::Playing; + self.capture(true); + } + } + /// Closing the screen keeps what is in the slots on the mount. + pub(super) fn mount_closed(&mut self) { + self.mount_sync(); + self.mount_menu.open = None; + } + /// Writes the menu slots to the mount, with the equip sounds. + fn mount_sync(&mut self) { + let Some(open) = self.mount_menu.open.as_ref() else { + return; + }; + let Some(index) = self.mount_mob_index(open.mob) else { + return; + }; + let (saddle, armor) = (open.saddle.is_some(), open.armor.clone()); + let items = open.items.clone(); + let m = &mut self.mobs[index]; + let at = m.center(); + let sound = if saddle && !m.extra.saddled { + Some("minecraft:entity.horse.saddle") + } else if armor.is_some() && m.extra.head.is_none() { + Some("minecraft:entity.horse.armor") + } else { + None + }; + m.extra.saddled = saddle; + if open.show_armor { + m.extra.head = armor.map(|a| a.item); + } + m.extra.items = items; + let (x, z) = (at[0].floor() as i32 >> 4, at[2].floor() as i32 >> 4); + self.world.modified.insert((x, z)); + if let Some(sound) = sound { + self.audio.play(sound, Some(at), 0.5, 1.0); + } + } + pub(super) fn mount_slots(&self) -> Option> { + let open = self + .mount_menu + .open + .as_ref() + .filter(|_| self.mount_active())?; + let mut v: Vec = (0..36).collect(); + if open.show_saddle { + v.push(SADDLE); + } + if open.show_armor { + v.push(ARMOR); + } + v.extend((0..open.columns * 3).map(|i| CHEST + i)); + Some(v) + } + pub(super) fn mount_slot_position(&self, i: usize) -> Option<(f32, f32)> { + let open = self + .mount_menu + .open + .as_ref() + .filter(|_| self.mount_active())?; + match i { + SADDLE => Some((8.0, 18.0)), + ARMOR => Some((8.0, 36.0)), + _ if i >= CHEST => { + let n = i - CHEST; + (n < open.columns * 3).then(|| { + ( + 80.0 + (n % open.columns) as f32 * 18.0, + 18.0 + (n / open.columns) as f32 * 18.0, + ) + }) + } + _ => None, + } + } + pub(super) fn mount_slot_mut(&mut self, i: usize) -> &mut Option { + match self.mount_menu.open.as_mut() { + Some(open) if i == SADDLE => &mut open.saddle, + Some(open) if i == ARMOR => &mut open.armor, + Some(open) if i >= CHEST && i - CHEST < CHEST_SIZE => &mut open.items[i - CHEST], + _ => &mut self.scratch_slot, + } + } + /// `ArmorSlot.mayPlace` and the stack limits of the mount's slots. + pub(super) fn mount_slot_rules(&self, slot: usize, stack: &ItemStack) -> (bool, u32) { + let Some(open) = self.mount_menu.open.as_ref() else { + return (false, 64); + }; + match slot { + SADDLE => (&*stack.item == "minecraft:saddle", 1), + ARMOR => (body_armor_fits(open.species, &stack.item), 1), + _ => (true, 64), + } + } + /// A click in the mount menu before the generic handling. + pub(super) fn mount_click(&mut self, right: bool) -> bool { + if !self.mount_active() { + return false; + } + let Some(r) = self.renderer.as_ref() else { + return true; + }; + let batch = HudBatch::new([r.config.width, r.config.height]); + let Some(slot) = self.slot_at(&batch, self.cursor.0, self.cursor.1) else { + return true; + }; + let shift = self.keys.contains(&winit::keyboard::KeyCode::ShiftLeft) + || self.keys.contains(&winit::keyboard::KeyCode::ShiftRight); + if shift { + self.mount_quick_move(slot); + } else if slot >= SADDLE { + self.click_filtered(slot, right); + } else { + return false; + } + self.mount_sync(); + true + } + /// The inventory slot ids in menu order. + fn mount_player_slots() -> Vec { + (9..36).chain(0..9).collect() + } + /// `AbstractMountInventoryMenu.quickMoveStack`. + fn mount_quick_move(&mut self, slot: usize) { + let Some(open) = self.mount_menu.open.as_ref() else { + return; + }; + let (columns, show_saddle, show_armor) = (open.columns, open.show_saddle, open.show_armor); + let Some(mut stack) = self.slot_mut(slot).take() else { + return; + }; + if slot >= SADDLE { + let player = Self::mount_player_slots(); + self.move_to(&mut stack, &player, true); + } else { + let armor_free = self.mount_slot_mut(ARMOR).is_none(); + let saddle_free = self.mount_slot_mut(SADDLE).is_none(); + let armor_ok = show_armor && self.mount_slot_rules(ARMOR, &stack).0 && armor_free; + let saddle_ok = show_saddle && self.mount_slot_rules(SADDLE, &stack).0 && saddle_free; + if armor_ok { + self.move_to(&mut stack, &[ARMOR], false); + } else if saddle_ok { + self.move_to(&mut stack, &[SADDLE], false); + } else { + let chest: Vec = (0..columns * 3).map(|i| CHEST + i).collect(); + let moved = columns > 0 && self.move_to(&mut stack, &chest, false); + if !moved { + // Between the hotbar and the main inventory. + let other: Vec = if slot < 9 { + (9..36).collect() + } else { + (0..9).collect() + }; + self.move_to(&mut stack, &other, false); + } + } + } + if stack.count > 0 { + *self.slot_mut(slot) = Some(stack); + } + } + /// `HorseInventoryScreen`'s background, slot frames and the mount. + pub(super) fn draw_mount_background(&self, batch: &mut HudBatch, ox: f32, oy: f32) { + let Some(open) = self.mount_menu.open.as_ref() else { + return; + }; + let atlas = &self.res.atlas; + batch.sprite_region( + atlas, + "gui/container/horse", + [ox, oy, 176.0, 166.0], + 256.0, + 256.0, + ); + if open.columns > 0 { + batch.sprite_region( + atlas, + "gui/sprites/container/horse/chest_slots", + [ox + 79.0, oy + 17.0, open.columns as f32 * 18.0, 54.0], + 90.0, + 54.0, + ); + } + if open.show_saddle { + batch.sprite(atlas, "gui/sprites/container/slot", ox + 7.0, oy + 17.0); + if open.saddle.is_none() { + batch.sprite( + atlas, + "gui/sprites/container/slot/saddle", + ox + 8.0, + oy + 18.0, + ); + } + } + if open.show_armor { + batch.sprite(atlas, "gui/sprites/container/slot", ox + 7.0, oy + 35.0); + if open.armor.is_none() { + batch.sprite( + atlas, + "gui/sprites/container/slot/horse_armor", + ox + 8.0, + oy + 36.0, + ); + } + } + let grey = rgba(64, 64, 64, 255); + let title = match self.mobs.iter().find(|m| m.id == open.mob) { + Some(m) => m.custom_name.clone().unwrap_or_else(|| { + let key = format!( + "entity.minecraft.{}", + m.kind.id.trim_start_matches("minecraft:") + ); + self.translate(&key, &key) + }), + None => String::new(), + }; + batch.text(atlas, &title, ox + 8.0, oy + 6.0, grey, false); + batch.text(atlas, "Inventory", ox + 8.0, oy + 72.0, grey, false); + if let Some(m) = self.mobs.iter().find(|m| m.id == open.mob) { + self.draw_mob_preview( + batch, + m, + ox + 26.0, + oy + 18.0, + ox + 78.0, + oy + 70.0, + 17.0, + 0.25, + ); + } + } + /// `extractEntityInInventoryFollowsMouse` for a mob: depth-sorted, + /// back-face-culled quads turned toward the cursor. + #[allow(clippy::too_many_arguments)] + fn draw_mob_preview( + &self, + batch: &mut HudBatch, + mob: &Mob, + x0: f32, + y0: f32, + x1: f32, + y1: f32, + size: f32, + offset_y: f32, + ) { + let (cx, cy) = ((x0 + x1) / 2.0, (y0 + y1) / 2.0); + let x_angle = ((cx - self.cursor.0) / 40.0).atan(); + let y_angle = ((cy - self.cursor.1) / 40.0).atan(); + let mut m = mob.clone(); + m.previous = m.position; + m.body_yaw = 180.0 + x_angle * 20.0; + m.previous_body_yaw = m.body_yaw; + m.head_yaw = m.body_yaw + x_angle * 20.0; + m.previous_head_yaw = m.head_yaw; + m.head_pitch = -y_angle * 20.0; + m.previous_head_pitch = m.head_pitch; + m.hurt_time = 0; + m.death_time = 0; + let camera = glam::DVec3::new(m.position.x, m.position.y, m.position.z); + let atlas = &self.res.atlas; + let lookup = |name: &str| atlas.sprites.get(name).map(|r| [r.u0, r.v0, r.u1, r.v1]); + let mut verts = Vec::new(); + horizon_client::mobs::render::render_with( + &m, + 1.0, + camera, + &lookup, + 240 | 240 << 8, + &self.res.mob_data, + &[], + &mut verts, + ); + let height = m.kind.height as f32; + let gui = glam::Mat4::from_translation(glam::Vec3::new(cx, cy, 0.0)) + * glam::Mat4::from_scale(glam::Vec3::new(size, size, -size)) + * glam::Mat4::from_translation(glam::Vec3::new(0.0, height / 2.0 + offset_y, 0.0)) + * glam::Mat4::from_rotation_z(std::f32::consts::PI) + * glam::Mat4::from_rotation_x((y_angle * 20.0).to_radians()); + let mut quads: Vec<(f32, [[f32; 2]; 4], [[f32; 2]; 4], u32)> = Vec::new(); + for q in verts.as_chunks::<4>().0 { + let p: [glam::Vec3; 4] = + std::array::from_fn(|i| gui.transform_point3(glam::Vec3::from_array(q[i].pos))); + let n = (p[1] - p[0]).cross(p[2] - p[0]); + if n.z >= 0.0 { + continue; + } + let n = n.normalize_or_zero(); + let shade = (0.55 + 0.45 * -n.z - 0.15 * n.y).clamp(0.4, 1.0); + let c = q[0].color; + let ch = |s: u32| ((((c >> s) & 255) as f32 * shade) as u32) << s; + let color = (c & 0xFF00_0000) | ch(0) | ch(8) | ch(16); + let depth = p.iter().map(|v| v.z).sum::() / 4.0; + quads.push(( + depth, + p.map(|v| [v.x, v.y]), + std::array::from_fn(|i| q[i].uv), + color, + )); + } + quads.sort_by(|a, b| a.0.total_cmp(&b.0)); + let start = batch.vertices.len(); + for (_, p, uv, color) in quads { + batch.quad(p, uv, color); + } + batch.clip_since(start, x0, y0, x1, y1); + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn only_horses_wear_horse_armour() { + assert!(body_armor_fits( + Species::Horse, + "minecraft:iron_horse_armor" + )); + assert!(body_armor_fits( + Species::ZombieHorse, + "minecraft:diamond_horse_armor" + )); + assert!(!body_armor_fits( + Species::Donkey, + "minecraft:iron_horse_armor" + )); + assert!(!body_armor_fits( + Species::Horse, + "minecraft:iron_chestplate" + )); + } +} diff --git a/crates/horizon-client/src/game/mounts.rs b/crates/horizon-client/src/game/mounts.rs index 3865dfc82..bfe73d235 100644 --- a/crates/horizon-client/src/game/mounts.rs +++ b/crates/horizon-client/src/game/mounts.rs @@ -99,6 +99,15 @@ impl Game<'_> { if !equine::is_equine(species) || !m.alive() || Some(m.id) == self.riding { return false; } + // AbstractHorse.mobInteract: shift + use opens a tamed adult's inventory. + if !m.is_baby() + && m.extra.tame + && (self.keys.contains(&winit::keyboard::KeyCode::ShiftLeft) + || self.keys.contains(&winit::keyboard::KeyCode::ShiftRight)) + { + self.open_mount_menu(index); + return true; + } if self.feed_mount(index, item) { return true; } diff --git a/crates/horizon-client/src/game/recipe_book.rs b/crates/horizon-client/src/game/recipe_book.rs index d66b23e97..995b2704c 100644 --- a/crates/horizon-client/src/game/recipe_book.rs +++ b/crates/horizon-client/src/game/recipe_book.rs @@ -99,6 +99,9 @@ impl Game<'_> { if self.screen != Screen::Inventory || self.remote.is_some() || self.station.is_some() { return None; } + if self.mount_active() { + return None; + } match self.container_kind() { None if self.container.is_none() => Some(BookType::Crafting), Some(BlockEntity::Furnace(f)) => Some(match f.kind { diff --git a/crates/horizon-client/src/game/station_control.rs b/crates/horizon-client/src/game/station_control.rs index 7ef770bbd..8c9dff712 100644 --- a/crates/horizon-client/src/game/station_control.rs +++ b/crates/horizon-client/src/game/station_control.rs @@ -17,6 +17,7 @@ pub(super) const HELP: &[&str] = &[ "effect ID SECONDS [AMPLIFIER] give a status effect (effect clear removes all)", "effects list active status effects", "trade PROFESSION [LEVEL] [TYPE] open a villager trading menu (offers from the world's trade sequences)", + "mount-menu [tame] [chest] open the inventory of the nearest horse, donkey or mule (tame, chest set those)", "close close the open menu", ]; fn id(name: &str) -> String { @@ -194,6 +195,29 @@ impl Game<'_> { "effects" => Ok(Some( json!({ "effects": self.effects_json(), "health": self.player.as_ref().map(|p| p.health.health()) }), )), + "mount-menu" => { + let eye = self.eye_position().ok_or("no player")?; + let index = (0..self.mobs.len()) + .filter(|&i| horizon_client::mobs::equine::is_equine(self.mobs[i].species())) + .min_by(|&a, &b| { + let d = |i: usize| { + let c = self.mobs[i].center(); + (c[0] - eye[0]).powi(2) + + (c[1] - eye[1]).powi(2) + + (c[2] - eye[2]).powi(2) + }; + d(a).total_cmp(&d(b)) + }) + .ok_or("no horse around")?; + if flag("tame") { + self.mobs[index].extra.tame = true; + } + if flag("chest") { + self.mobs[index].extra.chested = true; + } + self.open_mount_menu(index); + ok() + } "close" => { self.close_container(); self.screen = Screen::Playing; diff --git a/crates/horizon-client/src/game/stations.rs b/crates/horizon-client/src/game/stations.rs index ffd882ef5..165d20b56 100644 --- a/crates/horizon-client/src/game/stations.rs +++ b/crates/horizon-client/src/game/stations.rs @@ -483,6 +483,9 @@ impl Game<'_> { /// `Slot.mayPlace` and `getMaxStackSize` for station and brewing slots. fn slot_rules(&self, slot: usize, stack: &ItemStack) -> (bool, u32) { let data = self.data(); + if slot >= super::mount_menu::SADDLE { + return self.mount_slot_rules(slot, stack); + } if let Some(BlockEntity::Crafter(c)) = self.container_kind() && (300..309).contains(&slot) { @@ -531,7 +534,7 @@ impl Game<'_> { } } /// `AbstractContainerMenu.doClick` PICKUP on a filtered slot. - fn click_filtered(&mut self, slot: usize, right: bool) { + pub(super) fn click_filtered(&mut self, slot: usize, right: bool) { let carried = self.carried.take(); let current = self.slot_mut(slot).take(); let (new_slot, new_carried) = match (carried, current) { diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index a15b1e1c6..e27e0af1f 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -435,6 +435,8 @@ pub struct Extra { pub sheared: bool, pub saddled: bool, pub chested: bool, + /// The chest contents of a donkey or mule (15 slots). + pub items: Vec>, pub tame: bool, pub sitting: bool, /// The owner's UUID (tamed animals).