QtCraft API C++ classes QML types Handbook

QcItemStack Struct

A number of identical items, e.g. one inventory slot. More...

Header: #include <common/gameplay/QcItemStack.h>

Public Functions

const QList<QcItemStack> &contents() const
const QList<QcEnchantment> &enchantments() const
QcItemStack forDisplay() const
bool hasContents() const
bool isEmpty() const
const QcItemData &itemData() const
quint32 mapId() const
QString name() const
int priorWork() const
QList<QcItemStack> split(int maxStack) const
int stackLimit(int maxStack) const
bool stacksWith(const QcItemStack &other) const
std::optional<QcItemStack> tryWithContents(QList<QcItemStack> stacks) const
std::optional<QcItemStack> tryWithData(const QcItemData &next) const
QcItemStack withContents(QList<QcItemStack> stacks) const
QcItemStack withCount(int amount) const
QcItemStack withData(const QcItemData &next) const
QcItemStack withEnchantments(QList<QcEnchantment> list) const
QcItemStack withMapId(quint32 id) const
QcItemStack withName(QString text) const
QcItemStack withPriorWork(int uses) const
QcItemStack withoutKept() const
bool operator==(const QcItemStack &other) const

Public Variables

int count
int damage
QExplicitlySharedDataPointer<const QcSharedItemData> data
QcItemId item

Static Public Members

int compare(const QcItemStack &a, const QcItemStack &b)

Detailed Description

damage counts tool uses. What only some stacks carry (a map id, contents, a custom name) is in data (decision E-823): null for plain stacks, so they pay one null pointer (a stack is 24 bytes); shared and never changed in place, so copying a stack copies a pointer. Set it only through the with…() functions, which leave it null when empty.

Member Function Documentation

[static] int QcItemStack::compare(const QcItemStack &a, const QcItemStack &b)

Returns the order of a and b (negative, 0 or positive) in a total order of stacks (empty ones first) by item, damage, count and data, so that rules which go through stacks in a fixed order (hoppers sharing a target, decision E-344) never depend on directions.

const QList<QcItemStack> &QcItemStack::contents() const

Returns the stacks held inside (a backpack's slots, stage 68.2); empty for none.

const QList<QcEnchantment> &QcItemStack::enchantments() const

Returns the enchantments it carries (decision E-864); empty for none.

QcItemStack QcItemStack::forDisplay() const

Returns what clients need to draw the stack lying on the ground or in a frame (decision E-832): item, count, damage, map id and name, without contents and kept components, so a dropped backpack does not send what it holds to everyone near.

bool QcItemStack::hasContents() const

Returns whether it holds stacks inside.

bool QcItemStack::isEmpty() const

Returns whether the stack holds no item (no item or a count of 0 or less).

const QcItemData &QcItemStack::itemData() const

Returns the data, or an empty one.

quint32 QcItemStack::mapId() const

Returns the map id of a filled map, 0 for none (decision E-798).

QString QcItemStack::name() const

Returns a custom name (stage 41.2a); empty for none.

int QcItemStack::priorWork() const

Returns how often it went through an anvil (decision E-866).

QList<QcItemStack> QcItemStack::split(int maxStack) const

Returns the stack in parts of at most stackLimit(maxStack) items, for a stack larger than its item allows (a generous block drop, a save from before a mod lowered maxStack). Only the first part keeps the kept components: one may hold items, which a copy would multiply. A stack with contents is one item, whatever its count, for the same reason. Empty for an empty stack.

int QcItemStack::stackLimit(int maxStack) const

Returns the stack size this stack may reach given its item's maxStack: 1 with contents.

bool QcItemStack::stacksWith(const QcItemStack &other) const

Returns whether the items of this stack and other are the same and may go into one stack (up to stackLimit): the same item, damage and data (decisions E-798, E-823). Stacks with contents never stack, so each holds one item (stackLimit). Items that wear out stack to one, so worn tools never merge.

std::optional<QcItemStack> QcItemStack::tryWithContents(QList<QcItemStack> stacks) const

Returns the same stack holding stacks, or nothing when the data would be beyond the limits (tryWithData).

std::optional<QcItemStack> QcItemStack::tryWithData(const QcItemData &next) const

Returns the same stack with next as its data, or nothing (with the warning of withData) when the data is beyond the limits. Callers that take items out of slots to put them into the data (filling a backpack) ask first, so a refusal loses and doubles nothing (stage 68.2).

QcItemStack QcItemStack::withContents(QList<QcItemStack> stacks) const

Returns the same stack holding stacks (withData).

QcItemStack QcItemStack::withCount(int amount) const

Returns the same items and data, amount of them.

QcItemStack QcItemStack::withData(const QcItemData &next) const

Returns the same stack with next as its data (null when next holds nothing). Data beyond the limits of QcItemData (QcItemData::fitsLimits) is refused with a warning: the stack keeps its data, so the server never makes a stack that its readers would refuse.

QcItemStack QcItemStack::withEnchantments(QList<QcEnchantment> list) const

Returns the same stack with the enchantments list (withData).

QcItemStack QcItemStack::withMapId(quint32 id) const

Returns the same stack with the map id id (withData).

QcItemStack QcItemStack::withName(QString text) const

Returns the same stack with the custom name text (withData).

QcItemStack QcItemStack::withPriorWork(int uses) const

Returns the same stack with uses anvil uses, clamped to 0..QcItemData::maxPriorWork (withData).

QcItemStack QcItemStack::withoutKept() const

Returns the same stack without the components a save kept for a newer version (QcItemData::kept).

bool QcItemStack::operator==(const QcItemStack &other) const

Returns whether other has the same item, count, damage and data.

Member Variable Documentation

int QcItemStack::count

How many items.

int QcItemStack::damage

Uses the items have worn off.

QExplicitlySharedDataPointer<const QcSharedItemData> QcItemStack::data

The optional data (see the struct).

QcItemId QcItemStack::item

The item; qcNoItem for an empty stack.