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 | |
int | AddItem (const cItem &a_ItemStack, bool a_AllowNewStacks=true) |
Adds as many items out of a_ItemStack as can fit. More... | |
int | AddItems (cItems &a_ItemStackList, bool a_AllowNewStacks) |
Same as AddItem, but works on an entire list of item stacks. More... | |
int | ChangeSlotCount (int a_SlotNum, int 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... | |
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... | |
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 | 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) |
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... | |
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... | |
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.
int 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. Returns the number of items that fit.
Definition at line 106 of file Inventory.cpp.
int 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 160 of file Inventory.cpp.
|
protected |
|
static |
Converts an armor slot number into the ID for the EntityEquipment packet.
Definition at line 534 of file Inventory.cpp.
int cInventory::ChangeSlotCount | ( | int | a_SlotNum, |
int | 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 421 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 472 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 412 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 437 of file Inventory.cpp.
|
inline |
Returns the cItemGrid object representing the armor slots.
Definition at line 103 of file Inventory.h.
const cItem & cInventory::GetArmorSlot | ( | int | a_ArmorSlotNum | ) | const |
Returns current item in a_ArmorSlotNum in armor slots.
Definition at line 335 of file Inventory.cpp.
|
inline |
Definition at line 166 of file Inventory.h.
|
inline |
Definition at line 164 of file Inventory.h.
|
inline |
Definition at line 163 of file Inventory.h.
const cItem & cInventory::GetEquippedItem | ( | void | ) | const |
Returns current equiped item.
Definition at line 386 of file Inventory.cpp.
|
inline |
Definition at line 165 of file Inventory.h.
|
inline |
Returns slot number of equiped item.
Definition at line 149 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 700 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 729 of file Inventory.cpp.
|
inline |
Returns the cItemGrid object representing the hotbar slots.
Definition at line 109 of file Inventory.h.
const cItem & cInventory::GetHotbarSlot | ( | int | a_HotBarSlotNum | ) | const |
Returns current item in a_ArmorSlotNum in hotbar slots.
Definition at line 363 of file Inventory.cpp.
|
inline |
Returns the cItemGrid object representing the main inventory slots.
Definition at line 106 of file Inventory.h.
const cItem & cInventory::GetInventorySlot | ( | int | a_InventorySlotNum | ) | const |
Returns current item in a_ArmorSlotNum in inventory slots.
Definition at line 349 of file Inventory.cpp.
|
inline |
Returns the player associated with this inventory.
Definition at line 112 of file Inventory.h.
|
inline |
Returns the player associated with this inventory (const version)
Definition at line 120 of file Inventory.h.
const cItem & cInventory::GetShieldSlot | ( | ) | const |
Returns current item in shield slot.
Definition at line 377 of file Inventory.cpp.
const cItem & cInventory::GetSlot | ( | int | a_SlotNum | ) | const |
Returns current item in a_SlotNum slot.
Definition at line 313 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 235 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 222 of file Inventory.cpp.
bool cInventory::LoadFromJson | ( | Json::Value & | a_Value | ) |
Definition at line 667 of file Inventory.cpp.
|
overrideprotectedvirtual |
Called whenever a slot changes.
Implements cItemGrid::cListener.
Definition at line 758 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 184 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 207 of file Inventory.cpp.
void cInventory::SaveToJson | ( | Json::Value & | a_Value | ) |
Definition at line 622 of file Inventory.cpp.
void cInventory::SendEquippedSlot | ( | ) |
Sends the equipped item slot to the client.
Definition at line 303 of file Inventory.cpp.
void cInventory::SendSlot | ( | int | a_SlotNum | ) |
Sends the slot contents to the owner.
Definition at line 483 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 267 of file Inventory.cpp.
void cInventory::SetEquippedSlotNum | ( | int | a_SlotNum | ) |
Sets equiped item to the a_SlotNum slot number.
Definition at line 395 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 285 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 276 of file Inventory.cpp.
void cInventory::SetShieldSlot | ( | const cItem & | a_Item | ) |
Sets current item in shield slot.
Definition at line 294 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 245 of file Inventory.cpp.
void cInventory::UpdateItems | ( | void | ) |
|
protected |
Definition at line 185 of file Inventory.h.
|
protected |
Definition at line 190 of file Inventory.h.
|
protected |
Definition at line 187 of file Inventory.h.
|
protected |
Definition at line 186 of file Inventory.h.
|
protected |
Definition at line 192 of file Inventory.h.
|
protected |
Definition at line 188 of file Inventory.h.