Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
cItem Class Reference

#include <Item.h>

Collaboration diagram for cItem:
Collaboration graph
[legend]

Classes

struct  sItemCompare
 Compares two items for the same type or category. More...
 

Public Member Functions

cItemAddCount (char a_AmountToAdd)
 Adds the specified count to this object and returns the reference to self (useful for chaining) More...
 
int AddEnchantment (int a_EnchantmentID, unsigned int a_Level, bool a_FromBook)
 Adds this specific enchantment to this item, returning the cost. More...
 
int AddEnchantmentsFromItem (const cItem &a_Other)
 Adds the enchantments on a_Other to this item, returning the XP cost of the transfer. More...
 
bool CanHaveEnchantment (int a_EnchantmentID)
 Returns whether or not this item is allowed to have the given enchantment. More...
 
 cItem (short a_ItemType, char a_ItemCount=1, short a_ItemDamage=0, const AString &a_Enchantments="", const AString &a_CustomName="", const AStringVector &a_LoreTable={})
 Creates an item of the specified type, by default 1 piece with no damage and no enchantments. More...
 
 cItem (void)
 Creates an empty item. More...
 
void Clear (void)
 Empties the item and frees up any dynamic storage used by the internals. More...
 
cItem CopyOne (void) const
 Returns a copy of this item with m_ItemCount set to 1. More...
 
bool DamageItem (short a_Amount=1)
 Damages a weapon / tool. More...
 
void Empty (void)
 Empties the item and frees up any dynamic storage used by the internals. More...
 
bool EnchantByXPLevels (unsigned a_NumXPLevels, MTRand &a_Random)
 Randomly enchants the item using the specified number of XP levels. More...
 
void FromJson (const Json::Value &a_Value)
 Loads the item data from JSON representation. More...
 
unsigned GetEnchantability ()
 Returns the enchantability of the item. More...
 
const cItemHandlerGetHandler (void) const
 Returns the cItemHandler responsible for this item type. More...
 
void GetJson (Json::Value &a_OutValue) const
 Saves the item data into JSON representation. More...
 
short GetMaxDamage (void) const
 Returns the maximum damage value that this item can have; zero if damage is not applied. More...
 
char GetMaxStackSize (void) const
 Returns the maximum amount of stacked items of this type. More...
 
bool IsBothNameAndLoreEmpty (void) const
 
bool IsCustomNameEmpty (void) const
 
bool IsDamageable (void) const
 
bool IsEmpty (void) const
 Returns true if the item represents an empty stack - either the type is invalid, or count is zero. More...
 
bool IsEqual (const cItem &a_Item) const
 
bool IsFullStack (void) const
 Returns true if the item is stacked up to its maximum stacking. More...
 
bool IsLoreEmpty (void) const
 
bool IsSameType (const cItem &a_Item) const
 

Static Public Member Functions

static bool IsEnchantable (short a_ItemType, bool a_FromBook=false)
 Returns true if the specified item type is enchantable. More...
 

Public Attributes

AString m_CustomName
 
cEnchantments m_Enchantments
 
cFireworkItem m_FireworkItem
 
cColor m_ItemColor
 
char m_ItemCount
 
short m_ItemDamage
 
short m_ItemType
 
AStringVector m_LoreTable
 
int m_RepairCost
 

Detailed Description

Definition at line 36 of file Item.h.

Constructor & Destructor Documentation

◆ cItem() [1/2]

cItem::cItem ( void  )

Creates an empty item.

Definition at line 16 of file Item.cpp.

◆ cItem() [2/2]

cItem::cItem ( short  a_ItemType,
char  a_ItemCount = 1,
short  a_ItemDamage = 0,
const AString a_Enchantments = "",
const AString a_CustomName = "",
const AStringVector a_LoreTable = {} 
)

Creates an item of the specified type, by default 1 piece with no damage and no enchantments.

Definition at line 31 of file Item.cpp.

Member Function Documentation

◆ AddCount()

cItem & cItem::AddCount ( char  a_AmountToAdd)

Adds the specified count to this object and returns the reference to self (useful for chaining)

Definition at line 104 of file Item.cpp.

◆ AddEnchantment()

int cItem::AddEnchantment ( int  a_EnchantmentID,
unsigned int  a_Level,
bool  a_FromBook 
)

Adds this specific enchantment to this item, returning the cost.

FromBook specifies whether the enchantment should be treated as coming from a book. If true, then the cost returned uses the book values, if false it uses the normal item multipliers.

Definition at line 510 of file Item.cpp.

◆ AddEnchantmentsFromItem()

int cItem::AddEnchantmentsFromItem ( const cItem a_Other)

Adds the enchantments on a_Other to this item, returning the XP cost of the transfer.

Definition at line 675 of file Item.cpp.

◆ CanHaveEnchantment()

bool cItem::CanHaveEnchantment ( int  a_EnchantmentID)

Returns whether or not this item is allowed to have the given enchantment.

Note: Does not check whether the enchantment is exclusive with the current enchantments on the item.

