Skip to main content

Inventory

Struct Inventory 

Source
pub struct Inventory { /* private fields */ }
Expand description

The client’s inventory: player inventory, cursor, the open window, click prediction and the confirm protocol. Pure and deterministic: packets in, packets out, no I/O or clock (tick counts time).

Implementations§

Source§

impl Inventory

The 0.4.1 names of the modern methods (26.1 was the only modern version then); each one is the _modern method of the same name and works for every modern version.

Source

pub fn set_registries_26_1(&mut self, reg: HashRegistries)

👎Deprecated since 0.5.3:

use set_registries_modern

Source

pub fn registries_26_1(&self) -> &HashRegistries

👎Deprecated since 0.5.3:

use registries_modern

Source

pub fn enchantment_name_26_1(&self, id: i32) -> Option<&str>

👎Deprecated since 0.5.3:

use enchantment_name_modern

Source

pub fn set_creative_26_1(&mut self, creative: bool)

👎Deprecated since 0.5.3:

use set_creative_modern

Source

pub fn on_update_tags_26_1(&mut self, body: Bytes)

👎Deprecated since 0.5.3:

use on_update_tags_modern

Source

pub fn on_registry_data_26_1(&mut self, body: Bytes)

👎Deprecated since 0.5.3:

use on_registry_data_modern

Source

pub fn on_mount_screen_26_1( &mut self, window_id: i32, columns: i32, entity_type: i32, can_saddle: bool, can_body: bool, )

👎Deprecated since 0.5.3:

use on_mount_screen_modern

Source

pub fn on_merchant_offers_26_1(&mut self, body: &Bytes)

👎Deprecated since 0.5.3:

use on_merchant_offers_modern

Source

pub fn anvil_rename_26_1( &mut self, name: &str, ) -> Result<Option<Outgoing>, ClickError>

👎Deprecated since 0.5.3:

use anvil_rename_modern

Source

pub fn trident_spin_attack_strength_26_1( &mut self, stack: &Stack, ) -> Option<f32>

👎Deprecated since 0.5.3:

use trident_spin_attack_strength_modern

Source

pub fn select_loom_pattern_26_1( &mut self, index: i32, ) -> Result<Option<Outgoing>, ClickError>

👎Deprecated since 0.5.3:

use select_loom_pattern_modern

Source

pub fn select_trade_26_1(&mut self, index: i32) -> Result<Outgoing, ClickError>

👎Deprecated since 0.5.3:

use select_trade_modern

Source

pub fn take_creative_echo_26_1(&mut self) -> Vec<CreativePacket>

👎Deprecated since 0.5.3:

use take_creative_echo_modern

Source

pub fn creative_screen_26_1(&self) -> bool

👎Deprecated since 0.5.3:

use creative_screen_modern

Source

pub fn set_experience_level_26_1(&mut self, level: i32)

👎Deprecated since 0.5.3:

use set_experience_level_modern

Source

pub fn on_recipes_26_1<'a>( &mut self, sets: impl IntoIterator<Item = (&'a str, &'a [i32])>, stonecutter_inputs: Option<Vec<i32>>, )

👎Deprecated since 0.5.3:

use on_recipes_modern

Source

pub fn on_open_screen_26_1(&mut self, id: i32, menu: i32, title: ByteString)

👎Deprecated since 0.5.3:

use on_open_screen_modern

Source§

impl Inventory

The 0.4.1 names of the modern slot packets (they exist in every build, like 0.4.1’s).

Source

pub fn on_window_items_26_1( &mut self, window_id: i32, state_id: i32, items: impl IntoIterator<Item = Option<Stack>>, carried: Option<Stack>, )

👎Deprecated since 0.5.3:

use on_window_items_modern

Source

pub fn on_set_slot_26_1( &mut self, window_id: i32, state_id: i32, slot: i16, item: Option<Stack>, )

👎Deprecated since 0.5.3:

use on_set_slot_modern

Source§

impl Inventory

Source

pub fn click(&mut self, click: Click) -> Result<Outgoing, ClickError>

Simulates a click exactly like the vanilla client (ClientPlayerInteractionManager.clickSlot: next action number, onSlotClick, packet with its return value) and returns the packet to send now. The prediction is applied immediately; the click is pending until its confirm arrives.

Bots should click only while not turning (the server and anticheats see clicks against the last sent rotation; vanilla players do not move the camera with a GUI open).

Source

pub fn state_id(&self) -> i32

26.1: the state id the next click of the current screen carries.

Source

pub fn open_inventory(&mut self) -> Result<Option<Outgoing>, ClickError>

Opens the player inventory GUI (key E). Returns the packet to send (1.8: the “open inventory achievement” client command; 1.12 / 1.16.5: nothing). No-op when already open.

Source

pub fn close(&mut self) -> Result<Outgoing, ClickError>

