QtCraft API C++ classes QML types Handbook

QcRails Namespace

Rails (decision E-382): the track a rail state lays out and the state a rail takes from the rails around it. More...

Header: #include <common/blockrules/QcRails.h>

Classes

struct Behaviour
struct End
struct Joint
struct Line
class Table
struct Track

Types

enum class Kind { Straight, Ascending, Curve }

Variables

const std::size_t shapeNeighbourCount

Functions

QcVec3 endPoint(QcBlockPos cell, QcRails::End end)
bool isRail(const QcContentRegistry &content, QcBlockId block)
std::optional<QcRails::Joint> joined(const QcBlockAccess &world, const QcRails::Table &rails, QcBlockPos cell, QcRails::Track track, int end)
QcRails::Line lineOf(const QcBlockAccess &world, const QcRails::Table &rails, QcBlockPos cell, int reach)
std::array<QcBlockPos, shapeNeighbourCount> shapeNeighbours(QcBlockPos pos)
QcBlockId shapedState(const QcBlockAccess &world, QcBlockPos pos, QcBlockId id, std::optional<QcBlockFace> lookSide)
std::array<QcBlockPos, 8> slopeNeighbours(QcBlockPos pos)
QcBlockId stateOf(const QcContentRegistry &content, QcBlockId block, QcRails::Kind kind, QcBlockFace facing)
std::optional<QcRails::Track> trackOf(const QcContentRegistry &content, QcBlockId block)

Detailed Description

A track runs straight through its cell along facing (straight), rises towards facing by one block (ascending) or bends from facing to the side clockwise of it (curve); a straight track faces north or east. A rail connects towards every side where a rail lies level with it, or one block higher (it rises there) or lower when that rail, shaped by the rails around it, reaches this one; the rules depend only on where rails lie, never on the order of the updates, so a layout behaves the same in every rotation and mirror image.

Classes

class Behaviour

What a rail state does to the carts on it (decision E-384). More...

class End

One end of a track: the middle of the cell's side side (north, east, south or west), at the bottom of the cell or, when raised, at its top. More...

class Joint

The cell of the rail whose track meets end end of the track track in cell (the same height, one higher or one lower beside it), and which of its ends meets it; nothing at the end of a line. More...

class Line

The rails of the same block as the rail at cell along its line, at most reach each way, in the order of the line (from the end of its first track end to that of its second), cell among them at index (the lines of powered and activator rails, decision E-384). More...

class Table

The track and behaviour of every block state of a content, looked up once (carts ask every tick). More...

class Track

The track a rail state lays out through its cell. More...

Type Documentation

enum class QcRails::Kind

The layouts of a track (see the namespace).

ConstantValueDescription
QcRails::Kind::Straight0Straight through the cell along its facing.
QcRails::Kind::Ascending1Rising by one block towards its facing.
QcRails::Kind::Curve2Bending from its facing to the side clockwise of it.

Variable Documentation

const std::size_t QcRails::shapeNeighbourCount

The number of shapeNeighbours().

Function Documentation

QcVec3 QcRails::endPoint(QcBlockPos cell, QcRails::End end)

Returns where end of the track in cell lies in the world.

bool QcRails::isRail(const QcContentRegistry &content, QcBlockId block)

Returns whether block is a valid block state of content and a rail.

std::optional<QcRails::Joint> QcRails::joined(const QcBlockAccess &world, const QcRails::Table &rails, QcBlockPos cell, QcRails::Track track, int end)

Returns the rail in world that meets end end (0 or 1) of track in cell, with the tracks of rails; nothing at the end of a line.

QcRails::Line QcRails::lineOf(const QcBlockAccess &world, const QcRails::Table &rails, QcBlockPos cell, int reach)

Returns the line of the rail at cell in world, at most reach rails each way, with the tracks of rails; empty when there is no rail at cell. A loop ends where it meets itself.

std::array<QcBlockPos, shapeNeighbourCount> QcRails::shapeNeighbours(QcBlockPos pos)

Returns the positions besides the six neighbours whose rail may change shape when a rail at pos comes or goes: the slope neighbours, and every rail that has a rail one block higher or lower beside it whose own neighbours include pos (whether that rail meets it depends on them). Up to two blocks away sideways and two up or down.

QcBlockId QcRails::shapedState(const QcBlockAccess &world, QcBlockPos pos, QcBlockId id, std::optional<QcBlockFace> lookSide)

Returns the state the rail id at pos takes from the rails around it in world. lookSide (the direction the placing player looks) decides between the two straight layouts where the neighbours do not (none or all four sides); without it the rail keeps its axis. A neighbour in a chunk that is not loaded, or a neighbour of a rail one higher or lower beside it, keeps the rail as it is (loading the chunk updates it).

std::array<QcBlockPos, 8> QcRails::slopeNeighbours(QcBlockPos pos)

Returns the eight positions one block higher or lower beside pos (slopes): the rails there meet a rail at pos, and their power lines run through it (decision E-384).

QcBlockId QcRails::stateOf(const QcContentRegistry &content, QcBlockId block, QcRails::Kind kind, QcBlockFace facing)

Returns the state of the rail block of content (any state of it) laid out as kind facing facing.

std::optional<QcRails::Track> QcRails::trackOf(const QcContentRegistry &content, QcBlockId block)

Returns the track of the rail state block of content; nothing for other blocks.