Definition at line 544 of file Item.cpp.

◆ Clear()

void cItem::Clear ( void  )

Empties the item and frees up any dynamic storage used by the internals.

TODO: What is the usage difference? Merge with Empty()?

Definition at line 80 of file Item.cpp.

◆ CopyOne()

cItem cItem::CopyOne ( void  ) const

Returns a copy of this item with m_ItemCount set to 1.

Useful to preserve enchantments etc. on stacked items

Definition at line 93 of file Item.cpp.

◆ DamageItem()

bool cItem::DamageItem ( short  a_Amount = 1)

Damages a weapon / tool.

Returns true when damage reaches max value and the item should be destroyed

Definition at line 181 of file Item.cpp.

◆ Empty()

void cItem::Empty ( void  )

Empties the item and frees up any dynamic storage used by the internals.

Definition at line 63 of file Item.cpp.

◆ EnchantByXPLevels()

bool cItem::EnchantByXPLevels ( unsigned  a_NumXPLevels,
MTRand a_Random 
)

Randomly enchants the item using the specified number of XP levels.

Returns true if the item was enchanted, false if not (not enchantable / too many enchantments already). Randomness is derived from the provided PRNG.

Definition at line 431 of file Item.cpp.

◆ FromJson()

void cItem::FromJson ( const Json::Value &  a_Value)

Loads the item data from JSON representation.

Definition at line 276 of file Item.cpp.

◆ GetEnchantability()

unsigned cItem::GetEnchantability ( )

Returns the enchantability of the item.

When the item hasn't a enchantability, it will returns 0

Definition at line 360 of file Item.cpp.

◆ GetHandler()

const cItemHandler & cItem::GetHandler ( void  ) const

Returns the cItemHandler responsible for this item type.

Definition at line 216 of file Item.cpp.

◆ GetJson()

void cItem::GetJson ( Json::Value &  a_OutValue) const

Saves the item data into JSON representation.

Definition at line 225 of file Item.cpp.

◆ GetMaxDamage()

short cItem::GetMaxDamage ( void  ) const

Returns the maximum damage value that this item can have; zero if damage is not applied.

Definition at line 118 of file Item.cpp.

◆ GetMaxStackSize()

char cItem::GetMaxStackSize ( void  ) const

Returns the maximum amount of stacked items of this type.

Definition at line 207 of file Item.cpp.

◆ IsBothNameAndLoreEmpty()

bool cItem::IsBothNameAndLoreEmpty ( void  ) const
inline

Definition at line 95 of file Item.h.

◆ IsCustomNameEmpty()

bool cItem::IsCustomNameEmpty ( void  ) const
inline

Definition at line 101 of file Item.h.

◆ IsDamageable()

bool cItem::IsDamageable ( void  ) const
inline

Definition at line 116 of file Item.h.

◆ IsEmpty()

bool cItem::IsEmpty ( void  ) const
inline

Returns true if the item represents an empty stack - either the type is invalid, or count is zero.

Definition at line 69 of file Item.h.

◆ IsEnchantable()

bool cItem::IsEnchantable ( short  a_ItemType,
bool  a_FromBook = false 
)
static

Returns true if the specified item type is enchantable.

If FromBook is true, the function is used in the anvil inventory with book enchantments. So it checks the "only book enchantments" too. Example: You can only enchant a hoe with a book.

Definition at line 322 of file Item.cpp.

◆ IsEqual()

bool cItem::IsEqual ( const cItem a_Item) const
inline

Definition at line 76 of file Item.h.

◆ IsFullStack()

bool cItem::IsFullStack ( void  ) const

Returns true if the item is stacked up to its maximum stacking.

Definition at line 198 of file Item.cpp.

◆ IsLoreEmpty()

bool cItem::IsLoreEmpty ( void  ) const
inline

Definition at line 102 of file Item.h.

◆ IsSameType()

bool cItem::IsSameType ( const cItem a_Item) const
inline

Definition at line 89 of file Item.h.

Member Data Documentation

◆ m_CustomName

AString cItem::m_CustomName

Definition at line 167 of file Item.h.

◆ m_Enchantments

cEnchantments cItem::m_Enchantments

Definition at line 166 of file Item.h.

◆ m_FireworkItem

cFireworkItem cItem::m_FireworkItem

Definition at line 201 of file Item.h.

◆ m_ItemColor

cColor cItem::m_ItemColor

Definition at line 202 of file Item.h.

◆ m_ItemCount

char cItem::m_ItemCount

Definition at line 164 of file Item.h.

◆ m_ItemDamage

short cItem::m_ItemDamage

Definition at line 165 of file Item.h.

◆ m_ItemType

short cItem::m_ItemType

Definition at line 163 of file Item.h.

◆ m_LoreTable

AStringVector cItem::m_LoreTable

Definition at line 171 of file Item.h.

◆ m_RepairCost

int cItem::m_RepairCost

Definition at line 200 of file Item.h.


The documentation for this class was generated from the following files: