Cuberite
A lightweight, fast and extensible game server for Minecraft
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]

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 (void)
 Creates an empty item. 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...
 
void Clear (void)
 
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)
 
bool EnchantByXPLevels (int a_NumXPLevels)
 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...
 
int GetEnchantability ()
 Returns the enchantability of the item. More...
 
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
 
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::cItem ( void  )
inline

Creates an empty item.

Definition at line 40 of file Item.h.

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 = {} 
)
inline

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

Definition at line 53 of file Item.h.

Member Function Documentation

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 26 of file Item.cpp.

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 434 of file Item.cpp.

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 599 of file Item.cpp.

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 468 of file Item.cpp.

void cItem::Clear ( void  )
inline

Definition at line 106 of file Item.h.

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 15 of file Item.cpp.

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 102 of file Item.cpp.

void cItem::Empty ( void  )
inline

Definition at line 92 of file Item.h.

bool cItem::EnchantByXPLevels ( int  a_NumXPLevels)

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

Definition at line 354 of file Item.cpp.

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

Loads the item data from JSON representation.

Definition at line 197 of file Item.cpp.

int cItem::GetEnchantability ( )

Returns the enchantability of the item.

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

Definition at line 281 of file Item.cpp.

cItemHandler * cItem::GetHandler ( void  ) const

Returns the cItemHandler responsible for this item type.

Definition at line 137 of file Item.cpp.

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

Saves the item data into JSON representation.

Definition at line 146 of file Item.cpp.

short cItem::GetMaxDamage ( void  ) const

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

Definition at line 40 of file Item.cpp.

char cItem::GetMaxStackSize ( void  ) const

Returns the maximum amount of stacked items of this type.

Definition at line 128 of file Item.cpp.

bool cItem::IsBothNameAndLoreEmpty ( void  ) const
inline

Definition at line 142 of file Item.h.

bool cItem::IsCustomNameEmpty ( void  ) const
inline

Definition at line 148 of file Item.h.

bool cItem::IsDamageable ( void  ) const
inline

Definition at line 163 of file Item.h.

bool cItem::IsEmpty ( void  ) const
inline

Definition at line 116 of file Item.h.

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 243 of file Item.cpp.

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

Definition at line 123 of file Item.h.

bool cItem::IsFullStack ( void  ) const

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

Definition at line 119 of file Item.cpp.

bool cItem::IsLoreEmpty ( void  ) const
inline

Definition at line 149 of file Item.h.

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

Definition at line 136 of file Item.h.

Member Data Documentation

AString cItem::m_CustomName

Definition at line 213 of file Item.h.

cEnchantments cItem::m_Enchantments

Definition at line 212 of file Item.h.

cFireworkItem cItem::m_FireworkItem

Definition at line 222 of file Item.h.

cColor cItem::m_ItemColor

Definition at line 223 of file Item.h.

char cItem::m_ItemCount

Definition at line 210 of file Item.h.

short cItem::m_ItemDamage

Definition at line 211 of file Item.h.

short cItem::m_ItemType

Definition at line 209 of file Item.h.

AStringVector cItem::m_LoreTable

Definition at line 217 of file Item.h.

int cItem::m_RepairCost

Definition at line 221 of file Item.h.


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