Docs » API reference » Bag

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

MethodDescription
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_dataPuts something in a slot, or empties it.
fn add(&self, stack: ItemStack) -> Result<Option<ItemStack>>Optional<ItemStack> add(ItemStack stack) player_dataPuts 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_dataTakes 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_dataEmpties 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.

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

FieldDescription
slot: BagSlotBagSlot slot()Where.
stack: ItemStackItemStack stack()What.

BagArea

A part of the bag.

One of a fixed set of values.

ValueMeaning
BagArea::BackpackBagArea.BACKPACKInside the backpack (0 to 15).
BagArea::SideBagArea.SIDEThe holsters on its sides and the pockets on its straps.
BagArea::BeltBagArea.BELTThe belt's cubes (0 to 3).
BagArea::HandBagArea.HANDA hand (0 left, 1 right).