Cuberite
A lightweight, fast and extensible game server for Minecraft
|
This class represents the player's inventory The slots are divided into three areas: More...
#include <Inventory.h>
Public Types | |
enum | { invArmorCount = 4 , invInventoryCount = 9 * 3 , invHotbarCount = 9 , invShieldCount = 1 , invArmorOffset = 0 , invInventoryOffset = invArmorOffset + invArmorCount , invHotbarOffset = invInventoryOffset + invInventoryCount , invShieldOffset = invHotbarOffset + invHotbarCount , invNumSlots = invShieldOffset + invShieldCount } |
Public Member Functions | |
char | AddItem (const cItem &a_ItemStack, bool a_AllowNewStacks=true) |
Adds as many items out of a_ItemStack as can fit. More... | |
char | AddItems (cItems &a_ItemStackList, bool a_AllowNewStacks) |
Same as AddItem, but works on an entire list of item stacks. More... | |
char | ChangeSlotCount (int a_SlotNum, char a_AddToCount) |
Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot. More... | |
cInventory (cPlayer &a_Owner) | |
void | Clear (void) |
Removes all items from the entire inventory. More... | |
void | CopyToItems (cItems &a_Items) |
Copies the non-empty slots into a_ItemStacks; preserves the original a_Items contents. More... | |
bool | DamageEquippedItem (short a_Amount=1) |
Adds the specified damage to the currently held item; deletes the item and returns true if the item broke. More... | |
bool | DamageItem (int a_SlotNum, short a_Amount) |
Adds the specified damage to the specified item; deletes the item and returns true if the item broke. More... | |
cItem * | FindItem (const cItem &a_RecipeItem) |
Finds an item based on ItemType and ItemDamage (<- defines the itemType, too) More... | |
cItemGrid & | GetArmorGrid (void) |
Returns the cItemGrid object representing the armor slots. More... | |
const cItem & | GetArmorSlot (int a_ArmorSlotNum) const |
Returns current item in a_ArmorSlotNum in armor slots. More... | |
const cItem & | GetEquippedBoots (void) const |
const cItem & | GetEquippedChestplate (void) const |
const cItem & | GetEquippedHelmet (void) const |
const cItem & | GetEquippedItem (void) const |
Returns current equiped item. More... | |
const cItem & | GetEquippedLeggings (void) const |
int | GetEquippedSlotNum (void) |
Returns slot number of equiped item. More... | |
cItemGrid & | GetHotbarGrid (void) |
Returns the cItemGrid object representing the hotbar slots. More... | |
const cItem & | GetHotbarSlot (int a_HotBarSlotNum) const |
Returns current item in a_ArmorSlotNum in hotbar slots. More... | |
cItemGrid & | GetInventoryGrid (void) |
Returns the cItemGrid object representing the main inventory slots. More... | |
const cItem & | GetInventorySlot (int a_InventorySlotNum) const |
Returns current item in a_ArmorSlotNum in inventory slots. More... | |
cPlayer & | GetOwner (void) |
Returns the player associated with this inventory. More... | |
const cPlayer & | GetOwner (void) const |
Returns the player associated with this inventory (const version) More... | |
const cItem & | GetShieldSlot () const |
Returns current item in shield slot. More... | |
const cItem & | GetSlot (int a_SlotNum) const |
Returns current item in a_SlotNum slot. More... | |
bool | HasItems (const cItem &a_ItemStack) |
Returns true if there are at least as many items of type a_ItemStack as in a_ItemStack. More... | |
int | HowManyCanFit (const cItem &a_ItemStack, bool a_ConsiderEmptySlots=true) |
Returns number of items out of a_ItemStack that can fit in the storage. More... | |
int | HowManyCanFit (const cItem &a_ItemStack, int a_BeginSlotNum, int a_EndSlotNum, bool a_ConsiderEmptySlots=true) |
Returns how many items of the specified type would fit into the slot range specified. More... | |
int | HowManyItems (const cItem &a_Item) |
Returns the number of items of type a_Item that are stored. More... | |
bool | LoadFromJson (Json::Value &a_Value) |
int | RemoveItem (const cItem &a_ItemStack) |
Removes the specified item from the inventory, as many as possible, up to a_ItemStack.m_ItemCount. More... | |
bool | RemoveOneEquippedItem (void) |
Removes one item out of the currently equipped item stack, returns true if successful, false if empty-handed. More... | |
int | ReplaceOneEquippedItem (const cItem &a_Item, bool a_TryOtherSlots=true) |
Removes one item from the the current equipped item stack, and attempts to add the specified item stack back to the same slot. More... | |
void | SaveToJson (Json::Value &a_Value) |
void | SendEquippedSlot () |
Sends the equipped item slot to the client. More... | |
void | SendSlot (int a_SlotNum) |
Sends the slot contents to the owner. More... | |
void | SetArmorSlot (int a_ArmorSlotNum, const cItem &a_Item) |
Puts a_Item item in a_ArmorSlotNum slot number in armor slots. More... | |
void | SetEquippedItem (const cItem &a_Item) |
Sets current item in the equipped hotbar slot. More... | |
void | SetEquippedSlotNum (int a_SlotNum) |
Sets equiped item to the a_SlotNum slot number. More... | |
void | SetHotbarSlot (int a_HotBarSlotNum, const cItem &a_Item) |
Puts a_Item item in a_HotBarSlotNum slot number in hotbar slots. More... | |
void | SetInventorySlot (int a_InventorySlotNum, const cItem &a_Item) |
Puts a_Item item in a_InventorySlotNum slot number in inventory slots. More... | |
void | SetShieldSlot (const cItem &a_Item) |
Sets current item in shield slot. More... | |
void | SetSlot (int a_SlotNum, const cItem &a_Item) |
Puts a_Item item in a_SlotNum slot number. More... | |
void | UpdateItems (void) |
Update items (e.g. More... | |
virtual | ~cInventory () override |
Public Member Functions inherited from cItemGrid::cListener | |
virtual | ~cListener () |
Static Public Member Functions | |
static int | ArmorSlotNumToEntityEquipmentID (short a_ArmorSlotNum) |
Converts an armor slot number into the ID for the EntityEquipment packet. More... | |
Protected Member Functions | |
bool | AddToBar (cItem &a_Item, const int a_Offset, const int a_Size, bool *a_bChangedSlots, int a_Mode=0) |
cItemGrid * | GetGridForSlotNum (int a_SlotNum, int &a_GridSlotNum) |
Returns the ItemGrid and the (grid-local) slot number for a (global) slot number; return nullptr for invalid SlotNum. More... | |
const cItemGrid * | GetGridForSlotNum (int a_SlotNum, int &a_GridSlotNum) const |
Returns the ItemGrid and the (grid-local) slot number for a (global) slot number; return nullptr for invalid SlotNum. More... | |
virtual void | OnSlotChanged (cItemGrid *a_ItemGrid, int a_SlotNum) override |
Called whenever a slot changes. More... | |
Protected Attributes | |
cItemGrid | m_ArmorSlots |
int | m_EquippedSlotNum |
cItemGrid | m_HotbarSlots |
cItemGrid | m_InventorySlots |
cPlayer & | m_Owner |
cItemGrid | m_ShieldSlots |
This class represents the player's inventory The slots are divided into three areas:
Definition at line 32 of file Inventory.h.
anonymous enum |
Enumerator | |
---|---|
invArmorCount | |
invInventoryCount | |
invHotbarCount | |
invShieldCount | |
invArmorOffset | |
invInventoryOffset | |
invHotbarOffset | |
invShieldOffset | |
invNumSlots |
Definition at line 40 of file Inventory.h.
cInventory::cInventory | ( | cPlayer & | a_Owner | ) |
Definition at line 20 of file Inventory.cpp.
|
inlineoverridevirtual |
Definition at line 58 of file Inventory.h.
char cInventory::AddItem | ( | const cItem & | a_ItemStack, |
bool | a_AllowNewStacks = true |
||
) |
Adds as many items out of a_ItemStack as can fit.
If a_AllowNewStacks is set to false, only existing stacks can be topped up; if a_AllowNewStacks is set to true, empty slots can be used for the rest. Fills existing stacks first and fills the hotbar before the main inventory. Returns the number of items that fit.
Definition at line 106 of file Inventory.cpp.
char cInventory::AddItems | ( | cItems & | a_ItemStackList, |
bool | a_AllowNewStacks | ||
) |
Same as AddItem, but works on an entire list of item stacks.
The a_ItemStackList is modified to reflect the leftover items. If a_AllowNewStacks is set to false, only existing stacks can be topped up; if a_AllowNewStacks is set to true, empty slots can be used for the rest. Returns the total number of items that fit.
Definition at line 165 of file Inventory.cpp.
|
protected |
|
static |
Converts an armor slot number into the ID for the EntityEquipment packet.
Definition at line 611 of file Inventory.cpp.
char cInventory::ChangeSlotCount | ( | int | a_SlotNum, |
char | a_AddToCount | ||
) |
Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot.
If the slot is empty, ignores the call. Returns the new count, or -1 if the slot number is invalid.
Definition at line 498 of file Inventory.cpp.
void cInventory::Clear | ( | void | ) |
Removes all items from the entire inventory.
Definition at line 40 of file Inventory.cpp.
void cInventory::CopyToItems | ( | cItems & | a_Items | ) |
Copies the non-empty slots into a_ItemStacks; preserves the original a_Items contents.
Definition at line 549 of file Inventory.cpp.
bool cInventory::DamageEquippedItem | ( | short | a_Amount = 1 | ) |
Adds the specified damage to the currently held item; deletes the item and returns true if the item broke.
Definition at line 489 of file Inventory.cpp.
bool cInventory::DamageItem | ( | int | a_SlotNum, |
short | a_Amount | ||
) |
Adds the specified damage to the specified item; deletes the item and returns true if the item broke.
Definition at line 514 of file Inventory.cpp.
Finds an item based on ItemType and ItemDamage (<- defines the itemType, too)
Definition at line 212 of file Inventory.cpp.
|
inline |
Returns the cItemGrid object representing the armor slots.
Definition at line 114 of file Inventory.h.
const cItem & cInventory::GetArmorSlot | ( | int | a_ArmorSlotNum | ) | const |
Returns current item in a_ArmorSlotNum in armor slots.
Definition at line 412 of file Inventory.cpp.
|
inline |
Definition at line 179 of file Inventory.h.
|
inline |
Definition at line 177 of file Inventory.h.
|
inline |
Definition at line 176 of file Inventory.h.
const cItem & cInventory::GetEquippedItem | ( | void | ) | const |
Returns current equiped item.
Definition at line 463 of file Inventory.cpp.
|
inline |
Definition at line 178 of file Inventory.h.
|
inline |
Returns slot number of equiped item.
Definition at line 162 of file Inventory.h.
|
protected |
Returns the ItemGrid and the (grid-local) slot number for a (global) slot number; return nullptr for invalid SlotNum.
Definition at line 806 of file Inventory.cpp.
|
protected |
Returns the ItemGrid and the (grid-local) slot number for a (global) slot number; return nullptr for invalid SlotNum.
Definition at line 777 of file Inventory.cpp.
|
inline |
Returns the cItemGrid object representing the hotbar slots.
Definition at line 120 of file Inventory.h.
const cItem & cInventory::GetHotbarSlot | ( | int | a_HotBarSlotNum | ) | const |
Returns current item in a_ArmorSlotNum in hotbar slots.
Definition at line 440 of file Inventory.cpp.
|
inline |
Returns the cItemGrid object representing the main inventory slots.
Definition at line 117 of file Inventory.h.
const cItem & cInventory::GetInventorySlot | ( | int | a_InventorySlotNum | ) | const |
Returns current item in a_ArmorSlotNum in inventory slots.
Definition at line 426 of file Inventory.cpp.
|
inline |
Returns the player associated with this inventory.
Definition at line 123 of file Inventory.h.
|
inline |
Returns the player associated with this inventory (const version)
Definition at line 131 of file Inventory.h.
const cItem & cInventory::GetShieldSlot | ( | ) | const |
Returns current item in shield slot.
Definition at line 454 of file Inventory.cpp.
const cItem & cInventory::GetSlot | ( | int | a_SlotNum | ) | const |
Returns current item in a_SlotNum slot.
Definition at line 390 of file Inventory.cpp.
bool cInventory::HasItems | ( | const cItem & | a_ItemStack | ) |
Returns true if there are at least as many items of type a_ItemStack as in a_ItemStack.
Definition at line 303 of file Inventory.cpp.
int cInventory::HowManyCanFit | ( | const cItem & | a_ItemStack, |
bool | a_ConsiderEmptySlots = true |
||
) |
Returns number of items out of a_ItemStack that can fit in the storage.
Definition at line 52 of file Inventory.cpp.
int cInventory::HowManyCanFit | ( | const cItem & | a_ItemStack, |
int | a_BeginSlotNum, | ||
int | a_EndSlotNum, | ||
bool | a_ConsiderEmptySlots = true |
||
) |
Returns how many items of the specified type would fit into the slot range specified.
Definition at line 61 of file Inventory.cpp.
int cInventory::HowManyItems | ( | const cItem & | a_Item | ) |
Returns the number of items of type a_Item that are stored.
Definition at line 290 of file Inventory.cpp.
bool cInventory::LoadFromJson | ( | Json::Value & | a_Value | ) |
Definition at line 744 of file Inventory.cpp.
|
overrideprotectedvirtual |
Called whenever a slot changes.
Implements cItemGrid::cListener.
Definition at line 835 of file Inventory.cpp.
int cInventory::RemoveItem | ( | const cItem & | a_ItemStack | ) |
Removes the specified item from the inventory, as many as possible, up to a_ItemStack.m_ItemCount.
Returns the number of items that were removed.
Definition at line 189 of file Inventory.cpp.
bool cInventory::RemoveOneEquippedItem | ( | void | ) |
Removes one item out of the currently equipped item stack, returns true if successful, false if empty-handed.
Definition at line 232 of file Inventory.cpp.
int cInventory::ReplaceOneEquippedItem | ( | const cItem & | a_Item, |
bool | a_TryOtherSlots = true |
||
) |
Removes one item from the the current equipped item stack, and attempts to add the specified item stack back to the same slot.
If it is not possible to place the item in the same slot, optionally (default true) tries to place the specified item elsewhere in the inventory. Returns the number of items successfully added. If the currently equipped slot is empty, its contents are simply set to the given Item.
Definition at line 247 of file Inventory.cpp.
void cInventory::SaveToJson | ( | Json::Value & | a_Value | ) |
Definition at line 699 of file Inventory.cpp.
void cInventory::SendEquippedSlot | ( | ) |
Sends the equipped item slot to the client.
Definition at line 380 of file Inventory.cpp.
void cInventory::SendSlot | ( | int | a_SlotNum | ) |
Sends the slot contents to the owner.
Definition at line 560 of file Inventory.cpp.
void cInventory::SetArmorSlot | ( | int | a_ArmorSlotNum, |
const cItem & | a_Item | ||
) |
Puts a_Item item in a_ArmorSlotNum slot number in armor slots.
Definition at line 335 of file Inventory.cpp.
void cInventory::SetEquippedItem | ( | const cItem & | a_Item | ) |
Sets current item in the equipped hotbar slot.
Definition at line 371 of file Inventory.cpp.
void cInventory::SetEquippedSlotNum | ( | int | a_SlotNum | ) |
Sets equiped item to the a_SlotNum slot number.
Definition at line 472 of file Inventory.cpp.
void cInventory::SetHotbarSlot | ( | int | a_HotBarSlotNum, |
const cItem & | a_Item | ||
) |
Puts a_Item item in a_HotBarSlotNum slot number in hotbar slots.
Definition at line 353 of file Inventory.cpp.
void cInventory::SetInventorySlot | ( | int | a_InventorySlotNum, |
const cItem & | a_Item | ||
) |
Puts a_Item item in a_InventorySlotNum slot number in inventory slots.
Definition at line 344 of file Inventory.cpp.
void cInventory::SetShieldSlot | ( | const cItem & | a_Item | ) |
Sets current item in shield slot.
Definition at line 362 of file Inventory.cpp.
void cInventory::SetSlot | ( | int | a_SlotNum, |
const cItem & | a_Item | ||
) |
Puts a_Item item in a_SlotNum slot number.
Definition at line 313 of file Inventory.cpp.
void cInventory::UpdateItems | ( | void | ) |
|
protected |
Definition at line 198 of file Inventory.h.
|
protected |
Definition at line 203 of file Inventory.h.
|
protected |
Definition at line 200 of file Inventory.h.
|
protected |
Definition at line 199 of file Inventory.h.
|
protected |
Definition at line 205 of file Inventory.h.
|
protected |
Definition at line 201 of file Inventory.h.