QtCraft API C++ classes QML types Handbook

QcContentRegistry Class

Central catalogue of all content (blocks, items, creatures, recipes, effects); assets, world generation, villages and translations are catalogues of their own that it owns (decision E-715). More...

Header: #include <common/content/registry/QcContentRegistry.h>

Public Types

struct ParsedState

Public Functions

void addPack(QcPackReference pack)
QcAdvancementCatalog &advancements()
const QcAdvancementCatalog &advancements() const
QcAssetCatalog &assets()
const QcAssetCatalog &assets() const
const QcBlockDefinition &block(QcBlockId id) const
qsizetype blockCount() const
std::optional<QcBlockId> blockId(const QString &name) const
const QList<QcBlockDefinition> &blocks() const
const QcCommandMacroDefinition *commandMacro(const QString &name) const
const QList<QcCommandMacroDefinition> &commandMacros() const
void createBlockItems()
std::optional<QcBlockId> defaultFire() const
const QcEffectDefinition *effect(const QString &name) const
const QList<QcEffectDefinition> &effects() const
const QcEnchantmentDefinition *enchantment(const QString &name) const
const QList<QcEnchantmentDefinition> &enchantments() const
QStringList finish()
const QList<QcHandbookChapter> &handbookChapters() const
const QcHoldDefaults &holdDefaults() const
bool isSameBlock(QcBlockId a, QcBlockId b) const
bool isValidBlock(QcBlockId id) const
bool isValidItem(QcItemId id) const
const QcItemDefinition &item(QcItemId id) const
qsizetype itemCount() const
std::optional<QcItemId> itemId(const QString &name) const
const QList<QcItemDefinition> &items() const
QcLootTables &lootTables()
const QcLootTables &lootTables() const
const QList<QcMaterialDefinition> &materials() const
void mergeHoldDefaults(const QcHoldDefaults &later)
std::optional<QcCreatureKindId> mobKind(const QString &name) const
QcMobKinds mobs() const
const QList<QcPackReference> &packs() const
QcContentRegistry::ParsedState parseState(const QString &text) const
const QList<QcPartFamily> &partFamilies() const
const QcProjectileDefinition *projectile(const QString &name) const
const QList<QcProjectileDefinition> &projectiles() const
QString property(QcBlockId id, const QString &property) const
std::optional<qsizetype> recipeIndex(const QString &name) const
const QList<QcRecipeDefinition> &recipes() const
QcResult<QcBlockId> registerBlock(QcBlockDefinition definition)
void registerCommandMacro(QcCommandMacroDefinition macro)
void registerEffect(QcEffectDefinition effect)
void registerEnchantment(QcEnchantmentDefinition enchantment)
void registerHandbookChapter(QcHandbookChapter chapter)
QcResult<QcItemId> registerItem(QcItemDefinition definition)
void registerMaterial(QcMaterialDefinition material)
void registerMob(QcMobDefinition definition)
void registerPartFamily(QcPartFamily family)
void registerProjectile(QcProjectileDefinition projectile)
void registerRecipe(QcRecipeDefinition definition)
QcStatus registerShape(QcShapeDefinition shape)
void registerSmeltingRecipe(QcSmeltingRecipe recipe)
void registerStonecuttingRecipe(QcSmeltingRecipe recipe)
void setWeather(QcWeatherDefinition weather)
const QcShapeDefinition *shape(const QString &name) const
const QcShapeDefinition &shapeOf(const QcBlockDefinition &block) const
const QList<QcShapeDefinition> &shapes() const
const QcSmeltingRecipe *smeltingRecipe(const QString &category, const QString &inputItem) const
const QList<QcSmeltingRecipe> &smeltingRecipes() const
const QcBlockState &state(QcBlockId id) const
qsizetype stateCount() const
std::optional<QcBlockId> stateId(const QString &text) const
QString stateName(QcBlockId id) const
const QcBlockStateTable &stateTable() const
std::optional<qsizetype> stonecuttingIndex(const QString &name) const
const QList<QcSmeltingRecipe> &stonecuttingRecipes() const
QcTranslations &translations()
const QcTranslations &translations() const
QcVillageCatalog &villageCatalog()
const QcVillageCatalog &villageCatalog() const
std::optional<QcCreatureKindId> villagerOfStyle(const QString &style) const
const QcVillagerSettings &villagerSettingsOf(QcCreatureKindId kind) const
const QcWeatherDefinition &weather() const
QcBlockId withProperty(QcBlockId id, const QString &property, const QString &value) const
QcWorldgenCatalog &worldgen()
const QcWorldgenCatalog &worldgen() const
void writeTo(QDataStream &stream) const

