Skip to main content

MenuRef

Struct MenuRef 

pub struct MenuRef { /* private fields */ }
Expand description

One player’s open menu, invalidated on close, replacement or reconnect. Client menu handles are also invalidated on respawn.

Clicks require a mutable client host, not a server or a read-only hook:

ⓘ
use mod_api::{MenuRef, ServerHost};
fn wrong(menu: MenuRef, host: &mut dyn ServerHost) {
    menu.click(host, &[]);
}
ⓘ
use mod_api::{MenuRef, ClientHost};
fn wrong(menu: MenuRef, host: &dyn ClientHost) {
    menu.click(host, &[]);
}

Implementations§

§

impl MenuRef

pub fn container_id(self, host: &dyn Host) -> Option<i32>

Side: server. Container id (0 for the player’s inventory menu).

pub fn kind(self, host: &dyn Host) -> Option<Option<String>>

Side: server. Registry menu type; the inventory menu has no MenuType in vanilla. The outer None means an unavailable menu.

pub fn slot_count(self, host: &dyn Host) -> Option<usize>

Side: both. Number of slots in AbstractContainerMenu.slots.

pub fn slot(self, host: &dyn Host, slot: usize) -> Option<Option<ItemStack>>

Side: both. Full stack at a menu index. Outer None means unavailable or out of range; Some(None) means an empty slot.

pub fn carried(self, host: &dyn Host) -> Option<Option<ItemStack>>

Side: both. Carried (cursor) stack; outer None means unavailable.

pub fn slot_backing( self, host: &dyn Host, slot: usize, ) -> Option<MenuSlotBacking>

Side: server. The storage menu slot slot shows (Slot.container and getContainerSlot): the player’s inventory by ENTITY_ITEMS index (InventoryMenu’s armour slots 5..9 go head to feet), a block entity’s or an entity’s slot, the ender chest’s, the crafting grid’s or a mod’s chest menu’s.

pub fn slot_holds( self, host: &dyn Host, slot: usize, stack: &ItemStack, ) -> Option<u32>

Side: server. How many of stack menu slot slot holds (Slot.mayPlace, then Slot.getMaxStackSize): a furnace’s fuel slot one bucket, an armour slot one piece that fits it, a crafting result none.

pub fn slot_gives(self, host: &dyn Host, slot: usize) -> Option<bool>

Side: server. Whether menu slot slot gives up what it holds (Slot.mayPickup): bound armour stays on outside creative.

pub fn slot_boxes(self, host: &dyn ClientHost) -> Option<Vec<Option<[f32; 4]>>>

Side: client. The open inventory screen’s slot boxes in menu slot order (AbstractContainerScreen.leftPos/topPos plus each Slot.x/Slot.y, 16x16). A box is [x, y, width, height] in GUI pixels, with None for a hidden slot. Returns None for a stale menu, another screen, or an inventory covered by the recipe book. The boxes follow the actual layout, including GUI scale and the recipe book’s horizontal offset.

pub fn close_container(self, host: &mut dyn ServerHost) -> bool

Side: server. Close a player’s open menu as ServerPlayer.closeContainer does, running the normal lifecycle once: the container’s lid, a vehicle’s or a trade’s stand-in, the crafting, station and mount menus, the carried stack back to the inventory, player_container_close, then the client’s window closed (ContainerClose). Refuses stale menus, clients, a player whose state is swapped in for a turn, and the player’s own inventory menu, which is never closed. A client closes its own screen with close.

pub fn click(self, host: &mut dyn ClientHost, clicks: &[MenuClick]) -> bool

Side: client. Submit clicks on the local player’s live menu through normal prediction and ContainerClick. Slots use the same menu order as slot; None is outside (-999). All clicks are validated before any prediction or send. A drag expands to one complete quick-craft gesture. Refuses stale menus, invalid slots/hotbar indices, spectators, non-client hosts, the creative inventory screen and empty batches without changing items. True means submitted, not accepted by the server: its corrections win.

pub fn close(self, host: &mut dyn ClientHost) -> bool

Side: client. Close the local player’s open container screen as Escape does (AbstractContainerScreen.onClose, LocalPlayer.closeContainer): the server is told (ContainerClose) and the screen goes. Refuses stale menus, non-client hosts and a menu whose screen is not open, such as the inventory menu while playing. A server closes a menu with close_container.

pub fn click_button(self, host: &mut dyn ClientHost, button: i32) -> bool

Side: client. Press button button of the local player’s open menu as a click on one of its buttons does (MultiPlayerGameMode.handleInventoryButtonClick, ContainerButtonClick): the server’s menu decides what it does (clickMenuButton, and menu_button for a mod’s menu). For a client mod’s own input on a menu’s screen where screen_click doesn’t come, such as a key or the wheel; no sound, that is the screen’s. Refuses stale menus, non-client hosts and the inventory menu, which no server opened. True means sent, not that the menu took it.

§

impl MenuRef

pub fn cursor(self) -> ItemPlace

The stack on this menu’s cursor, as a place (ItemAccess.forPlayerCursor): nothing once the menu is gone.

Trait Implementations§

§

impl Clone for MenuRef

§

fn clone(&self) -> MenuRef

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Copy for MenuRef

§

impl Debug for MenuRef

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Eq for MenuRef

§

impl Hash for MenuRef

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for MenuRef

§

fn eq(&self, other: &MenuRef) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for MenuRef

§

impl Wire for MenuRef

§

const MIN: usize

Minimum encoded size, used to reject impossible collection lengths.
§

fn put(&self, out: &mut Writer)

Encodes this value, recording failures on the writer.
§

fn put_owned(self, out: &mut Writer)

Consumes owned data when a resource’s ownership must cross the boundary.
§

fn take(input: &mut Reader<'_>) -> Result<MenuRef, WireError>

Decodes one value, leaving any following bytes for the caller.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Put for T
where T: Wire,

§

fn put_to(&self, out: &mut Writer)

Writes it.
§

impl<T> Record for T
where T: Wire,

§

fn encode(&self, out: &mut Writer)

Writes the argument into a hook call.
§

fn apply(&mut self, bytes: &[u8]) -> Result<(), WireError>

Applies one complete reply, refusing malformed or trailing bytes atomically.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.