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
impl MenuRef
pub fn container_id(self, host: &dyn Host) -> Option<i32>
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>>
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>
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>>
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>>
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>
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>
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>
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]>>>
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
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
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
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.
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.