Static Public Members

const char *const airName
QcResult<QcContentRegistry> readFrom(QDataStream &stream)

Detailed Description

Base game and mods register through the same functions; a later registration with the same name replaces the earlier one. Runtime block ids are block states (QcBlockStateTable) in registration order; air is always id 0, and a block's name resolves to its default state.

Member Function Documentation

void QcContentRegistry::addPack(QcPackReference pack)

Appends pack to the packs in load order (base game first).

QcAdvancementCatalog &QcContentRegistry::advancements()

Returns the advancements of the adventure guide (decision E-923), replaced or switched off by name; they reach the client without the triggers of their criteria.

const QcAdvancementCatalog &QcContentRegistry::advancements() const

Returns the advancements of the adventure guide (decision E-923).

QcAssetCatalog &QcContentRegistry::assets()

Returns the textures, skeleton models, appearances and sounds (QcAssetCatalog).

const QcAssetCatalog &QcContentRegistry::assets() const

Returns the textures, skeleton models, appearances and sounds (QcAssetCatalog).

const QcBlockDefinition &QcContentRegistry::block(QcBlockId id) const

Returns the definition of the block state id. Precondition: isValidBlock(id).

qsizetype QcContentRegistry::blockCount() const

Returns the number of block definitions; runtime ids range over stateCount() states.

std::optional<QcBlockId> QcContentRegistry::blockId(const QString &name) const

Returns the default state of the block named name; none for an unknown name.

const QList<QcBlockDefinition> &QcContentRegistry::blocks() const

Returns the block definitions in registration order (air first).

const QcCommandMacroDefinition *QcContentRegistry::commandMacro(const QString &name) const

Returns the command macro named name, or null if there is none.

const QList<QcCommandMacroDefinition> &QcContentRegistry::commandMacros() const

Returns the command macros in registration order.

void QcContentRegistry::createBlockItems()

Gives every visible, non-liquid block that has an item (hasItem) but no item of the same name yet an item that places it.

std::optional<QcBlockId> QcContentRegistry::defaultFire() const

Returns the fire a spark lights and burning bodies show: the first block with "fire": true (qtcraft:fire in the base game; decision E-392).

const QcEffectDefinition *QcContentRegistry::effect(const QString &name) const

Returns the status effect kind named name, or null if there is none.

const QList<QcEffectDefinition> &QcContentRegistry::effects() const

Returns the status effect kinds in registration order.

const QcEnchantmentDefinition *QcContentRegistry::enchantment(const QString &name) const

Returns the enchantment named name, or null if there is none.

const QList<QcEnchantmentDefinition> &QcContentRegistry::enchantments() const

Returns the enchantments in registration order.

QStringList QcContentRegistry::finish()

Completes the content after all packs: generates building parts (QcPartGenerator), takes circuit blocks with broken links out of circuits, creates the block items and the generated stonecutting recipes, and resolves what definitions name of each other (anvil swaps, villagers, archers, held items, creature traits, spawners, projectiles, village styles, outfits, advancements), leaving out or switching off what names nothing. Returns the warnings, in English like all content loading messages (decision E-973).

const QList<QcHandbookChapter> &QcContentRegistry::handbookChapters() const

Returns the handbook chapters in registration order.

const QcHoldDefaults &QcContentRegistry::holdDefaults() const

Returns how items are held by category.

bool QcContentRegistry::isSameBlock(QcBlockId a, QcBlockId b) const

Returns whether the states a and b belong to the same block definition.

bool QcContentRegistry::isValidBlock(QcBlockId id) const

Returns whether id is a known block state.

bool QcContentRegistry::isValidItem(QcItemId id) const

Returns whether id names a registered item (1..itemCount()).

const QcItemDefinition &QcContentRegistry::item(QcItemId id) const

Returns the definition of the item id. Precondition: isValidItem(id).

qsizetype QcContentRegistry::itemCount() const

Returns the number of items.

std::optional<QcItemId> QcContentRegistry::itemId(const QString &name) const