Closes the open GUI (Escape / E): close_window with its id. The client drops the cursor stack (the server throws it) and, for the 1.8 player inventory, empties the crafting grid (the server drops it).

Source§

impl Inventory

Source

pub fn creative_screen_legacy(&self) -> Option<CreativeTab>

Whether the open screen is the legacy creative inventory screen, and its tab.

Source

pub fn creative_delete_slot(&self) -> i16

The slot number of the creative inventory tab’s delete slot (window 0’s length): a click drops the cursor stack, a shift-click asks the server to clear every window 0 slot.

Source

pub fn take_creative_echo_legacy(&mut self) -> Vec<CreativePacket>

The packets the legacy creative screen sent outside a click since the last call (the listener’s broadcast when the screen opened); send them right after the packet Inventory::open_inventory returned.

Source

pub fn set_creative_tab_legacy(&mut self, tab: CreativeTab)

Selects the creative screen’s tab (no packet). The tab is kept while the screen is closed (vanilla keeps it in a static), so this also chooses the tab the next opening shows; the first opening shows an item tab.

Source

pub fn creative_menu_click( &mut self, menu: Option<Stack>, click: Click, ) -> Result<Outgoing, ClickError>

A click on the menu of a creative item tab: the menu slot shows menu (a stack of the tab’s item list; the server takes whatever the client sends, so any stack works). Pick up / shift / double click set the cursor (no packet), the number keys put a full stack into the hotbar (window 0 broadcasts), middle click clones, the drop key drops a copy.

§Errors

ClickError::NoScreen when no legacy creative item tab is open; ClickError::InvalidSlot for a drag; ClickError::SameTick for a second action in a tick.

Source

pub fn pick_block_legacy( &mut self, pick: &Stack, has_data: bool, ) -> Result<Option<Outgoing>, ClickError>

The pick block key (no screen open) for a target whose pick stack is pick (1.8: its item and damage; has_data: the item has subtypes, so the damage must match too, as 1.8 doPick passes it; 1.12.2: the whole stack, NBT included, the damage compared for items with subtypes). 1.8 PlayerInventory.addPickBlock / 1.12 method_13250 select a hotbar slot that holds it or, in creative mode, put it into the selected (or first empty) hotbar slot; in creative mode the selected slot is then sent. Returns the packet (None in survival); the selected hotbar slot may change (Inventory::selected): the client then sends held_item_change.

§Errors

ClickError::WindowOpen when a screen is open; ClickError::Unpredictable for a 1.12.2 survival pick of a stack outside the hotbar (MC|PickItem, not modelled) and on other versions.

Source

pub fn creative_load_hotbar_legacy( &mut self, saved: &[Option<Stack>; 9], ) -> Result<Outgoing, ClickError>

1.12.2 creative mode: a saved toolbar loaded with its key (hotbar key + the load key, no screen open; CreativeInventoryScreen.method_14550): the hotbar becomes saved (the toolbar the client stored earlier), each slot is sent, and window 0’s broadcast runs without a listener (it only records the slots as sent).

§Errors

ClickError::WindowOpen when a screen is open; ClickError::Unpredictable outside creative mode or on other versions.

Source§

impl Inventory

Source

pub fn consume_held(&mut self, n: u8) -> bool

Client-side use of the held stack (no packet): n items off the selected hotbar stack, the slot emptied when nothing is left. Vanilla does this when a right click places a block or plants seeds (1.8 BlockItem / SeedItem.use, 1.16.5 BlockItem.place) or when eating finishes, before the server’s set_slot; call it then (not in creative, where vanilla keeps the count). Returns whether there was a stack.

Source

pub fn damage_held(&mut self, amount: u16) -> bool

Client-side durability loss of the held stack (no packet; 1.8 / 1.12 ItemStack.damage without Unbreaking, which rolls a random number): the damage goes up by amount; past the durability the stack breaks (one item less, damage 0). Vanilla does this when a hit lands on a living entity (a sword 1, a tool 2), before the server’s set_slot. Returns whether the stack took the damage (1.16.5 / 26.x keep the damage in NBT / components: false, nothing changes).

Source

pub fn consume_offhand(&mut self, n: u8) -> bool

consume_held for the offhand stack (1.12 / 1.16.5; no-op on 1.8).

Source

pub fn finish_into(&mut self, off_hand: bool, container: i32) -> bool

Client-side end of a drink or a stew (onItemUseFinish, no packet): the last item of the stack in the main hand (or the off hand, 1.12+) becomes container (a glass bottle, a bucket, a bowl; one of it); a stack of more loses one item. Returns whether there was a stack.

Source

pub fn exchange_hand( &mut self, off_hand: bool, output: Stack, creative: bool, creative_keeps: bool, ) -> bool

