QtCraft API C++ classes QML types Handbook

QcEnchantmentDefinition Struct

An enchantment (enchantments/<name>.json, decision E-864), as in the reference game. More...

Header: #include <common/content/items/QcEnchantmentDefinition.h>

Public Functions

int highestPower(int level) const
int lowestPower(int level) const

Public Variables

QStringList conflicts
QcEnchantmentEffect effect
QStringList items
int maxLevel
int minPower
QString name
int powerPerLevel
int powerSpread
QString translationKey
int weight

Static Public Members

const qsizetype maxConflicts
const qsizetype maxItemKinds
const int maxLevelLimit
enum class QcEnchantmentEffect { Efficiency, Unbreaking, Sharpness, Protection, FeatherFalling }

Detailed Description

It names the items it applies to, how often the enchanting table picks it, the enchantments it excludes, its effect and the enchanting power each level needs: from minPower + powerPerLevel × (level - 1) up to that plus powerSpread.

The content sync sends all of it: the client needs the effect (mining speed it predicts) and the name for the tooltip.

Member Function Documentation

int QcEnchantmentDefinition::highestPower(int level) const

Returns the highest enchanting power at which level is offered: lowestPower() plus powerSpread.

int QcEnchantmentDefinition::lowestPower(int level) const

Returns the lowest enchanting power at which level is offered.

Member Variable Documentation

QStringList QcEnchantmentDefinition::conflicts

Enchantments that never come together with it (both ways); at most maxConflicts names of at most QcItemData::maxEnchantmentName characters.

QcEnchantmentEffect QcEnchantmentDefinition::effect

The effect it has ("effect", required, a name known to QcEnchantmentParser::effectOf()).

QStringList QcEnchantmentDefinition::items

Item kinds it applies to (QcEnchanting::kindsOf), 1 to maxItemKinds of: a tool category ("pickaxe", "axe", "shovel", "hoe", "shears"), "digger" (pickaxe, axe, shovel, hoe), "weapon", "armour", "armour_head" … "armour_feet", "launcher" or "durable".

int QcEnchantmentDefinition::maxLevel

Highest level it can have ("maxLevel", 1 to maxLevelLimit, default 1).

const int QcEnchantmentDefinition::maxLevelLimit

The highest level an enchantment may have in its data and on an item.

int QcEnchantmentDefinition::minPower

Enchanting power level 1 needs at least ("minPower", 1 to 100).

QString QcEnchantmentDefinition::name

Qualified name ("name", required, at most QcItemData::maxEnchantmentName characters).

int QcEnchantmentDefinition::powerPerLevel

Power each further level adds to the lowest power ("powerPerLevel", 0 to 100).

int QcEnchantmentDefinition::powerSpread

Width of each level's power range above its lowest power ("powerSpread", 0 to 100).

QString QcEnchantmentDefinition::translationKey

Translation key of its display name ("translation"); defaults to enchantment.<namespace>.<name>.

int QcEnchantmentDefinition::weight

Relative chance against the other candidates of an offer (1–1000).

Related Non-Members

enum class QcEnchantmentEffect

What an enchantment does (decision E-864): the game knows these effects; an enchantment's data names one of them ("effect": "efficiency"), so a mod can add an enchantment with its own name, levels and items for a known effect, but no new kind of effect.

ConstantValueDescription
QcEnchantmentDefinition::QcEnchantmentEffect::Efficiency0Mining speed: the tool's speed gains level² + 1 on blocks of its category (QcMining).
QcEnchantmentDefinition::QcEnchantmentEffect::Unbreaking1Durability: each use wears the item only with chance 1 / (level + 1); armour with 0.6 + 0.4 / (level + 1) (QcEnchanting::keepsDurability).
QcEnchantmentDefinition::QcEnchantmentEffect::Sharpness2Melee damage: + 0.5 × level + 0.5 health points per hit.
QcEnchantmentDefinition::QcEnchantmentEffect::Protection3Protection points against every damage the armour takes off, and falls: level per piece.
QcEnchantmentDefinition::QcEnchantmentEffect::FeatherFalling4Protection points against falls only: 3 × level per piece.