Skip to main content

Menu

Struct Menu 

Source
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: bool

Implementations§

Source§

impl Menu

Source

pub(super) fn from_parts( behavior: MenuBehavior, layout: MenuLayout, kind: Box<dyn MenuKind>, overrides_player_slots: bool, ) -> Self

Assembles a menu from its parts.

Source

pub const fn behavior(&self) -> &MenuBehavior

Returns a reference to the shared menu behavior.

Source

pub const fn behavior_mut(&mut self) -> &mut MenuBehavior

Returns a mutable reference to the shared menu behavior.

Source

pub fn kind(&self) -> &dyn MenuKind

Returns a reference to this menu’s kind.

Source

pub fn kind_mut(&mut self) -> &mut dyn MenuKind

Returns a mutable reference to this menu’s kind.

Source

pub const fn container_id(&self) -> u8

The container ID for this menu (0 for the player inventory).

Source

pub const fn menu_type(&self) -> Option<MenuTypeRef>

The menu type for the open-screen packet, or None for the player’s own inventory.

Source

pub const fn overrides_player_slots(&self) -> bool

Returns whether this menu paints over the client’s standard player slots.

Source

pub fn still_valid(&self, player: &Player) -> bool

Returns true if this menu is still valid for the player.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub(crate) fn update_crafting_result(&mut self)

Recomputes the base inventory menu’s crafting result. A no-op for any other menu.

Source

fn slots_changed(&mut self, guard: &mut ContainerLockGuard, player: &Player)

Recomputes recipe-driven slots after a change (delegates to the kind).

Source

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.

Source

pub fn on_tick(&mut self, player: &Player)

Runs the kind’s on_tick hook. Called once per server tick while open.

Source

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.

Source

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.

Source

fn do_quick_move(&mut self, slot_index: usize, player: &Player)

Handles quick move (shift-click).

Source

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).

Source

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§

Source§

impl Debug for Menu

Source§

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

Formats the value using the given formatter. Read more

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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoShared for T

Source§

fn into_shared(self) -> Arc<Mutex<RawMutex, Self>>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more