QtCraft API C++ classes QML types Handbook

QcBlockScreens Class

The screens of containers and machines the players have open (chests, hoppers, dispensers, furnaces, container minecarts): opening, closing, sending their state. More...

Header: #include <server/machines/QcBlockScreens.h>

Public Types

struct OpenContainer

Public Functions

void close(QcServerClient &client, bool notify)
void closeAnvil(QcServerClient &client)
void closeEnchanting(QcServerClient &client)
void closeStonecutter(QcServerClient &client)
void containerChanged(QcServerClient &client, const QcBlockScreens::OpenContainer &container, bool changed)
void endTrade(QcServerClient &client)
void open(QcServerClient &client, QcBlockPos pos)
void openCart(QcServerClient &client, const QcMinecart &cart)
std::optional<QcBlockScreens::OpenContainer> openContainerOf(QcServerClient &client)
std::optional<QList<QcItemStack>> openHeld(QcServerClient &client)
QcBlockEntities::Machine *openMachineOf(const QcServerClient &client)
void send(QcServerClient &client, bool force = false)
void sendToCartViewers(quint32 cart)
void sendToViewers(QcBlockPos pos)
void setAnvilCloser(std::function<void (QcServerClient &)> closer)
void setEnchantingCloser(std::function<void (QcServerClient &)> closer)
void setStonecutterCloser(std::function<void (QcServerClient &)> closer)
void update()

Static Public Members

void releaseViewers(QcServerState &state, QcChunkPos chunk)

Detailed Description

A container whose signal counts its viewers (the trapped chest, decision E-783) shows in its state power how many players look into it, at most 15. Storage blocks sound as they open and close (QcContainerSounds).

Member Function Documentation

void QcBlockScreens::close(QcServerClient &client, bool notify)

Forgets the open machine of client; notify tells the client (the server closed it).

void QcBlockScreens::closeAnvil(QcServerClient &client)

Closes the open anvil of client (with notice; its slots go back), if any.

void QcBlockScreens::closeEnchanting(QcServerClient &client)

Closes the open enchanting table of client (with notice; its slots go back), if any.

void QcBlockScreens::closeStonecutter(QcServerClient &client)

Closes the open stonecutter of client (with notice; its input goes back), if any.

void QcBlockScreens::containerChanged(QcServerClient &client, const QcBlockScreens::OpenContainer &container, bool changed)

The slots of the container client has open changed: everyone looking into it sees them, comparators and hoppers around hear of it when changed. A held backpack has no place in the world: only its holder sees it.

void QcBlockScreens::endTrade(QcServerClient &client)

Ends the trading screen of client (with notice), if any; QcServerTrading::update releases the villager.

void QcBlockScreens::open(QcServerClient &client, QcBlockPos pos)

Opens the machine or chest screen of the block at pos for the player client.

void QcBlockScreens::openCart(QcServerClient &client, const QcMinecart &cart)

Opens the screen of the container minecart cart for the player client.

std::optional<QcBlockScreens::OpenContainer> QcBlockScreens::openContainerOf(QcServerClient &client)

Returns the open chest, container cart or held backpack of the player client while it still exists, else nothing.

std::optional<QList<QcItemStack>> QcBlockScreens::openHeld(QcServerClient &client)

Opens the backpack client holds (a portable container in the selected hotbar slot, decision E-833): its slots and the hotbar, its own slot locked. Contents its slots cannot show (beyond the slot count, or refused there) leave the item and are returned for the caller to give to the player, so the first click into the screen cannot delete them. Returns those contents, or nothing when the player holds no backpack.

QcBlockEntities::Machine *QcBlockScreens::openMachineOf(const QcServerClient &client)

Returns the open machine of the player client while it still exists, else null.

[static] void QcBlockScreens::releaseViewers(QcServerState &state, QcChunkPos chunk)

Nobody looks into the containers of chunk of state, which just arrived: those that count their viewers start at 0 whatever was saved.

void QcBlockScreens::send(QcServerClient &client, bool force = false)

Sends the state of the machine client has open if it changed since the last message (or always with force).

void QcBlockScreens::sendToCartViewers(quint32 cart)

Sends the slots of the minecart cart to every player looking into it.

void QcBlockScreens::sendToViewers(QcBlockPos pos)

Sends the state to every player looking into the machine or chest at pos.

void QcBlockScreens::setAnvilCloser(std::function<void (QcServerClient &)> closer)

Sets the closer of an open anvil, as setStonecutterCloser(); set by QcServerAnvil (decision E-866).

void QcBlockScreens::setEnchantingCloser(std::function<void (QcServerClient &)> closer)

Sets the closer of an open enchanting table, as setStonecutterCloser(); set by QcServerEnchanting (decision E-864).

void QcBlockScreens::setStonecutterCloser(std::function<void (QcServerClient &)> closer)

Sets the closer, how an open stonecutter is closed (QcServerStonecutter::close with notice, which gives its input back) when a block's, cart's or villager's screen opens; set by QcServerStonecutter.

void QcBlockScreens::update()

Once per tick: sends what changed, closes screens whose block is gone, whose chunk unloaded or whose player died or walked away; containers that count their viewers take the new count, and containers opened or closed since the last tick sound.