Returns the id of the item named name; none for an unknown name.

const QList<QcItemDefinition> &QcContentRegistry::items() const

Returns the item definitions in id order (the item with id 1 first).

QcLootTables &QcContentRegistry::lootTables()

Returns the loot tables of generated chests (decision E-521, server side only), replaced by name.

const QcLootTables &QcContentRegistry::lootTables() const

Returns the loot tables of generated chests (decision E-521, server side only).

const QList<QcMaterialDefinition> &QcContentRegistry::materials() const

Returns the building materials in registration order.

void QcContentRegistry::mergeHoldDefaults(const QcHoldDefaults &later)

Merges later into how items are held by category (decision E-831); a later pack overrides the fields it sets. They reach the client.

std::optional<QcCreatureKindId> QcContentRegistry::mobKind(const QString &name) const

Returns the creature kind named name; none for an unknown name.

QcMobKinds QcContentRegistry::mobs() const

Returns the mob types in registration order, indexed by their creature kind (decision E-952).

const QList<QcPackReference> &QcContentRegistry::packs() const

Returns the packs in load order (base game first).

QcContentRegistry::ParsedState QcContentRegistry::parseState(const QString &text) const

Returns the state named by text ("name" or "name[a=x,b=y]"). Unknown properties or values keep their defaults and are described in problems, as is a missing closing bracket.

const QList<QcPartFamily> &QcContentRegistry::partFamilies() const

Returns the building part families in registration order.

const QcProjectileDefinition *QcContentRegistry::projectile(const QString &name) const

Returns the projectile kind named name, or null if there is none.

const QList<QcProjectileDefinition> &QcContentRegistry::projectiles() const

Returns the projectile kinds in registration order.

QString QcContentRegistry::property(QcBlockId id, const QString &property) const

Returns the value of property in the state id, empty when the block has no such property.

[static] QcResult<QcContentRegistry> QcContentRegistry::readFrom(QDataStream &stream)

Returns the content read from stream in the wire format of the content sync message (QcContentSerializer::read()), or an error for a corrupt stream.

std::optional<qsizetype> QcContentRegistry::recipeIndex(const QString &name) const

Returns the position in recipes() of the recipe named name; none for an unknown name.

const QList<QcRecipeDefinition> &QcContentRegistry::recipes() const

Returns the crafting recipes in registration order.

QcResult<QcBlockId> QcContentRegistry::registerBlock(QcBlockDefinition definition)

Registers the block definition or replaces the definition of an existing one of the same name; returns its default state. Replacing a block with a different number of states renumbers the states of later blocks. Fails for an invalid name, for air, for an invalid state or light opacity, and when the state table or its box budget would overflow.

void QcContentRegistry::registerCommandMacro(QcCommandMacroDefinition macro)

Registers the command macro of a pack, replacing one of the same name (server side only, not synchronised).

void QcContentRegistry::registerEffect(QcEffectDefinition effect)

Registers the status effect kind (decision E-450), replacing one of the same name; they reach the client.

void QcContentRegistry::registerEnchantment(QcEnchantmentDefinition enchantment)

Registers the enchantment (decision E-864), replacing one of the same name; they reach the client.

void QcContentRegistry::registerHandbookChapter(QcHandbookChapter chapter)

Registers the handbook chapter about playing, replacing one of the same name (server side only, not synchronised).

QcResult<QcItemId> QcContentRegistry::registerItem(QcItemDefinition definition)

Registers the item definition or replaces an existing one of the same name (keeping its id) and returns its id. Ids start at 1. Fails for an invalid name or a maxStack outside 1..QcItemDefinition::maxStackLimit.

void QcContentRegistry::registerMaterial(QcMaterialDefinition material)

Registers or replaces the building material (server side; the parts finish() generates are ordinary content).

void QcContentRegistry::registerMob(QcMobDefinition definition)

Registers or replaces the mob type definition; mob type ids are indices into mobs().

void QcContentRegistry::registerPartFamily(QcPartFamily family)

Registers or replaces the building part family (server side; the parts finish() generates are ordinary content).

void QcContentRegistry::registerProjectile(QcProjectileDefinition projectile)

Registers the projectile kind (decision E-425, server side only), replacing one of the same name.

void QcContentRegistry::registerRecipe(QcRecipeDefinition definition)

