Skip to content

Class endstone::EnchantItemEvent

ClassList > endstone > EnchantItemEvent

Called when a player enchants an item at an enchanting table. More...

  • #include <endstone/event/enchantment/enchant_item_event.h>

Inherits the following classes: endstone::Cancellable

Public Types

Type Name
typedef std::unordered_map< const Enchantment *, int > Enchantments

Public Functions

Type Name
ENDSTONE_EVENT (EnchantItemEvent)
EnchantItemEvent (Inventory & inventory, const NotNull< Player > & enchanter, const NotNull< Block > & enchant_block, ItemStack item, int exp_level_cost, Enchantments enchants_to_add, int which_button)
const NotNull< Block > & getEnchantBlock () const
Gets the enchanting table involved in this event.
const NotNull< Player > & getEnchanter () const
Gets the player enchanting the item.
const Enchantments & getEnchantsToAdd () const
Gets the enchantments that will be applied to the item.
Enchantments & getEnchantsToAdd ()
Gets the enchantments that will be applied to the item.
int getExpLevelCost () const
Gets the minimum player level required by the selected option.
const ItemStack & getItem () const
Gets the item being enchanted.
void setExpLevelCost (int exp_level_cost)
Sets the minimum player level required by the selected option.
void setItem (ItemStack item)
Sets the item to enchant.
int whichButton () const
Gets the selected enchanting button.

Public Functions inherited from endstone::Cancellable

See endstone::Cancellable

Type Name
virtual void cancel ()
Cancel this event.
virtual bool isCancelled () override const
Gets the cancellation state of this event.
virtual void setCancelled (bool cancel) override
Sets the cancellation state of this event.

Public Functions inherited from endstone::ICancellable

See endstone::ICancellable

Type Name
virtual void cancel () = 0
Cancels this event.
virtual bool isCancelled () const = 0
Gets the cancellation state of this event.
virtual void setCancelled (bool cancel) = 0
Sets the cancellation state of this event.
virtual ~ICancellable () = default

Detailed Description

Note:

Cancelling the event leaves the item, the player's experience levels and the lapis lazuli untouched.

Note:

Bedrock does not reveal a single hinted enchantment for an offer, so every enchantment the offer applies is listed in getEnchantsToAdd().

Public Types Documentation

typedef Enchantments

using endstone::EnchantItemEvent::Enchantments =  std::unordered_map<const Enchantment *, int>;

Public Functions Documentation

function ENDSTONE_EVENT

endstone::EnchantItemEvent::ENDSTONE_EVENT (
    EnchantItemEvent
) 

function EnchantItemEvent

inline endstone::EnchantItemEvent::EnchantItemEvent (
    Inventory & inventory,
    const  NotNull < Player > & enchanter,
    const  NotNull < Block > & enchant_block,
    ItemStack item,
    int exp_level_cost,
    Enchantments enchants_to_add,
    int which_button
) 

function getEnchantBlock

Gets the enchanting table involved in this event.

inline const  NotNull < Block > & endstone::EnchantItemEvent::getEnchantBlock () const

Returns:

the enchanting table


function getEnchanter

Gets the player enchanting the item.

inline const  NotNull < Player > & endstone::EnchantItemEvent::getEnchanter () const

Returns:

the player enchanting the item


function getEnchantsToAdd [½]

Gets the enchantments that will be applied to the item.

inline const Enchantments & endstone::EnchantItemEvent::getEnchantsToAdd () const

Returns:

the enchantments and their levels


function getEnchantsToAdd [2/2]

Gets the enchantments that will be applied to the item.

inline Enchantments & endstone::EnchantItemEvent::getEnchantsToAdd () 

Returns:

the enchantments and their levels


function getExpLevelCost

Gets the minimum player level required by the selected option.

inline int endstone::EnchantItemEvent::getExpLevelCost () const

The number of levels consumed remains determined by the selected button.

Returns:

the minimum required player level


function getItem

Gets the item being enchanted.

inline const  ItemStack & endstone::EnchantItemEvent::getItem () const

Returns:

the item being enchanted


function setExpLevelCost

Sets the minimum player level required by the selected option.

inline void endstone::EnchantItemEvent::setExpLevelCost (
    int exp_level_cost
) 

Parameters:

  • exp_level_cost the minimum required player level

function setItem

Sets the item to enchant.

inline void endstone::EnchantItemEvent::setItem (
    ItemStack item
) 

Parameters:

  • item the item to enchant

function whichButton

Gets the selected enchanting button.

inline int endstone::EnchantItemEvent::whichButton () const

Returns:

the selected button, from 0 to 2



The documentation for this class was generated from the following file include/endstone/event/enchantment/enchant_item_event.h