1.16.5 ItemUsage.exchangeStack (Yarn method_30270) on the client, after an item use in the air of the main hand (or the off hand) turned one item into output (a bucket filled, a bottle filled, a map drawn; no packet): outside creative one item is used up; the last one becomes output, else output goes into the inventory (PlayerInventory.insertStack). In creative with creative_keeps the hand keeps its stack and output goes in only when no stack of its item is there yet; in creative what does not fit is gone. Returns whether output did not fit outside creative (vanilla drops it: the client swings its main hand).

Source

pub fn set_hand(&mut self, off_hand: bool, stack: Option<Stack>)

Sets the main hand’s (or the off hand’s) stack on the client (no packet).

Source

pub fn use_equips(&self, off_hand: bool, creative: bool) -> bool

What a right-click use of the stack in the main hand (or the off hand, 1.12+) does to the armor on the client (no packet; vanilla’s item use): true when it equips the stack. 1.8 / 1.12.2 / 1.16.5 (ArmorItem / ElytraItem): only into an empty armor slot. 26.x (a swappable equippable): also swaps with the piece worn, unless that is the same item with the same components or carries the binding curse outside creative. creative is the game mode.

Source

pub fn equip_from_hand(&mut self, off_hand: bool, creative: bool) -> bool

Applies the right-click equip of Inventory::use_equips like the vanilla client, before the server’s slot updates: 1.8 – 1.16.5 the stack moves into the armor slot and the hand empties (creative too); 26.x a single item swaps with the worn piece (in creative a copy goes on and the hand keeps its stack when the slot was empty), a larger stack puts one on and keeps the rest (not predicted when a worn piece would have to go into the inventory). Returns whether the use equips (the server’s answer then follows).

Source

pub fn drop_held(&mut self, whole_stack: bool) -> bool

Client-side drop of the held stack (no packet): one item off the selected hotbar stack, or all of it with whole_stack, the slot emptied when nothing is left. The 1.16.5 / 26.1 drop key does this before the server’s set_slot (ClientPlayerEntity.dropSelectedItem, LocalPlayer.drop: removeStack(selected, whole ? count : 1)); 1.8 / 1.12 do not. Returns whether there was a stack (vanilla then swings the arm).

Source

pub fn select(&mut self, slot: u8)

Selects a hotbar slot (the behaviour’s select_slot; vanilla’s insertStack prefers it).

Source§

impl Inventory

Source

pub fn on_held_slot(&mut self, slot: i8)

held_item_slot from the server.

Source

pub fn on_open_window( &mut self, id: i32, kind: Option<WindowKind>, title: ByteString, )

open_window: the server opened a window of this kind (None: a type the vanilla client has no screen for; ignored). Any open screen is closed client-side first.

Source

pub fn on_close_window(&mut self)

close_window from the server (closes whatever is open, whatever the id).

Source

pub fn on_window_items( &mut self, window_id: i32, items: impl IntoIterator<Item = Option<Stack>>, )

window_items: replaces the window’s slots (window_id as received, unsigned byte).

Source

pub fn on_set_slot(&mut self, window_id: i32, slot: i16, item: Option<Stack>)

set_slot (window_id as received, signed byte): -1 sets the cursor, 1.12 / 1.16.5 -2 a PlayerInventory index, window 0 slots 36..45 always reach window 0, others only the current screen.

Source

pub fn on_window_items_modern( &mut self, window_id: i32, state_id: i32, items: impl IntoIterator<Item = Option<Stack>>, carried: Option<Stack>, )

26.1 container_set_content (vanilla initializeContents): window 0 or the open container’s slots, its carried stack and its state id. Window 0’s carried stack only shows while no container is open (the client keeps one per menu).

Source

pub fn on_set_slot_modern( &mut self, window_id: i32, state_id: i32, slot: i16, item: Option<Stack>, )

26.1 container_set_slot: window 0 slots always reach window 0 (any slot), the open container’s only that container; the menu’s state id follows.

Source

pub fn on_set_cursor(&mut self, item: Option<Stack>)

26.1 set_cursor_item: the open menu’s carried stack.

Source

pub fn on_set_player_inventory(&mut self, slot: i32, item: Option<Stack>)

26.1 set_player_inventory: a PlayerInventory index (0..=40; the body armor and saddle slots 41 and 42 are not kept).

Source

pub fn recipes(&self) -> &RecipeBook

The crafting recipes the server declared (1.16.5; 1.8 clients know theirs).

Source

pub fn clear_server_data(&mut self)

Forgets the server’s recipes and item tags (1.16.5): what reads them is refused again until they are sent anew (ghast-client calls this when Interests::RECIPES is switched off).

Source

pub fn on_declare_recipes(&mut self, book: RecipeBook)

1.16.5 declare_recipes: replaces the client’s recipes (the remainders of a taken crafting result, a furnace’s shift-click, the smithing table, the stonecutter; until a declared book arrives those are refused as unpredictable).

Source

pub fn on_window_property(&mut self, window_id: i32, property: i16, value: i16)

