QtCraft API C++ classes QML types Handbook

QcItemEntityManager Class

Dropped item stacks lying in the world. More...

Header: #include <server/items/QcItemEntityManager.h>

Public Types

struct Drop
struct TickCallbacks
GiveFunction
LoadedFunction

Public Functions

int activeCount() const
void adopt(const QList<QcItemEntityManager::Drop> &drops, const std::function<quint32 ()> &nextEntityId)
void clear()
bool crowded() const
qint64 discardedCount() const
QList<QcItemEntity> &editableItems()
const QList<QcItemEntity> &items() const
const QList<QcItemEntityManager::Drop> &queued() const
qsizetype removeWhere(const std::function<bool (const QcItemEntity &)> &match)
void restore(const QList<QcItemEntityManager::Drop> &drops, const std::function<quint32 ()> &nextEntityId)
void setLimits(qsizetype active, qsizetype queued, qsizetype total)
quint32 spawn(const QcItemEntityManager::Drop &drop, quint32 id)
quint32 spawnScattered(const QcItemStack &stack, const QcVec3 &position, quint32 id)
bool take(quint32 id, int count)
bool takeOne(quint32 id)
QList<QcItemEntityManager::Drop> takeQueued(const std::function<bool (const Drop &)> &match)
QList<QcVec3> takeStirred()
QList<QcItemEntity> tick(const QcBlockAccess &world, const QList<QcPickupPlayer> &players, double dt, const QcItemEntityManager::TickCallbacks &callbacks)

Static Public Members

const int activeLimit
const double despawnSeconds
const double driftSpeed
const double itemSize
const int mergeIntervalTicks
const double mergeRadius
const double pickupDelay
const double pickupReach
const int queueLimit
const double thrownPickupDelay
const int totalLimit

Detailed Description

They fall, slide to a stop, merge with equal stacks nearby, are picked up by players walking into them and despawn after a while. Only items in loaded chunks move and age; the others wait unchanged until their chunk loads again.

Items below QcWorld::voidLimitY are removed, and drops there never appear (decision E-288).

The number of items is bounded: above activeLimit awake items in loaded chunks new drops wait in a queue and appear as soon as older items are picked up or despawn. A chunk that loads with too many items keeps the surplus as surplus items (frozen, invisible) that wake up oldest first. The queue and the number of items (also those in unloaded chunks) are bounded as well, dropping the oldest when full.

Member Type Documentation

[alias] QcItemEntityManager::GiveFunction

Called when an item touches the player playerEntityId with its stack; returns how many items did not fit into the inventory.

[alias] QcItemEntityManager::LoadedFunction

Returns whether the chunk at position is loaded.

Member Function Documentation

int QcItemEntityManager::activeCount() const

Returns the awake items in loaded chunks after the last tick (plus drops spawned since).

void QcItemEntityManager::adopt(const QList<QcItemEntityManager::Drop> &drops, const std::function<quint32 ()> &nextEntityId)

Adds drops with ids from nextEntityId without clearing first: the drops of a chunk that came back (decision E-374).

void QcItemEntityManager::clear()

Removes every item and every waiting drop.

bool QcItemEntityManager::crowded() const

Returns whether the queue is at least half full. Drops that matter little (blocks broken by an explosion) stay away then, so the queue keeps room for what must not get lost (chest contents).

qint64 QcItemEntityManager::discardedCount() const

Returns the items removed because a limit was exceeded since the start.

QList<QcItemEntity> &QcItemEntityManager::editableItems()

Returns the items for moving them from outside their physics (pistons push them, decision E-337).

const QList<QcItemEntity> &QcItemEntityManager::items() const

Returns the awake items.

const QList<QcItemEntityManager::Drop> &QcItemEntityManager::queued() const

Returns the drops waiting to appear, oldest first.

qsizetype QcItemEntityManager::removeWhere(const std::function<bool (const QcItemEntity &)> &match)

Removes the awake items match picks (burning in lava). Returns how many.

void QcItemEntityManager::restore(const QList<QcItemEntityManager::Drop> &drops, const std::function<quint32 ()> &nextEntityId)

Replaces all items with drops, e.g. from a save; ids are assigned by nextEntityId.

void QcItemEntityManager::setLimits(qsizetype active, qsizetype queued, qsizetype total)

Sets the bounds: active awake items, queued waiting drops, total items.

quint32 QcItemEntityManager::spawn(const QcItemEntityManager::Drop &drop, quint32 id)

Adds drop as the item id, or queues it when too many items are active (more than a stack: the rest is queued). Returns id, 0 when queued, empty, unknown or in the void.

quint32 QcItemEntityManager::spawnScattered(const QcItemStack &stack, const QcVec3 &position, quint32 id)

Drops stack at position as the item id with a small random upward velocity (mined blocks, loot). Returns what spawn() returns.

bool QcItemEntityManager::take(quint32 id, int count)

Takes count items off the stack of item entity id (a hopper collecting a stack). Returns false when there is no such awake item or it has fewer.

bool QcItemEntityManager::takeOne(quint32 id)

Takes one item off the stack of item entity id (a seed planting itself); the entity goes when its stack is empty. Returns false when there is no such awake item.

QList<QcItemEntityManager::Drop> QcItemEntityManager::takeQueued(const std::function<bool (const Drop &)> &match)

Takes the waiting drops match picks out of the queue. Returns them in queue order.

QList<QcVec3> QcItemEntityManager::takeStirred()

Returns where items moved, appeared, grew by merging or woke from dormancy since the last call: sleeping hoppers below them wake (decision E-344); resting items cost nothing.

QList<QcItemEntity> QcItemEntityManager::tick(const QcBlockAccess &world, const QList<QcPickupPlayer> &players, double dt, const QcItemEntityManager::TickCallbacks &callbacks)

One tick of dt seconds in world: physics, pickup by players, merging, ageing and despawning, through callbacks. Returns the items that despawned of old age (the caller may plant saplings from them).

Member Variable Documentation

const double QcItemEntityManager::despawnSeconds

Seconds an item in a loaded chunk lasts.

const double QcItemEntityManager::driftSpeed

Speed in m/s that items in flowing liquid drift with along its current (decision E-296).

const double QcItemEntityManager::itemSize

Width and height of an item's box in blocks.

const int QcItemEntityManager::mergeIntervalTicks

Ticks between two merges.

const double QcItemEntityManager::mergeRadius

Equal stacks closer than this many blocks merge, every mergeIntervalTicks ticks.

const double QcItemEntityManager::pickupReach

Items touch a player when they are within the player's box grown by this much.