Skip to main content

MenuBehavior

Struct MenuBehavior 

Source
pub struct MenuBehavior {
Show 14 fields slots: Vec<Box<dyn Slot>>, remote_slots: Vec<RemoteSlot>, carried: ItemStack, remote_carried: RemoteSlot, container_id: u8, state_id: u32, menu_type: Option<MenuTypeRef>, suppress_remote_updates: bool, quickcraft: Option<DragKind>, quickcraft_slots: Vec<usize>, data_slots: Vec<i16>, remote_data_slots: Vec<i16>, container_refs: Vec<ContainerRef>, instance: MenuInstanceId,
}
Expand description

Shared behavior and state for all menu types.

Fields§

§slots: Vec<Box<dyn Slot>>

The slots in this menu.

§remote_slots: Vec<RemoteSlot>

The client’s perception of the itemstacks.

§carried: ItemStack

The item being carried by the cursor.

§remote_carried: RemoteSlot

The client’s perception of the carried item.

§container_id: u8

The container ID (0 for player inventory).

§state_id: u32

Incremented on every server/client mismatch.

§menu_type: Option<MenuTypeRef>

None for the player inventory.

§suppress_remote_updates: bool

Suppresses remote updates during click handling.

§quickcraft: Option<DragKind>

The kind of drag in progress, or None when idle.

§quickcraft_slots: Vec<usize>

Slots involved in the current quickcraft operation.

§data_slots: Vec<i16>

Data slots for furnace progress, enchanting levels and the like.

§remote_data_slots: Vec<i16>

The client’s perception of the data slot values.

§container_refs: Vec<ContainerRef>§instance: MenuInstanceId

Identity stamp tying Section and DataSlot handles to this menu.

Implementations§

Source§

impl MenuBehavior

Source

pub(crate) fn new( instance: MenuInstanceId, slots: Vec<Box<dyn Slot>>, container_id: u8, menu_type: Option<MenuTypeRef>, container_refs: Vec<ContainerRef>, ) -> Self

Creates a menu behavior with the given slots.

Source

pub fn lock_all_containers(&self) -> ContainerLockGuard

Locks all containers referenced by slots in this menu.

Source

pub(crate) fn lock_all_containers_with( &self, additional: ContainerRef, ) -> ContainerLockGuard

Locks the menu containers together with one additional container.

Source

pub fn slots(&self) -> &[Box<dyn Slot>]

The slots of this menu, fixed at build time.

Source

pub const fn carried(&self) -> &ItemStack

The item carried by the cursor.

Source

pub const fn carried_mut(&mut self) -> &mut ItemStack

The item carried by the cursor.

Source

pub const fn container_id(&self) -> u8

The container ID (0 for the player inventory).

Source

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

The menu type, or None for the player’s own inventory.

Source

pub const fn state_id(&self) -> u32

The current state ID.

Source

pub const fn quickcraft(&self) -> Option<DragKind>

The kind of drag in progress, or None when idle.

Source

pub(crate) const fn instance(&self) -> MenuInstanceId

The identity stamp of the menu this behavior belongs to.

Source

pub(crate) fn add_data_slot(&mut self, initial_value: i16) -> usize

Adds a data slot with an initial value, returning its index.

Source

pub(crate) fn get_data(&self, index: usize) -> Option<i16>

Gets the value of a data slot.

Source

pub(crate) fn set_data(&mut self, index: usize, value: i16)

Sets the value of a data slot.

Source

pub(crate) fn reset_quick_craft(&mut self)

Resets the quickcraft state.

Source

pub(crate) fn update_quick_move_source( &self, guard: &mut ContainerLockGuard, slot_index: usize, remaining: &ItemStack, previous: &ItemStack, )

Writes a quick-move remainder back to its source slot. Fake slots are recomputed, so only their change notification fires.

Source