craft_progress_bar (window property).

Source

pub fn on_transaction( &mut self, window_id: i8, action: i16, accepted: bool, ) -> Option<Outgoing>

transaction (window confirm) from the server. Returns the answer to send now, exactly when vanilla answers (not accepted, and the window is 0 or the open one); resolves the pending click when it is its confirm. Route every confirm through here and answer nowhere else, so each is answered exactly once.

Source§

impl Inventory

Source

pub fn set_registries_modern(&mut self, reg: HashRegistries)

26.1: the registry names click hashes and the binding curse check need (the configuration phase’s minecraft:enchantment keys in order). Without them, clicks with enchanted items send hashes the server corrects, and taking enchanted armor off is not predicted.

Clients of one process that receive the same names share one copy of them.

Source

pub fn registries_modern(&self) -> &HashRegistries

26.1: the registry names set with Inventory::set_registries_modern.

Source

pub fn enchantment_name_modern(&self, id: i32) -> Option<&str>

26.1: the name of enchantment registry id id as the server’s registry_data keyed it (minecraft:sharpness), from the registries set with Inventory::set_registries_modern; None for an unknown id.

Source

pub fn set_creative_modern(&mut self, creative: bool)

26.1: whether the player is in creative mode (instant build): middle-click clones, clone drags, armor with the binding curse comes off, overflow vanishes. Set from the abilities packet by Inventory::apply_raw_modern.

Source

pub fn on_update_tags_modern(&mut self, body: Bytes)

26.1 update_tags (configuration tags or play tags): the body is kept and parsed at the first click in an anvil, grindstone, loom or mount screen (the item, enchantment, banner pattern and entity type tags those read). The play packet is also handled by Inventory::apply_raw_modern.

Source

pub fn on_registry_data_modern(&mut self, body: Bytes)

26.1 configuration registry_data: the minecraft:enchantment body is kept (parsed with the tags) for the anvil’s rules; other registries are ignored. Entries sent without data (a server and client sharing the vanilla pack) use the vanilla definitions.

Source

pub fn on_mount_screen_modern( &mut self, window_id: i32, columns: i32, entity_type: i32, can_saddle: bool, can_body: bool, )

26.1 horse_screen_open (ClientboundMountScreenOpenPacket): the mount’s inventory screen. The client builds it from the entity, so the caller passes what the screen reads off it: the entity type (minecraft:entity_type registry id), the packet’s inventory columns and canUseSlot(SADDLE) / canUseSlot(BODY) (horses, donkeys, mules, camels: saddle when alive, adult and tamed, body always; llamas: both always; nautili: both when alive, adult and tame).

Source

pub fn on_merchant_offers_modern(&mut self, body: &Bytes)

26.1 merchant_offers: the open villager screen’s offers.

Source

pub fn anvil_rename_modern( &mut self, name: &str, ) -> Result<Option<Outgoing>, ClickError>

26.1 anvil: types name into the name field (AnvilMenu.setItemName; the name is filtered like vanilla’s and limited to 50 characters). Returns the rename_item to send when the name changed (Ok(None): nothing to send). An empty name removes a custom name. Like the real screen, it does nothing while the input slot is empty.

§Errors

ClickError::NoScreen when no anvil is open.

Source

pub fn trident_spin_attack_strength_modern( &mut self, stack: &Stack, ) -> Option<f32>

26.1 EnchantmentHelper.getTridentSpinAttackStrength(stack): 0 run through the minecraft:trident_spin_attack_strength effect of every enchantment in the stack’s enchantments (in their order), as the server’s enchantment registry defines it (registry_data with data, else vanilla’s definition: riptide adds 1.5 + 0.75 × (level - 1)). Some(0.0) without such an enchantment.

None when it cannot be computed: an enchantment whose definition is unknown (not sent with data and not vanilla), an effect that does not read, or one that draws on the holder’s random (remove_binomial). The first call parses the raw registry data and tags (hence &mut self).

Source

pub fn select_loom_pattern_modern( &mut self, index: i32, ) -> Result<Option<Outgoing>, ClickError>

26.1 loom: clicks pattern button index (LoomMenu.clickMenuButton). Returns the container_button_click when the loom accepts it (Ok(None): not a selectable pattern).

§Errors

ClickError::NoScreen when no loom is open; ClickError::Unpredictable when the patterns are not known.

Source

pub fn select_trade_modern( &mut self, index: i32, ) -> Result<Outgoing, ClickError>

26.1 villager screen: picks trade index (setSelectionHint, tryMoveItems: the payment goes back to the inventory and the trade’s costs come out of it). Returns the select_trade to send.

§Errors

ClickError::NoScreen when no villager screen is open.

Source

pub fn take_creative_echo_modern(&mut self) -> Vec<CreativePacket>

