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.
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.
Sourcepub fn set_registries_26_1(&mut self, reg: HashRegistries)
👎Deprecated since 0.5.3: use set_registries_modern
pub fn set_registries_26_1(&mut self, reg: HashRegistries)
use set_registries_modern
Alias of Inventory::set_registries_modern.
Sourcepub fn registries_26_1(&self) -> &HashRegistries
👎Deprecated since 0.5.3: use registries_modern
pub fn registries_26_1(&self) -> &HashRegistries
use registries_modern
Alias of Inventory::registries_modern.
Sourcepub fn enchantment_name_26_1(&self, id: i32) -> Option<&str>
👎Deprecated since 0.5.3: use enchantment_name_modern
pub fn enchantment_name_26_1(&self, id: i32) -> Option<&str>
use enchantment_name_modern
Alias of Inventory::enchantment_name_modern.
Sourcepub fn set_creative_26_1(&mut self, creative: bool)
👎Deprecated since 0.5.3: use set_creative_modern
pub fn set_creative_26_1(&mut self, creative: bool)
use set_creative_modern
Alias of Inventory::set_creative_modern.
👎Deprecated since 0.5.3: use on_update_tags_modern
use on_update_tags_modern
Alias of Inventory::on_update_tags_modern.
Sourcepub fn on_registry_data_26_1(&mut self, body: Bytes)
👎Deprecated since 0.5.3: use on_registry_data_modern
pub fn on_registry_data_26_1(&mut self, body: Bytes)
use on_registry_data_modern
Alias of Inventory::on_registry_data_modern.
Sourcepub 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
pub fn on_mount_screen_26_1( &mut self, window_id: i32, columns: i32, entity_type: i32, can_saddle: bool, can_body: bool, )
use on_mount_screen_modern
Alias of Inventory::on_mount_screen_modern.
Sourcepub fn on_merchant_offers_26_1(&mut self, body: &Bytes)
👎Deprecated since 0.5.3: use on_merchant_offers_modern
pub fn on_merchant_offers_26_1(&mut self, body: &Bytes)
use on_merchant_offers_modern
Alias of Inventory::on_merchant_offers_modern.
Sourcepub fn anvil_rename_26_1(
&mut self,
name: &str,
) -> Result<Option<Outgoing>, ClickError>
👎Deprecated since 0.5.3: use anvil_rename_modern
pub fn anvil_rename_26_1( &mut self, name: &str, ) -> Result<Option<Outgoing>, ClickError>
use anvil_rename_modern
Sourcepub fn trident_spin_attack_strength_26_1(
&mut self,
stack: &Stack,
) -> Option<f32>
👎Deprecated since 0.5.3: use trident_spin_attack_strength_modern
pub fn trident_spin_attack_strength_26_1( &mut self, stack: &Stack, ) -> Option<f32>
use trident_spin_attack_strength_modern
Sourcepub fn select_loom_pattern_26_1(
&mut self,
index: i32,
) -> Result<Option<Outgoing>, ClickError>
👎Deprecated since 0.5.3: use select_loom_pattern_modern
pub fn select_loom_pattern_26_1( &mut self, index: i32, ) -> Result<Option<Outgoing>, ClickError>
use select_loom_pattern_modern
Sourcepub fn select_trade_26_1(&mut self, index: i32) -> Result<Outgoing, ClickError>
👎Deprecated since 0.5.3: use select_trade_modern
pub fn select_trade_26_1(&mut self, index: i32) -> Result<Outgoing, ClickError>
use select_trade_modern
Sourcepub fn take_creative_echo_26_1(&mut self) -> Vec<CreativePacket>
👎Deprecated since 0.5.3: use take_creative_echo_modern
pub fn take_creative_echo_26_1(&mut self) -> Vec<CreativePacket>
use take_creative_echo_modern
Alias of Inventory::take_creative_echo_modern.
Sourcepub fn creative_screen_26_1(&self) -> bool
👎Deprecated since 0.5.3: use creative_screen_modern
pub fn creative_screen_26_1(&self) -> bool
use creative_screen_modern
Alias of Inventory::creative_screen_modern.
Sourcepub fn set_experience_level_26_1(&mut self, level: i32)
👎Deprecated since 0.5.3: use set_experience_level_modern
pub fn set_experience_level_26_1(&mut self, level: i32)
use set_experience_level_modern
Alias of Inventory::set_experience_level_modern.
Sourcepub 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
pub fn on_recipes_26_1<'a>( &mut self, sets: impl IntoIterator<Item = (&'a str, &'a [i32])>, stonecutter_inputs: Option<Vec<i32>>, )
use on_recipes_modern
Alias of Inventory::on_recipes_modern.
Sourcepub fn on_open_screen_26_1(&mut self, id: i32, menu: i32, title: ByteString)
👎Deprecated since 0.5.3: use on_open_screen_modern
pub fn on_open_screen_26_1(&mut self, id: i32, menu: i32, title: ByteString)
use on_open_screen_modern
Alias of Inventory::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).
impl Inventory
The 0.4.1 names of the modern slot packets (they exist in every build, like 0.4.1’s).
Sourcepub 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
pub fn on_window_items_26_1( &mut self, window_id: i32, state_id: i32, items: impl IntoIterator<Item = Option<Stack>>, carried: Option<Stack>, )
use on_window_items_modern
Alias of Inventory::on_window_items_modern.
Sourcepub 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
pub fn on_set_slot_26_1( &mut self, window_id: i32, state_id: i32, slot: i16, item: Option<Stack>, )
use on_set_slot_modern
Alias of Inventory::on_set_slot_modern.
Source§impl Inventory
impl Inventory
Sourcepub fn click(&mut self, click: Click) -> Result<Outgoing, ClickError>
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).
Sourcepub fn open_inventory(&mut self) -> Result<Option<Outgoing>, ClickError>
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.
Sourcepub fn close(&mut self) -> Result<Outgoing, ClickError>
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
impl Inventory
Sourcepub fn creative_screen_legacy(&self) -> Option<CreativeTab>
pub fn creative_screen_legacy(&self) -> Option<CreativeTab>
Whether the open screen is the legacy creative inventory screen, and its tab.
Sourcepub fn creative_delete_slot(&self) -> i16
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.
Sourcepub fn take_creative_echo_legacy(&mut self) -> Vec<CreativePacket>
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.
Sourcepub fn set_creative_tab_legacy(&mut self, tab: CreativeTab)
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.
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.
Sourcepub fn pick_block_legacy(
&mut self,
pick: &Stack,
has_data: bool,
) -> Result<Option<Outgoing>, ClickError>
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.
Sourcepub fn creative_load_hotbar_legacy(
&mut self,
saved: &[Option<Stack>; 9],
) -> Result<Outgoing, ClickError>
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
impl Inventory
Sourcepub fn consume_held(&mut self, n: u8) -> bool
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.
Sourcepub fn damage_held(&mut self, amount: u16) -> bool
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).
Sourcepub fn consume_offhand(&mut self, n: u8) -> bool
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).
Sourcepub fn finish_into(&mut self, off_hand: bool, container: i32) -> bool
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.
Sourcepub fn exchange_hand(
&mut self,
off_hand: bool,
output: Stack,
creative: bool,
creative_keeps: bool,
) -> bool
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).
Sourcepub fn set_hand(&mut self, off_hand: bool, stack: Option<Stack>)
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).
Sourcepub fn use_equips(&self, off_hand: bool, creative: bool) -> bool
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.
Sourcepub fn equip_from_hand(&mut self, off_hand: bool, creative: bool) -> bool
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).
Sourcepub fn drop_held(&mut self, whole_stack: bool) -> bool
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§impl Inventory
impl Inventory
Sourcepub fn on_held_slot(&mut self, slot: i8)
pub fn on_held_slot(&mut self, slot: i8)
held_item_slot from the server.
Sourcepub fn on_open_window(
&mut self,
id: i32,
kind: Option<WindowKind>,
title: ByteString,
)
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.
Sourcepub fn on_close_window(&mut self)
pub fn on_close_window(&mut self)
close_window from the server (closes whatever is open, whatever the id).
Sourcepub fn on_window_items(
&mut self,
window_id: i32,
items: impl IntoIterator<Item = Option<Stack>>,
)
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).
Sourcepub fn on_set_slot(&mut self, window_id: i32, slot: i16, item: Option<Stack>)
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.
Sourcepub fn on_window_items_modern(
&mut self,
window_id: i32,
state_id: i32,
items: impl IntoIterator<Item = Option<Stack>>,
carried: Option<Stack>,
)
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).
Sourcepub fn on_set_slot_modern(
&mut self,
window_id: i32,
state_id: i32,
slot: i16,
item: Option<Stack>,
)
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.
Sourcepub fn on_set_cursor(&mut self, item: Option<Stack>)
pub fn on_set_cursor(&mut self, item: Option<Stack>)
26.1 set_cursor_item: the open menu’s carried stack.
Sourcepub fn on_set_player_inventory(&mut self, slot: i32, item: Option<Stack>)
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).
Sourcepub fn recipes(&self) -> &RecipeBook
pub fn recipes(&self) -> &RecipeBook
The crafting recipes the server declared (1.16.5; 1.8 clients know theirs).
Sourcepub fn clear_server_data(&mut self)
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).
Sourcepub fn on_declare_recipes(&mut self, book: RecipeBook)
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).
Sourcepub fn on_window_property(&mut self, window_id: i32, property: i16, value: i16)
pub fn on_window_property(&mut self, window_id: i32, property: i16, value: i16)
craft_progress_bar (window property).
Sourcepub fn on_transaction(
&mut self,
window_id: i8,
action: i16,
accepted: bool,
) -> Option<Outgoing>
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
impl Inventory
Sourcepub fn set_registries_modern(&mut self, reg: HashRegistries)
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.
Sourcepub fn registries_modern(&self) -> &HashRegistries
pub fn registries_modern(&self) -> &HashRegistries
26.1: the registry names set with Inventory::set_registries_modern.
Sourcepub fn enchantment_name_modern(&self, id: i32) -> Option<&str>
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.
Sourcepub fn set_creative_modern(&mut self, creative: bool)
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.
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.
Sourcepub fn on_registry_data_modern(&mut self, body: Bytes)
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.
Sourcepub fn on_mount_screen_modern(
&mut self,
window_id: i32,
columns: i32,
entity_type: i32,
can_saddle: bool,
can_body: bool,
)
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).
Sourcepub fn on_merchant_offers_modern(&mut self, body: &Bytes)
pub fn on_merchant_offers_modern(&mut self, body: &Bytes)
26.1 merchant_offers: the open villager screen’s offers.
Sourcepub fn anvil_rename_modern(
&mut self,
name: &str,
) -> Result<Option<Outgoing>, ClickError>
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.
Sourcepub fn trident_spin_attack_strength_modern(
&mut self,
stack: &Stack,
) -> Option<f32>
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).
Sourcepub fn select_loom_pattern_modern(
&mut self,
index: i32,
) -> Result<Option<Outgoing>, ClickError>
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.
Sourcepub fn select_trade_modern(
&mut self,
index: i32,
) -> Result<Outgoing, ClickError>
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.
Sourcepub fn take_creative_echo_modern(&mut self) -> Vec<CreativePacket>
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.
Sourcepub fn creative_screen_modern(&self) -> bool
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.
Sourcepub fn set_experience_level_modern(&mut self, level: i32)
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.
Sourcepub fn on_recipes_modern<'a>(
&mut self,
sets: impl IntoIterator<Item = (&'a str, &'a [i32])>,
stonecutter_inputs: Option<Vec<i32>>,
)
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).
Sourcepub fn on_open_screen_modern(&mut self, id: i32, menu: i32, title: ByteString)
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
impl Inventory
Sourcepub fn player(&self, index: usize) -> Option<&Stack>
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).
Sourcepub fn held_writes(&self) -> u16
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.
Sourcepub fn offhand_writes(&self) -> u16
pub fn offhand_writes(&self) -> u16
Inventory::held_writes for the off-hand slot (1.12 / 1.16.5).
Sourcepub fn take_player_touched(&mut self) -> bool
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.
Sourcepub fn gui_open(&self) -> bool
pub fn gui_open(&self) -> bool
Whether a GUI is open (a container window or the player inventory).
Sourcepub fn inventory_open(&self) -> bool
pub fn inventory_open(&self) -> bool
Whether the player inventory GUI is open (no container window).
Sourcepub fn slot_count(&self) -> usize
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).
Sourcepub fn container_len(&self) -> usize
pub fn container_len(&self) -> usize
Container slots of the open window (before the player’s 36), 0 for window 0.
Sourcepub fn slot(&self, i: usize) -> Option<&Stack>
pub fn slot(&self, i: usize) -> Option<&Stack>
Slot i of the current screen (window 0 layout when no container is open).
Sourcepub fn window0_slot(&self, i: usize) -> Option<&Stack>
pub fn window0_slot(&self, i: usize) -> Option<&Stack>
Slot i of window 0 (PlayerScreenHandler numbering), whatever is open.
Sourcepub fn slot_of_player(&self, k: usize) -> Option<i16>
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).
Sourcepub fn find(&self, pred: impl FnMut(&Stack) -> bool) -> Option<i16>
pub fn find(&self, pred: impl FnMut(&Stack) -> bool) -> Option<i16>
First slot of the current screen whose stack matches.
Sourcepub fn count(&self, pred: impl FnMut(&Stack) -> bool) -> i32
pub fn count(&self, pred: impl FnMut(&Stack) -> bool) -> i32
Total count of matching stacks in the player inventory (hotbar, main, armor, offhand).
Sourcepub fn result_known(&self) -> bool
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).
Sourcepub fn result_current(&self) -> bool
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§impl Inventory
impl Inventory
Sourcepub fn on_trade_offers(&mut self, window_id: i32, offers: Vec<TradeOffer>)
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.
Sourcepub fn on_open_window_v1_16_5(
&mut self,
id: i32,
menu_type: i32,
title: ByteString,
)
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.
Sourcepub fn take_screen_packets(&mut self) -> Vec<Outgoing>
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.
Sourcepub fn set_experience_level(&mut self, level: i32)
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).
Sourcepub fn experience_level(&self) -> i32
pub fn experience_level(&self) -> i32
The experience level as the client holds it (taking an anvil result lowers it).
Sourcepub fn set_creative(&mut self, creative: bool)
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).
Sourcepub fn anvil_cost(&self) -> Option<i32>
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).
Sourcepub fn anvil_rename(
&mut self,
name: &str,
) -> Result<Option<Outgoing>, ClickError>
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).
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.
Sourcepub fn set_mount_rules(&mut self, rules: Option<MountRules>)
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.
Sourcepub fn mount_rules(&self) -> Option<MountRules>
pub fn mount_rules(&self) -> Option<MountRules>
The open mount screen’s rules (Inventory::set_mount_rules).
Sourcepub fn on_trade_list_legacy(&mut self, data: &Bytes)
pub fn on_trade_list_legacy(&mut self, data: &Bytes)
1.8 / 1.12 MC|TrList custom payload data (window id, then the offers).
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.
Sourcepub fn on_trade_list_v1_16_5(&mut self, p: &TradeList)
pub fn on_trade_list_v1_16_5(&mut self, p: &TradeList)
1.16.5 trade_list.
Sourcepub fn trade_offers(&self) -> Option<&[TradeOffer]>
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).
Sourcepub fn select_trade(&mut self, index: i32) -> Result<Outgoing, ClickError>
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
impl Inventory
Sourcepub fn new(version: Version) -> Result<Inventory, VersionNotEnabled>
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).
Sourcepub fn set_click_timeout(&mut self, ticks: u32)
pub fn set_click_timeout(&mut self, ticks: u32)
Sets how many ticks a click may wait for its confirm.
Sourcepub fn set_click_settle_ticks(&mut self, ticks: u32)
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).
Sourcepub fn enchantment_level(&self, stack: &Stack, name: &str) -> i32
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.
Sourcepub fn reset(&mut self)
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).
Sourcepub fn tick(&mut self)
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.
Sourcepub fn drain_events(&mut self) -> Events
pub fn drain_events(&mut self) -> Events
Takes the accumulated change flags and click results.
Source§impl Inventory
impl Inventory
Sourcepub fn encode_v26_1(&self, out: &Outgoing) -> Option<ServerboundPlayPacket>
pub fn encode_v26_1(&self, out: &Outgoing) -> Option<ServerboundPlayPacket>
Outgoing::to_v26_1 with this inventory’s registries.
Sourcepub fn apply_v26_1(&mut self, p: &ClientboundPlayPacket)
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).
Sourcepub fn apply_raw_v26_1(&mut self, raw: &RawPacket) -> Result<(), DecodeError>
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
impl Inventory
Sourcepub fn apply_v1_8(&mut self, p: &ClientboundPlayPacket) -> Option<Outgoing>
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).
Sourcepub fn apply_v1_12_2(&mut self, p: &ClientboundPlayPacket) -> Option<Outgoing>
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).
Sourcepub fn apply_v1_16_5(&mut self, p: &ClientboundPlayPacket) -> Option<Outgoing>
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
impl Inventory
Sourcepub fn apply_raw_modern(&mut self, raw: &RawPacket) -> Result<(), DecodeError>
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).
Sourcepub fn encode_modern(&self, out: &Outgoing) -> Option<RawPacket>
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).
Sourcepub fn encode_creative_modern(&self, p: &CreativePacket) -> Option<RawPacket>
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).