Skip to content

Class endstone::ItemMeta

ClassList > endstone > ItemMeta

Represents the metadata of a generic item.

  • #include <endstone/inventory/meta/item_meta.h>

Inherited by the following classes: endstone::MapMeta

Public Types

Type Name
enum Type

Public Functions

Type Name
ItemMeta (const ItemMeta * meta)
bool addEnchant (const std::string & id, int level, bool force=false)
Adds the specified enchantment to this item meta.
T * as ()
const T * as () const
virtual std::unique_ptr< ItemMeta > clone () const
Creates a clone of the current metadata.
int getDamage () const
Gets the damage.
std::string getDisplayName () const
Gets the display name that is set.
int getEnchantLevel (const std::string & id) const
Checks for the level of the specified enchantment.
std::unordered_map< std::string, int > getEnchants () const
Returns a copy the enchantments in this ItemMeta .
std::vector< std::string > getLore () const
Gets the lore that is set.
int getRepairCost () const
Gets the repair penalty.
virtual Type getType () const
Gets the type of this item meta.
bool hasDamage () const
Checks to see if this item has damage.
bool hasDisplayName () const
Checks for existence of a display name.
bool hasEnchant (const std::string & id) const
Checks for existence of the specified enchantment.
bool hasEnchants () const
Checks for the existence of any enchantments.
bool hasLore () const
Checks for existence of lore.
bool hasRepairCost () const
Checks to see if this has a repair penalty.
virtual bool isEmpty () const
Checks if the item metadata is empty.
bool isUnbreakable () const
Return if the unbreakable tag is true. An unbreakable item will not lose durability.
bool removeEnchant (const std::string & id)
Removes the specified enchantment from this item meta.
void removeEnchants ()
Removes all enchantments from this item meta.
void setDamage (int damage)
Sets the damage.
void setDisplayName (std::optional< std::string > name)
Sets the display name.
void setLore (std::optional< std::vector< std::string > > lore)
Sets the lore for this item or removes lore when given std::nullopt.
void setRepairCost (int cost)
Sets the repair penalty.
void setUnbreakable (bool unbreakable)
Sets the unbreakable tag. An unbreakable item will not lose durability.
virtual ~ItemMeta () = default

Public Types Documentation

enum Type

enum endstone::ItemMeta::Type {
    Item,
    Map
};

Public Functions Documentation

function ItemMeta

inline explicit endstone::ItemMeta::ItemMeta (
    const ItemMeta * meta
) 

function addEnchant

Adds the specified enchantment to this item meta.

inline bool endstone::ItemMeta::addEnchant (
    const std::string & id,
    int level,
    bool force=false
) 

Parameters:

  • id Enchantment id to add
  • level Level for the enchantment
  • force this indicates the enchantment should be applied, ignoring the level limit

Returns:

true if the item meta changed as a result of this call, false otherwise


function as [½]

template<typename T>
inline T * endstone::ItemMeta::as () 

function as [2/2]

template<typename T>
inline const T * endstone::ItemMeta::as () const

function clone

Creates a clone of the current metadata.

inline virtual std::unique_ptr< ItemMeta > endstone::ItemMeta::clone () const

Returns:

A copy of the metadata containing the same state as the original.


function getDamage

Gets the damage.

inline int endstone::ItemMeta::getDamage () const

Returns:

the damage


function getDisplayName

Gets the display name that is set.

inline std::string endstone::ItemMeta::getDisplayName () const

Returns:

the display name that is set


function getEnchantLevel

Checks for the level of the specified enchantment.

inline int endstone::ItemMeta::getEnchantLevel (
    const std::string & id
) const

Parameters:

  • id enchantment id to check

Returns:

The level that the specified enchantment has, or 0 if none


function getEnchants

Returns a copy the enchantments in this ItemMeta .

inline std::unordered_map< std::string, int > endstone::ItemMeta::getEnchants () const

Returns an empty map if none.

Returns:

An immutable copy of the enchantments


function getLore

Gets the lore that is set.

inline std::vector< std::string > endstone::ItemMeta::getLore () const

Returns:

a list of lore that is set


function getRepairCost

Gets the repair penalty.

inline int endstone::ItemMeta::getRepairCost () const

Returns:

the repair penalty


function getType

Gets the type of this item meta.

inline virtual Type endstone::ItemMeta::getType () const

Returns:

type of this item meta


function hasDamage

Checks to see if this item has damage.

inline bool endstone::ItemMeta::hasDamage () const

Returns:

true if this has damage


function hasDisplayName

Checks for existence of a display name.

inline bool endstone::ItemMeta::hasDisplayName () const

Returns:

true if this has a display name


function hasEnchant

Checks for existence of the specified enchantment.

inline bool endstone::ItemMeta::hasEnchant (
    const std::string & id
) const

Parameters:

  • id enchantment id to check

Returns:

true if this enchantment exists for this meta


function hasEnchants

Checks for the existence of any enchantments.

inline bool endstone::ItemMeta::hasEnchants () const

Returns:

true if an enchantment exists on this meta


function hasLore

Checks for existence of lore.

inline bool endstone::ItemMeta::hasLore () const

Returns:

true if this has lore


function hasRepairCost

Checks to see if this has a repair penalty.

inline bool endstone::ItemMeta::hasRepairCost () const

Returns:

true if this has a repair penalty


function isEmpty

Checks if the item metadata is empty.

inline virtual bool endstone::ItemMeta::isEmpty () const

Returns:

true if the metadata is empty, false otherwise.


function isUnbreakable

Return if the unbreakable tag is true. An unbreakable item will not lose durability.

inline bool endstone::ItemMeta::isUnbreakable () const

Returns:

true if the unbreakable tag is true


function removeEnchant

Removes the specified enchantment from this item meta.

inline bool endstone::ItemMeta::removeEnchant (
    const std::string & id
) 

Parameters:

Returns:

true if the item meta changed as a result of this call, false otherwise


function removeEnchants

Removes all enchantments from this item meta.

inline void endstone::ItemMeta::removeEnchants () 


function setDamage

Sets the damage.

inline void endstone::ItemMeta::setDamage (
    int damage
) 

Parameters:

  • damage item damage

function setDisplayName

Sets the display name.

inline void endstone::ItemMeta::setDisplayName (
    std::optional< std::string > name
) 

Parameters:

  • name the name to set

function setLore

Sets the lore for this item or removes lore when given std::nullopt.

inline void endstone::ItemMeta::setLore (
    std::optional< std::vector< std::string > > lore
) 

Parameters:

  • lore the lore that will be set

function setRepairCost

Sets the repair penalty.

inline void endstone::ItemMeta::setRepairCost (
    int cost
) 

Parameters:

  • cost repair penalty

function setUnbreakable

Sets the unbreakable tag. An unbreakable item will not lose durability.

inline void endstone::ItemMeta::setUnbreakable (
    bool unbreakable
) 

Parameters:

  • unbreakable true if set unbreakable

function ~ItemMeta

virtual endstone::ItemMeta::~ItemMeta () = default


The documentation for this class was generated from the following file include/endstone/inventory/meta/item_meta.h