26.1: the packets the creative inventory screen sent in answer to server packets since the last call (vanilla echoes every window 0 slot the server sets while the screen is open); send them right away.

Source

pub fn creative_screen_modern(&self) -> bool

Whether the 26.1 creative inventory screen is open (window 0 opened in creative mode): clicks then return Outgoing::Creative.

Source

pub fn set_experience_level_modern(&mut self, level: i32)

26.1: the player’s experience level (the anvil’s result can only be taken with enough); set from the experience packet by Inventory::apply_raw_modern.

Source

pub fn on_recipes_modern<'a>( &mut self, sets: impl IntoIterator<Item = (&'a str, &'a [i32])>, stonecutter_inputs: Option<Vec<i32>>, )

26.1 update_recipes (declare_recipes): the recipe item sets the furnace, smithing and stonecutter slot rules read ((set name, item ids), e.g. ("minecraft:furnace_input", …)) and the stonecutter recipes’ inputs (None when one names a tag: shift-clicks into the stonecutter are then not predicted).

Source

pub fn on_open_screen_modern(&mut self, id: i32, menu: i32, title: ByteString)

Modern open_screen: the menu registry id (minecraft:menu) and the title. Menus the client has no screen for are ignored.

Source§

impl Inventory

Source

pub fn cursor(&self) -> Option<&Stack>

The cursor (“carried”) stack.

Source

pub fn player(&self, index: usize) -> Option<&Stack>

PlayerInventory slot by vanilla index: 0..=8 hotbar, 9..=35 main, 36..=39 armor (feet, legs, chest, head), 40 offhand (1.12 / 1.16.5).

Source

pub fn hotbar(&self, k: usize) -> Option<&Stack>

Hotbar slot 0..=8.

Source

pub fn selected(&self) -> u8

The selected hotbar slot.

Source

pub fn held_writes(&self) -> u16

How many times the server wrote the selected hotbar slot (set_slot, window_items; 1.8 – 1.16.5), whether the stack changed or not, wrapping. A 1.8 client’s item use ends when the held stack is replaced, even by an equal one.

Source

pub fn offhand_writes(&self) -> u16

Inventory::held_writes for the off-hand slot (1.12 / 1.16.5).

Source

pub fn take_player_touched(&mut self) -> bool

Whether the player slots or the selected hotbar slot may have changed since the last call (and since the inventory was made); clears the flag. Conservative: any write sets it, changed or not. For a caller that keeps something derived from the hands (or any player slot) and re-reads only when this is true; there must be one such caller.

Source

pub fn held(&self) -> Option<&Stack>

The stack in the selected hotbar slot.

Source

pub fn armor(&self, a: usize) -> Option<&Stack>

Armor piece: 0 head, 1 chest, 2 legs, 3 feet.

Source

pub fn offhand(&self) -> Option<&Stack>

The offhand stack (1.12 / 1.16.5).

Source

pub fn window(&self) -> Option<&Window>

The open container window, if any.

Source

pub fn gui_open(&self) -> bool

Whether a GUI is open (a container window or the player inventory).

Source

pub fn inventory_open(&self) -> bool

Whether the player inventory GUI is open (no container window).

Source

pub fn slot_count(&self) -> usize

Number of slots of the current screen (window 0 when no container is open: 45 on 1.8, 46 on 1.12 / 1.16.5).

Source

pub fn container_len(&self) -> usize

Container slots of the open window (before the player’s 36), 0 for window 0.

Source

pub fn slot(&self, i: usize) -> Option<&Stack>

Slot i of the current screen (window 0 layout when no container is open).

Source

pub fn window0_slot(&self, i: usize) -> Option<&Stack>

Slot i of window 0 (PlayerScreenHandler numbering), whatever is open.

Source

pub fn slot_kind(&self, i: usize) -> Option<SlotKind>

Kind of slot i of the current screen.

Source

pub fn slot_of_player(&self, k: usize) -> Option<i16>

The current screen’s slot that shows PlayerInventory index k (e.g. hotbar 0 is window 0 slot 36 and slot 54 of a 3-row chest).

Source

pub fn find(&self, pred: impl FnMut(&Stack) -> bool) -> Option<i16>

First slot of the current screen whose stack matches.

Source

pub fn count(&self, pred: impl FnMut(&Stack) -> bool) -> i32

Total count of matching stacks in the player inventory (hotbar, main, armor, offhand).

Source

pub fn result_known(&self) -> bool

Whether the current screen’s crafting result (window 0 slot 0, crafting table slot 0) is what the vanilla client shows. The 1.8 client computes results from its recipe book (ghast does not) and the server never sends them except in window_items; on 1.16.5 the server sends each new result as set_slot. The 1.12 client never computes results: the slot always holds what the server last sent (taking a result whose grid changed since is refused, its remainders depend on the recipes). While unknown, result clicks are ClickError::Unpredictable. 1.8 – 1.16.5 anvil and grindstone: whether ghast could compute the output like the client (false for inputs it cannot read, until the server’s set_slot).

