Skip to content

Class endstone::PrepareItemEnchantEvent

ClassList > endstone > PrepareItemEnchantEvent

Called when an enchanting table prepares offers for an item. More...

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

Inherits the following classes: endstone::Cancellable

Public Types

Type Name
typedef std::array< std::optional< EnchantmentOffer >, 3 > Offers

Public Functions

Type Name
ENDSTONE_EVENT (PrepareItemEnchantEvent)
PrepareItemEnchantEvent (Inventory & inventory, const NotNull< Player > & enchanter, const NotNull< Block > & enchant_block, ItemStack item, Offers offers, int enchantment_bonus)
const NotNull< Block > & getEnchantBlock () const
Gets the enchanting table involved in this event.
const NotNull< Player > & getEnchanter () const
Gets the player for whom the offers are being prepared.
int getEnchantmentBonus () const
Gets the enchanting bonus provided by nearby bookshelves.
const ItemStack & getItem () const
Gets the item for which offers are being prepared.
const Offers & getOffers () const
Gets the three enchanting offers.
Offers & getOffers ()
Gets the three enchanting offers.
void setOffers (Offers offers)
Sets the three enchanting offers.

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

Set an offer to std::nullopt to hide it, or assign a new EnchantmentOffer to replace it. Each offer contains every enchantment that Bedrock applies when its corresponding button is selected.

Note:

This event can be called multiple times while the enchanting table is open.

Note:

Cancelling the event removes all enchanting offers.

Public Types Documentation

typedef Offers

using endstone::PrepareItemEnchantEvent::Offers =  std::array<std::optional<EnchantmentOffer>, 3>;

Public Functions Documentation

function ENDSTONE_EVENT

endstone::PrepareItemEnchantEvent::ENDSTONE_EVENT (
    PrepareItemEnchantEvent
) 

function PrepareItemEnchantEvent

inline endstone::PrepareItemEnchantEvent::PrepareItemEnchantEvent (
    Inventory & inventory,
    const  NotNull < Player > & enchanter,
    const  NotNull < Block > & enchant_block,
    ItemStack item,
    Offers offers,
    int enchantment_bonus
) 

function getEnchantBlock

Gets the enchanting table involved in this event.

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

Returns:

the enchanting table


function getEnchanter

Gets the player for whom the offers are being prepared.

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

Returns:

the player viewing the enchanting table


function getEnchantmentBonus

Gets the enchanting bonus provided by nearby bookshelves.

inline int endstone::PrepareItemEnchantEvent::getEnchantmentBonus () const

Returns:

the number of contributing bookshelves


function getItem

Gets the item for which offers are being prepared.

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

Returns:

the item being enchanted


function getOffers [½]

Gets the three enchanting offers.

inline const Offers & endstone::PrepareItemEnchantEvent::getOffers () const

A missing value indicates that the corresponding slot has no offer.

Returns:

the enchanting offers


function getOffers [2/2]

Gets the three enchanting offers.

inline Offers & endstone::PrepareItemEnchantEvent::getOffers () 

A missing value indicates that the corresponding slot has no offer.

Returns:

the enchanting offers


function setOffers

Sets the three enchanting offers.

inline void endstone::PrepareItemEnchantEvent::setOffers (
    Offers offers
) 

Parameters:

  • offers the enchanting offers


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