Bag
What a player carries: the backpack's 16 slots, its side slots, the strap pockets, the belt's 4 cubes and both hands.
Items are where the player put them, slot by slot. Reading needs nothing. Changing needs player_data, and the player sees the change on their own pack at once.
A handle to something in the game. Once that thing is gone, its calls fail with Gone. You get one from player.bag().
Methods
| Method | Description |
|---|---|
fn get(&self, slot: BagSlot) -> Result<Option<ItemStack>>Optional<ItemStack> get(BagSlot slot) | What is in a slot. |
fn set(&self, slot: BagSlot, stack: Option<ItemStack>) -> Result<()>void set(BagSlot slot, ItemStack stack) player_data | Puts something in a slot, or empties it. |
fn add(&self, stack: ItemStack) -> Result<Option<ItemStack>>Optional<ItemStack> add(ItemStack stack) player_data | Puts items where they fit, backpack first; returns what did not fit. |
fn remove(&self, item: ItemType, count: i64) -> Result<i64>long remove(ItemType item, long count) player_data | Takes up to that many from anywhere; returns how many were taken. |
fn count(&self, item: ItemType) -> Result<i64>long count(ItemType item) | How many they carry, everywhere. |
fn all(&self) -> Result<Vec<BagEntry>>List<BagEntry> all() | Every slot that holds something. |
fn clear(&self) -> Result<()>void clear() player_data | Empties everything but the belt's cubes. |
BagSlot
A place in the bag: an area and a number in it.
Plain data, copied between the server and the plugin.
| Field | Description |
|---|---|
area: BagAreaBagArea area() | Which part of the bag. |
index: i64long index() | Which slot in it, from 0. |
BagEntry
One filled slot.
Plain data, copied between the server and the plugin.
BagArea
A part of the bag.
One of a fixed set of values.