Source

pub fn result_current(&self) -> bool

Whether the current screen’s crafting result belongs to the grid as it is now. 1.12: the server sent it and the grid has not changed since (a click that changes the grid leaves the old result in the slot until the server’s set_slot; taking such a stale result is ClickError::Unpredictable). 1.8 / 1.16.5: the same as result_known.

Source

pub fn pending(&self) -> bool

Whether a click waits for its confirm.

Source

pub fn resyncing(&self) -> bool

Whether the inventory waits for the server’s resync after a rejected click.

Source

pub fn can_click(&self) -> Result<(), ClickError>

Whether click would currently refuse for a reason other than the click itself.

Source§

impl Inventory

Source

pub fn on_trade_offers(&mut self, window_id: i32, offers: Vec<TradeOffer>)

1.8 – 1.16.5 villager screen: the server’s offers for window window_id (vanilla keeps them only while that window’s trading screen is open). The output is not looked up again until the next slot change, like vanilla. Inventory::apply_v1_8 / Inventory::apply_v1_12_2 (MC|TrList) and Inventory::apply_v1_16_5 (trade_list) call this.

Source

pub fn on_open_window_v1_16_5( &mut self, id: i32, menu_type: i32, title: ByteString, )

1.16.5 open_window by menu type id (WindowKind::from_v1_16_5); also remembers which recipes a furnace, blast furnace or smoker smelts (its shift-click reads them). Inventory::apply_v1_16_5 calls this.

Source

pub fn take_screen_packets(&mut self) -> Vec<Outgoing>

The packets the open screen sent by itself since the last call, to write before anything else this tick (the 1.16.5 anvil screen’s rename_item when its first input changed, also through a server packet). A click’s own packet comes after these.

Source

pub fn set_experience_level(&mut self, level: i32)

The player’s experience level (the 1.16.5 anvil’s cost check; also the 26.x anvil). Set from the experience packet (Inventory::apply_v1_16_5 does).

Source

pub fn experience_level(&self) -> i32

The experience level as the client holds it (taking an anvil result lowers it).

Source

pub fn set_creative(&mut self, creative: bool)

Creative mode (the 1.16.5 anvil: no level check, every enchantment fits; also 26.x). Set from the abilities packet (Inventory::apply_v1_16_5 does).

Source

pub fn anvil_cost(&self) -> Option<i32>

The 1.16.5 anvil’s level cost as the client holds it (None: no 1.16.5 anvil open).

Source

pub fn anvil_rename( &mut self, name: &str, ) -> Result<Option<Outgoing>, ClickError>

Anvil: types name into the name field like the screen (1.16.5: onRenamed; 26.x: as Inventory::anvil_rename_modern). Returns the rename_item / MC|ItemName to send (Ok(None): nothing is sent: no first input, or an empty name on 1.16.5). The field takes at most 35 characters (1.8.9: 30), without § and control characters. Typing exactly the item’s translated name is not recognised (ghast has no translations): it renames.

§Errors

ClickError::NoScreen when no anvil is open; ClickError::InvalidSlot for a name the field does not take; ClickError::Unpredictable when the result cannot be computed (an item name ghast cannot read).

Source

pub fn click_button( &mut self, index: i32, ) -> Result<Option<Outgoing>, ClickError>

1.16.5 menu buttons the client acts on itself (stonecutter recipe index, like its screen; Outgoing::ButtonClick is the packet to send). Ok(None): the menu does not take that button (nothing to send).

§Errors

ClickError::NoScreen when no such menu is open.

Source

pub fn set_mount_rules(&mut self, rules: Option<MountRules>)

1.8 – 1.16.5 mount screen (a Horse window): what its saddle and armor slots take, read off the entity like vanilla’s screen does (None: unknown, the default after the window opens; clicks that would need them are refused). Vanilla: 1.8 open_window EntityHorse names the entity; saddle always, horse armor for horse type 0. 1.12: saddle for all but llamas, horse armor for horses, carpets for llamas. 1.16.5 (open_horse_window): saddle for a tame adult (not a llama), horse armor for horses, carpets for llamas and trader llamas.

Source

pub fn mount_rules(&self) -> Option<MountRules>

The open mount screen’s rules (Inventory::set_mount_rules).

Source

pub fn on_trade_list_legacy(&mut self, data: &Bytes)

1.8 / 1.12 MC|TrList custom payload data (window id, then the offers).

Source

pub fn on_tags_v1_16_5(&mut self, p: &Tags)

1.16.5 tags: the item tags the beacon, furnace and llama slots read (the client uses the server’s; until they arrive those rules are refused as unpredictable). Inventory::apply_v1_16_5 calls this.

Source

pub fn on_trade_list_v1_16_5(&mut self, p: &TradeList)

