QcEnchantingTable Namespace
The enchanting table's rules as in the reference game (decision E-864): bookshelves around the table raise the three offers' levels, and a player's enchantment seed fixes the offers until he enchants (then the server draws a new seed). More...
| Header: | #include <common/gameplay/QcEnchantingTable.h> |
Classes
| struct | Offer |
Types
Variables
| const QLatin1StringView | lapisItem |
| const int | maxShelves |
| const int | offerCount |
| const QLatin1StringView | shelfBlock |
| const QLatin1StringView | tableBlock |
Functions
| QcItemId | enchantedItem(const QcContentRegistry &content, QcItemId item) |
| QList<QcEnchantment> | enchantmentsFor(const QcContentRegistry &content, const QcItemStack &stack, int levelCost, quint32 seed) |
| bool | letsShelfThrough(const QcContentRegistry &content, std::optional<QcBlockId> block) |
| std::array<int, offerCount> | levelCosts(quint32 seed, int shelves, int enchantability) |
| QcEnchantingTable::Offers | offers(const QcContentRegistry &content, const QcItemStack &stack, int shelves, quint32 seed) |
| int | priceOf(int slot) |
| int | shelvesAround(QcBlockPos table, const std::function<bool (QcBlockPos)> &isShelf, const std::function<bool (QcBlockPos)> &isFree) |
| QList<QcBlockPos> | shelvesIn(const QcContentRegistry &content, QcBlockPos table, const QcEnchantingTable::BlockAt &blockAt) |
| QList<QcBlockPos> | shelvesOf(QcBlockPos table, const std::function<bool (QcBlockPos)> &isShelf, const std::function<bool (QcBlockPos)> &isFree) |
Detailed Description
Pure, so the offers are testable and the same on every run: the same seed, item and shelves give the same offers.
Classes
class Offer
One offer: the levels the player needs (0: no offer) and the enchantments it gives. More...
Type Documentation
[alias] QcEnchantingTable::BlockAt
What stands at a position of a world (none: not loaded there).
[alias] QcEnchantingTable::Offers
The three offers of a table.
Variable Documentation
const QLatin1StringView QcEnchantingTable::lapisItem
The item an offer costs besides levels.
const int QcEnchantingTable::maxShelves
At most this many bookshelves count.
const int QcEnchantingTable::offerCount
The number of offers.
const QLatin1StringView QcEnchantingTable::shelfBlock
The block that counts around the table (at most maxShelves of it).
const QLatin1StringView QcEnchantingTable::tableBlock
The enchanting table's block.
Function Documentation
QcItemId QcEnchantingTable::enchantedItem(const QcContentRegistry &content, QcItemId item)
Returns the item item of content becomes when it is enchanted: its enchantsInto (decision E-873), else itself.
QList<QcEnchantment> QcEnchantingTable::enchantmentsFor(const QcContentRegistry &content, const QcItemStack &stack, int levelCost, quint32 seed)
Returns the enchantments of content for stack at enchanting levelCost, drawn with seed (offer slot uses seed + slot).
bool QcEnchantingTable::letsShelfThrough(const QcContentRegistry &content, std::optional<QcBlockId> block)
Returns whether block of content lets a bookshelf's power through to the table: air or a replaceable block (tall grass, fire); not a position that is not loaded.
std::array<int, offerCount> QcEnchantingTable::levelCosts(quint32 seed, int shelves, int enchantability)
Returns the levels of the three offers for an item with enchantability (0: none) and shelves, drawn with seed.
QcEnchantingTable::Offers QcEnchantingTable::offers(const QcContentRegistry &content, const QcItemStack &stack, int shelves, quint32 seed)
Returns the three offers for stack with shelves, drawn with seed from the enchantments of content (nothing for an empty stack, more than one item, one already enchanted or an item without enchantability or applicable enchantments). An item with enchantsInto (a book) gets the enchantments of the item it becomes (an enchanted book takes all, decision E-873).
int QcEnchantingTable::priceOf(int slot)
Returns the lapis lazuli and the levels taken for offer slot.
int QcEnchantingTable::shelvesAround(QcBlockPos table, const std::function<bool (QcBlockPos)> &isShelf, const std::function<bool (QcBlockPos)> &isFree)
Returns the bookshelves that count for a table at table: those two blocks away on the ring around it (at the table's height and one above) with a free block between them and the table, at most maxShelves. isShelf and isFree tell what stands at a position.
QList<QcBlockPos> QcEnchantingTable::shelvesIn(const QcContentRegistry &content, QcBlockPos table, const QcEnchantingTable::BlockAt &blockAt)
Returns the bookshelves (qtcraft:bookshelf of content) that count for the table at table in the world blockAt tells (shelvesOf with letsShelfThrough): the one rule of the server's offers and the client's runes in the world (decision E-884).
QList<QcBlockPos> QcEnchantingTable::shelvesOf(QcBlockPos table, const std::function<bool (QcBlockPos)> &isShelf, const std::function<bool (QcBlockPos)> &isFree)
Returns the positions of the bookshelves that count for a table at table, as shelvesAround() finds them with isShelf and isFree, at most maxShelves (the runes in the world fly from them, decision E-884).