pub struct Menu {
behavior: MenuBehavior,
layout: MenuLayout,
kind: Box<dyn MenuKind>,
overrides_player_slots: bool,
}Expand description
A menu opened by a player: the shared click machinery plus one
MenuKind.
The single concrete menu type. It owns the MenuBehavior, the
MenuLayout, and a boxed MenuKind. Click handlers are inherent methods.
Fields§
§behavior: MenuBehavior§layout: MenuLayout§kind: Box<dyn MenuKind>§overrides_player_slots: boolImplementations§
Source§impl Menu
impl Menu
Sourcepub(super) fn from_parts(
behavior: MenuBehavior,
layout: MenuLayout,
kind: Box<dyn MenuKind>,
overrides_player_slots: bool,
) -> Self
pub(super) fn from_parts( behavior: MenuBehavior, layout: MenuLayout, kind: Box<dyn MenuKind>, overrides_player_slots: bool, ) -> Self
Assembles a menu from its parts.
Sourcepub const fn behavior(&self) -> &MenuBehavior
pub const fn behavior(&self) -> &MenuBehavior
Returns a reference to the shared menu behavior.
Sourcepub const fn behavior_mut(&mut self) -> &mut MenuBehavior
pub const fn behavior_mut(&mut self) -> &mut MenuBehavior
Returns a mutable reference to the shared menu behavior.
Sourcepub fn kind_mut(&mut self) -> &mut dyn MenuKind
pub fn kind_mut(&mut self) -> &mut dyn MenuKind
Returns a mutable reference to this menu’s kind.
Sourcepub const fn container_id(&self) -> u8
pub const fn container_id(&self) -> u8
The container ID for this menu (0 for the player inventory).
The menu type for the open-screen packet, or None for the player’s own
inventory.
Sourcepub const fn overrides_player_slots(&self) -> bool
pub const fn overrides_player_slots(&self) -> bool
Returns whether this menu paints over the client’s standard player slots.
Sourcepub fn still_valid(&self, player: &Player) -> bool
pub fn still_valid(&self, player: &Player) -> bool
Returns true if this menu is still valid for the player.
Sourcepub fn can_take_item_for_pick_all(
&self,
carried: &ItemStack,
slot_index: usize,
) -> bool
pub fn can_take_item_for_pick_all( &self, carried: &ItemStack, slot_index: usize, ) -> bool
Returns true if the item can be taken from the slot during pickup all.
Sourcepub fn removed(&mut self, player: &Player)
pub fn removed(&mut self, player: &Player)
Called when the menu is closed. Hands the carried item and input sections
back to the player, then runs the kind’s cleanup. Items drop into the
world if the player can’t take them (see
Player::returns_menu_items_to_inventory).
Sourcepub fn set_item_name(&mut self, name: impl Into<String>, player: &Player)
pub fn set_item_name(&mut self, name: impl Into<String>, player: &Player)
Applies a client rename to the menu’s kind. A no-op for kinds without a rename input.
Sourcepub(crate) fn clear_or_count_crafting_items(
&mut self,
predicate: &dyn Fn(&ItemStack) -> bool,
amount_to_remove: i32,
counting_only: bool,
) -> i32
pub(crate) fn clear_or_count_crafting_items( &mut self, predicate: &dyn Fn(&ItemStack) -> bool, amount_to_remove: i32, counting_only: bool, ) -> i32
Clears or counts crafting-grid items in the base inventory menu, returning the number cleared or counted. Returns 0 for any other menu.
Sourcepub(crate) fn update_crafting_result(&mut self)
pub(crate) fn update_crafting_result(&mut self)
Recomputes the base inventory menu’s crafting result. A no-op for any other menu.
Sourcefn slots_changed(&mut self, guard: &mut ContainerLockGuard, player: &Player)
fn slots_changed(&mut self, guard: &mut ContainerLockGuard, player: &Player)
Recomputes recipe-driven slots after a change (delegates to the kind).
Sourcepub fn on_open(&mut self, player: &Player)
pub fn on_open(&mut self, player: &Player)
Runs the kind’s on_open hook, after contents are built but before they
are sent to the client.
Sourcepub fn on_tick(&mut self, player: &Player)
pub fn on_tick(&mut self, player: &Player)
Runs the kind’s on_tick hook. Called once per server tick while open.
Sourcefn quick_move_stack(
&mut self,
guard: &mut ContainerLockGuard,
slot_index: usize,
player: &Player,
) -> ItemStack
fn quick_move_stack( &mut self, guard: &mut ContainerLockGuard, slot_index: usize, player: &Player, ) -> ItemStack
Shift-click (quick move) for a slot: the kind’s override if any, else the declarative route table. Returns the item originally in the slot, or empty if nothing moved.
Sourcepub fn clicked(&mut self, click: Click, player: &Player)
pub fn clicked(&mut self, click: Click, player: &Player)
Handles a click action in this menu. Packet clicks are validated via
Click::parse; invalid programmatically constructed clicks are ignored.
TODO: Add tryItemClickBehaviorOverride for bundle item support.
Sourcefn do_quick_move(&mut self, slot_index: usize, player: &Player)
fn do_quick_move(&mut self, slot_index: usize, player: &Player)
Handles quick move (shift-click).
Sourcefn do_swap(&mut self, slot_index: usize, with: SwapTarget, player: &Player)
fn do_swap(&mut self, slot_index: usize, with: SwapTarget, player: &Player)
Handles swap (number keys for a hotbar slot, or swap-hands for the offhand).
Sourcefn do_pickup_all(
&mut self,
slot_index: usize,
direction: FillDirection,
player: &Player,
)
fn do_pickup_all( &mut self, slot_index: usize, direction: FillDirection, player: &Player, )
Handles pickup all (double-click): collects matching items from all slots into the carried stack.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Menu
impl !UnwindSafe for Menu
impl Freeze for Menu
impl Send for Menu
impl Sync for Menu
impl Unpin for Menu
impl UnsafeUnpin for Menu
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreArc<SyncMutex<>>