1.16.5 trade_list.

Source

pub fn trade_offers(&self) -> Option<&[TradeOffer]>

The open villager screen’s offers as the client holds them (uses counted on the client), None when no villager screen is open or the server has not sent them (1.8 – 1.16.5).

Source

pub fn select_trade(&mut self, index: i32) -> Result<Outgoing, ClickError>

Villager screen: picks offer index like the screen’s arrows / trade buttons and returns the packet to send (1.8 / 1.12 MC|TrSel, 1.16.5 / 26.1 select_trade). 1.8 / 1.12: the output is looked up again for that offer (0 = the first offer that matches). 1.16.5: also the payments go back into the inventory and the offer’s own items come out of it (switchTo), as the screen does. 26.1: as Inventory::select_trade_modern.

§Errors

ClickError::NoScreen when no villager screen is open; ClickError::InvalidSlot when the offers are not known or index is not one of them.

Source§

impl Inventory

Source

pub fn new(version: Version) -> Result<Inventory, VersionNotEnabled>

An empty inventory (a fresh player entity).

§Errors

VersionNotEnabled when this build of the crate lacks the version’s feature (Version::is_enabled).

Source

pub fn set_click_timeout(&mut self, ticks: u32)

Sets how many ticks a click may wait for its confirm.

Source

pub fn set_click_settle_ticks(&mut self, ticks: u32)

26.1: how many ticks after a click without a correcting container packet make it ClickOutcome::Accepted. 26.1 has no confirm: the server applies the click when it receives it and answers in the same moment, with container_set_slot / container_set_content / set_cursor_item only for slots its result disagrees with, and with nothing when the client predicted right. So silence is the acceptance; set this to cover the round trip (ceil(rtt / 50 ms) + 1; default DEFAULT_CLICK_SETTLE_TICKS). A correction before that makes the click ClickOutcome::Rejected (already applied: no resync wait).

Source

pub fn version(&self) -> Version

The protocol version.

Source

pub fn enchantment_level(&self, stack: &Stack, name: &str) -> i32

The level of enchantment name (sharpness or minecraft:sharpness) on stack, on every version (1.8 / 1.12 numeric ids, 1.16.5 names, 26.x the server’s enchantment registry from Inventory::set_registries_modern); 0 when it has none.

Source

pub fn reset(&mut self)

A new player entity (join, respawn, dimension change): everything is cleared, including the action counters; the server resends the inventory. The selected hotbar slot restarts at 0 too (a new PlayerInventory).

Source

pub fn tick(&mut self)

Call once at the start of every client tick: resets the per-tick packet-order guard and ages the pending click.

Source

pub fn drain_events(&mut self) -> Events

Takes the accumulated change flags and click results.

Source§

impl Inventory

Source

pub fn encode_v26_1(&self, out: &Outgoing) -> Option<ServerboundPlayPacket>

Outgoing::to_v26_1 with this inventory’s registries.

Source

pub fn apply_v26_1(&mut self, p: &ClientboundPlayPacket)

Applies a 26.1 clientbound play packet: login / respawn, open_screen, container_close, container_set_content, container_set_slot, set_cursor_item, set_player_inventory, set_held_slot, container_set_data. Slots are converted through their encoding (use Inventory::apply_raw_modern to avoid decoding components at all).

Source

pub fn apply_raw_v26_1(&mut self, raw: &RawPacket) -> Result<(), DecodeError>

The 26.1 name of Inventory::apply_raw_modern (a 26.1 inventory’s packets).

§Errors

A malformed packet (nothing changed).

Source§

impl Inventory

Source

pub fn apply_v1_8(&mut self, p: &ClientboundPlayPacket) -> Option<Outgoing>

Applies a 1.8 clientbound play packet: login / respawn (new player entity), open_window, close_window, window_items, set_slot, transaction, held_item_slot, craft_progress_bar; everything else is ignored. Returns the confirm answer to send now, if any (see Inventory::on_transaction).

Source

pub fn apply_v1_12_2(&mut self, p: &ClientboundPlayPacket) -> Option<Outgoing>

Applies a 1.12.2 clientbound play packet, like apply_v1_8 (open_window types as WindowKind::from_v1_12_2 maps them).

Source

pub fn apply_v1_16_5(&mut self, p: &ClientboundPlayPacket) -> Option<Outgoing>

Applies a 1.16.5 clientbound play packet, like apply_v1_8 plus open_horse_window and declare_recipes.

Source§

impl Inventory

Source

pub fn apply_raw_modern(&mut self, raw: &RawPacket) -> Result<(), DecodeError>

Applies a modern window packet from its raw body (ids: crate::modern::packet_ids): slots are read with a structural skip and keep their components as bytes (nothing is decoded until an accessor asks). Dispatches on the inventory’s version; does nothing for a legacy inventory.

§Errors

A malformed packet (nothing changed).