pub fn move_item_stack_to( &self, guard: &mut ContainerLockGuard, source_slot: usize, item_stack: &mut ItemStack, start_slot: usize, end_slot: usize, direction: FillDirection, ) -> bool

Moves items from source_slot into slots [start_slot, end_slot), walking the range in direction. Aliases of the source’s physical storage are skipped. Returns true if anything moved.

Source

pub(crate) const fn suppress_remote_updates(&mut self)

Suppresses remote updates during click handling.

Source

pub(crate) const fn resume_remote_updates(&mut self)

Resumes remote updates after click handling.

Source

pub(crate) fn transfer_state(&mut self, other: &MenuBehavior)

Copies another menu’s remote slot state, matched by (container_id, container_slot), so closing a menu doesn’t resync shared inventory slots.

Source

pub const fn slot_count(&self) -> usize

The number of slots in this menu.

Source

const fn increment_state_id(&mut self) -> u32

Increments and returns the new state ID.

Source

fn send_packet<P: ClientPacket>(connection: &Arc<PlayerConnection>, packet: P)

Encodes and sends a packet through the connection.

Source

pub(crate) fn send_all_data_to_remote( &mut self, connection: &Arc<PlayerConnection>, )

Sends every slot, the carried item and all data slots to the client and marks them synced.

Source

pub fn broadcast_changes(&mut self, connection: &Arc<PlayerConnection>)

Syncs only the changed slots, carried item and data slots to the client, once per tick.

Source

fn synchronize_data_slot_to_remote( &mut self, index: usize, connection: &Arc<PlayerConnection>, )

Sends a data slot update to the client if it changed.

Source

fn synchronize_slot_to_remote( &mut self, slot: usize, item: ItemStack, connection: &Arc<PlayerConnection>, )

Sends a single slot update and records the sent stack as the client’s perception.

Source

fn synchronize_carried_to_remote(&mut self, connection: &Arc<PlayerConnection>)

Sends the carried item (cursor) to the client.

Source

pub(crate) fn set_remote_slot_known(&mut self, slot: usize, item: &ItemStack)

Sets a remote slot to a known ItemStack when we know exactly what the client has.

Source

pub(crate) fn mark_remote_slot_unknown(&mut self, slot: usize)

Forgets what the client has in slot, forcing a resync on the next broadcast.

Source

pub(crate) fn set_remote_slot(&mut self, slot: usize, hash: HashedStack)

Records the client’s reported perception of a slot.

Source

pub(crate) fn set_remote_carried(&mut self, hash: HashedStack)

Records the client’s reported carried item.

Source

pub(crate) fn do_quick_craft( &mut self, action: QuickCraft, has_infinite_materials: bool, player: &Player, can_drag_to: &impl Fn(usize) -> bool, )

Handles one phase of a quickcraft (drag) operation. can_drag_to is the kind’s per-slot veto.

Source

fn finish_quick_craft( &mut self, player: &Player, can_drag_to: &impl Fn(usize) -> bool, )

Distributes the carried items over the dragged slots and resets the drag state (the End phase of MenuBehavior::do_quick_craft).

Source

pub(crate) fn drop_carried(&mut self, button: MouseButton, player: &Player)

Drops the carried stack when the player clicks outside the window. Left drops all, right drops one.

Source

pub(crate) fn do_pickup( &mut self, slot_index: usize, button: MouseButton, player: &Player, )

Handles a pickup click (left/right click to pick up or place items).

Source

pub(crate) fn do_clone( &mut self, slot_index: usize, has_infinite_materials: bool, )

Handles clone (middle-click in creative).

Source

pub(crate) fn do_throw( &mut self, slot_index: usize, whole_stack: bool, player: &Player, )

Handles throw (drop key). Q drops one item, Ctrl+Q (whole_stack) drops the whole stack, repeating while the slot refills with the same item.

Trait Implementations§

Source§

impl Debug for MenuBehavior

Source§

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

Formats the value using the given formatter. Read more

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