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: ItemStackThe item being carried by the cursor.
remote_carried: RemoteSlotThe client’s perception of the carried item.
container_id: u8The container ID (0 for player inventory).
state_id: u32Incremented on every server/client mismatch.
None for the player inventory.
suppress_remote_updates: boolSuppresses 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: MenuInstanceIdImplementations§
Source§impl MenuBehavior
impl MenuBehavior
Sourcepub(crate) fn new(
instance: MenuInstanceId,
slots: Vec<Box<dyn Slot>>,
container_id: u8,
menu_type: Option<MenuTypeRef>,
container_refs: Vec<ContainerRef>,
) -> Self
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.
Sourcepub fn lock_all_containers(&self) -> ContainerLockGuard
pub fn lock_all_containers(&self) -> ContainerLockGuard
Locks all containers referenced by slots in this menu.
Sourcepub(crate) fn lock_all_containers_with(
&self,
additional: ContainerRef,
) -> ContainerLockGuard
pub(crate) fn lock_all_containers_with( &self, additional: ContainerRef, ) -> ContainerLockGuard
Locks the menu containers together with one additional container.
Sourcepub const fn carried_mut(&mut self) -> &mut ItemStack
pub const fn carried_mut(&mut self) -> &mut ItemStack
The item carried by the cursor.
Sourcepub const fn container_id(&self) -> u8
pub const fn container_id(&self) -> u8
The container ID (0 for the player inventory).
The menu type, or None for the player’s own inventory.
Sourcepub const fn quickcraft(&self) -> Option<DragKind>
pub const fn quickcraft(&self) -> Option<DragKind>
The kind of drag in progress, or None when idle.
Sourcepub(crate) const fn instance(&self) -> MenuInstanceId
pub(crate) const fn instance(&self) -> MenuInstanceId
The identity stamp of the menu this behavior belongs to.
Sourcepub(crate) fn add_data_slot(&mut self, initial_value: i16) -> usize
pub(crate) fn add_data_slot(&mut self, initial_value: i16) -> usize
Adds a data slot with an initial value, returning its index.
Sourcepub(crate) fn reset_quick_craft(&mut self)
pub(crate) fn reset_quick_craft(&mut self)
Resets the quickcraft state.
Sourcepub(crate) fn update_quick_move_source(
&self,
guard: &mut ContainerLockGuard,
slot_index: usize,
remaining: &ItemStack,
previous: &ItemStack,
)
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.
Sourcepub 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
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.
Sourcepub(crate) const fn suppress_remote_updates(&mut self)
pub(crate) const fn suppress_remote_updates(&mut self)
Suppresses remote updates during click handling.
Sourcepub(crate) const fn resume_remote_updates(&mut self)
pub(crate) const fn resume_remote_updates(&mut self)
Resumes remote updates after click handling.
Sourcepub(crate) fn transfer_state(&mut self, other: &MenuBehavior)
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.
Sourcepub const fn slot_count(&self) -> usize
pub const fn slot_count(&self) -> usize
The number of slots in this menu.
Sourceconst fn increment_state_id(&mut self) -> u32
const fn increment_state_id(&mut self) -> u32
Increments and returns the new state ID.
Sourcefn send_packet<P: ClientPacket>(connection: &Arc<PlayerConnection>, packet: P)
fn send_packet<P: ClientPacket>(connection: &Arc<PlayerConnection>, packet: P)
Encodes and sends a packet through the connection.
Sourcepub(crate) fn send_all_data_to_remote(
&mut self,
connection: &Arc<PlayerConnection>,
)
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.
Sourcepub fn broadcast_changes(&mut self, connection: &Arc<PlayerConnection>)
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.
Sourcefn synchronize_data_slot_to_remote(
&mut self,
index: usize,
connection: &Arc<PlayerConnection>,
)
fn synchronize_data_slot_to_remote( &mut self, index: usize, connection: &Arc<PlayerConnection>, )
Sends a data slot update to the client if it changed.
Sourcefn synchronize_slot_to_remote(
&mut self,
slot: usize,
item: ItemStack,
connection: &Arc<PlayerConnection>,
)
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.
Sourcefn synchronize_carried_to_remote(&mut self, connection: &Arc<PlayerConnection>)
fn synchronize_carried_to_remote(&mut self, connection: &Arc<PlayerConnection>)
Sends the carried item (cursor) to the client.
Sourcepub(crate) fn set_remote_slot_known(&mut self, slot: usize, item: &ItemStack)
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.
Sourcepub(crate) fn mark_remote_slot_unknown(&mut self, slot: usize)
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.
Sourcepub(crate) fn set_remote_slot(&mut self, slot: usize, hash: HashedStack)
pub(crate) fn set_remote_slot(&mut self, slot: usize, hash: HashedStack)
Records the client’s reported perception of a slot.
Sourcepub(crate) fn set_remote_carried(&mut self, hash: HashedStack)
pub(crate) fn set_remote_carried(&mut self, hash: HashedStack)
Records the client’s reported carried item.
Sourcepub(crate) fn do_quick_craft(
&mut self,
action: QuickCraft,
has_infinite_materials: bool,
player: &Player,
can_drag_to: &impl Fn(usize) -> bool,
)
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.
Sourcefn finish_quick_craft(
&mut self,
player: &Player,
can_drag_to: &impl Fn(usize) -> bool,
)
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).
Sourcepub(crate) fn drop_carried(&mut self, button: MouseButton, player: &Player)
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.
Sourcepub(crate) fn do_pickup(
&mut self,
slot_index: usize,
button: MouseButton,
player: &Player,
)
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).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MenuBehavior
impl !UnwindSafe for MenuBehavior
impl Freeze for MenuBehavior
impl Send for MenuBehavior
impl Sync for MenuBehavior
impl Unpin for MenuBehavior
impl UnsafeUnpin for MenuBehavior
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<>>