Source

pub fn encode_modern(&self, out: &Outgoing) -> Option<RawPacket>

The serverbound packet of an Outgoing as raw id + body, for the inventory’s version (None for a legacy inventory, the legacy-only variants and Outgoing::Creative, whose packets Inventory::encode_creative_modern encodes one by one).

Source

pub fn encode_creative_modern(&self, p: &CreativePacket) -> Option<RawPacket>

One packet of Outgoing::Creative as raw id + body for the inventory’s version: swing (main hand) or set_creative_mode_slot (None for a legacy inventory).

Trait Implementations§

Source§

impl Clone for Inventory

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Inventory

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Inventory

§

impl Forget for Inventory

§

impl Move for Inventory

§

impl RefUnwindSafe for Inventory

§

impl Send for Inventory
where Bytes: Send, BoxRaw<ComponentPatch>: Send, RawVecInner: Send, Arc<CraftMemo>: Send, BoxRaw<Merchant>: Send, BoxRaw<Station>: Send, Arc<Book16>: Send, Arc<ItemTags16>: Send, Arc<RegistryNames>: Send, RawTable<((Reg, String), Vec<i32>)>: Send, BoxRaw<Lvl>: Send, BoxRaw<CreativeLegacy>: Send,

§

impl Sync for Inventory
where Bytes: Sync, BoxRaw<ComponentPatch>: Sync, RawVecInner: Sync, Arc<CraftMemo>: Sync, BoxRaw<Merchant>: Sync, BoxRaw<Station>: Sync, Arc<Book16>: Sync, Arc<ItemTags16>: Sync, Arc<RegistryNames>: Sync, RawTable<((Reg, String), Vec<i32>)>: Sync, BoxRaw<Lvl>: Sync, BoxRaw<CreativeLegacy>: Sync,

§

impl Unpin for Inventory
where *const u8: Unpin, Align8<*mut ()>: Unpin, &'static Vtable: Unpin, Box<ComponentPatch>: Unpin, *const u8 is !null: Unpin, Arc<CraftMemo>: Unpin, Box<Merchant>: Unpin, Box<Station>: Unpin, Arc<Book16>: Unpin, Arc<ItemTags16>: Unpin, Arc<RegistryNames>: Unpin, Box<Lvl>: Unpin, Box<CreativeLegacy>: Unpin,

§

impl UnsafeUnpin for Inventory
where *const u8: UnsafeUnpin, Align8<*mut ()>: UnsafeUnpin, &'static Vtable: UnsafeUnpin, *const ComponentPatch is !null: UnsafeUnpin, PhantomData<ComponentPatch>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<Option<Stack>>: UnsafeUnpin, *const ArcInner<CraftMemo> is !null: UnsafeUnpin, PhantomData<ArcInner<CraftMemo>>: UnsafeUnpin, *const Merchant is !null: UnsafeUnpin, PhantomData<Merchant>: UnsafeUnpin, *const Station is !null: UnsafeUnpin, PhantomData<Station>: UnsafeUnpin, PhantomData<Outgoing>: UnsafeUnpin, PhantomData<(i16, i16)>: UnsafeUnpin, PhantomData<ClickResult>: UnsafeUnpin, *const ArcInner<Book16> is !null: UnsafeUnpin, PhantomData<ArcInner<Book16>>: UnsafeUnpin, *const ArcInner<ItemTags16> is !null: UnsafeUnpin, PhantomData<ArcInner<ItemTags16>>: UnsafeUnpin, *const ArcInner<RegistryNames> is !null: UnsafeUnpin, PhantomData<ArcInner<RegistryNames>>: UnsafeUnpin, PhantomData<i32>: UnsafeUnpin, PhantomData<u16>: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<Offer>: UnsafeUnpin, PhantomData<CreativePacket>: UnsafeUnpin, PhantomData<((Reg, String), Vec<i32>)>: UnsafeUnpin, PhantomData<Option<Ench>>: UnsafeUnpin, PhantomData<String>: UnsafeUnpin, *const CreativeLegacy is !null: UnsafeUnpin, PhantomData<CreativeLegacy>: UnsafeUnpin,

§

impl UnwindSafe for Inventory
where *const u8: UnwindSafe, Align8<*mut ()>: UnwindSafe, &'static Vtable: UnwindSafe, BoxRaw<ComponentPatch>: UnwindSafe, RawVecInner: UnwindSafe, Arc<CraftMemo>: UnwindSafe, BoxRaw<Merchant>: UnwindSafe, BoxRaw<Station>: UnwindSafe, Arc<Book16>: UnwindSafe, Arc<ItemTags16>: UnwindSafe, Arc<RegistryNames>: UnwindSafe, HashMap<(Reg, String), Vec<i32>>: UnwindSafe, BoxRaw<Lvl>: UnwindSafe, BoxRaw<CreativeLegacy>: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.