Registers or replaces the crafting recipe definition by name.

QcStatus QcContentRegistry::registerShape(QcShapeDefinition shape)

Registers or replaces the named shape; blocks that refer to it pick it up. Returns an error when the name is not "namespace:path", the shape has too many boxes or its blocks would exceed the state table's budget.

void QcContentRegistry::registerSmeltingRecipe(QcSmeltingRecipe recipe)

Registers the smelting recipe, replacing one of the same name like crafting recipes.

void QcContentRegistry::registerStonecuttingRecipe(QcSmeltingRecipe recipe)

Registers the stonecutting recipe (decision E-784), from data or generated for building parts (QcStonecutting), replacing one of the same name.

void QcContentRegistry::setWeather(QcWeatherDefinition weather)

Sets what the weather does to the world to weather (server side only); a later pack replaces it.

See also weather().

const QcShapeDefinition *QcContentRegistry::shape(const QString &name) const

Returns the shape named name, or null if there is none.

const QcShapeDefinition &QcContentRegistry::shapeOf(const QcBlockDefinition &block) const

Returns the shape block uses: its named shape when registered, else its inline shape.

const QList<QcShapeDefinition> &QcContentRegistry::shapes() const

Returns the named shapes in registration order.

const QcSmeltingRecipe *QcContentRegistry::smeltingRecipe(const QString &category, const QString &inputItem) const

Returns the first recipe of category that takes inputItem, or null.

const QList<QcSmeltingRecipe> &QcContentRegistry::smeltingRecipes() const

Returns the smelting recipes in registration order.

const QcBlockState &QcContentRegistry::state(QcBlockId id) const

Returns the block and state index of the block state id. Precondition: isValidBlock(id).

qsizetype QcContentRegistry::stateCount() const

Returns the number of block states, the range of runtime block ids.

std::optional<QcBlockId> QcContentRegistry::stateId(const QString &text) const

Returns the state named by text, as parseState() without the problems.

QString QcContentRegistry::stateName(QcBlockId id) const

Returns the name of the state id: "name" or "name[a=x,b=y]" with every property, as stored in saves.

const QcBlockStateTable &QcContentRegistry::stateTable() const

Returns the table of all block states.

std::optional<qsizetype> QcContentRegistry::stonecuttingIndex(const QString &name) const

Returns the position in stonecuttingRecipes() of the recipe named name; none for an unknown name.

const QList<QcSmeltingRecipe> &QcContentRegistry::stonecuttingRecipes() const

Returns the stonecutting recipes in registration order.

QcTranslations &QcContentRegistry::translations()

Returns the texts of the content by language (QcTranslations).

const QcTranslations &QcContentRegistry::translations() const

Returns the texts of the content by language (QcTranslations).

QcVillageCatalog &QcContentRegistry::villageCatalog()

Returns the village styles and settings, villager species, professions and their offers (server side only).

const QcVillageCatalog &QcContentRegistry::villageCatalog() const

Returns the village styles and settings, villager species, professions and their offers (server side only).

std::optional<QcCreatureKindId> QcContentRegistry::villagerOfStyle(const QString &style) const

Returns the creature kind living in villages of style (its own or the settings'), when it is a villager (decision E-421).

const QcVillagerSettings &QcContentRegistry::villagerSettingsOf(QcCreatureKindId kind) const

Returns the settings of the creature kind kind (QcMobDefinition::villagerSettings, by the index finish() keeps on the creature); empty settings for a kind without them.

const QcWeatherDefinition &QcContentRegistry::weather() const

Returns what the weather does to the world.

See also setWeather().

QcBlockId QcContentRegistry::withProperty(QcBlockId id, const QString &property, const QString &value) const

Returns the state id with property set to value; id itself for unknown properties or values.

QcWorldgenCatalog &QcContentRegistry::worldgen()

Returns the biomes, features, ores, terrain, structures and world type settings (server side only).

const QcWorldgenCatalog &QcContentRegistry::worldgen() const

Returns the biomes, features, ores, terrain, structures and world type settings (server side only).

void QcContentRegistry::writeTo(QDataStream &stream) const

Writes the content to stream in the wire format of the content sync message (QcContentSerializer::write()).

Member Variable Documentation

const char *const QcContentRegistry::airName

The name of the air block, the block with id 0.