Skip to content

CBL API

Simon816 edited this page May 17, 2020 · 1 revision

There are several built-in APIs in CBL that cover core features of Minecraft as well as providing utilities for building higher-order types.

Basic Types

void

The empty type. Only valid for return types.

int

Outline

type int {
    bool operator ||(int other);
    bool operator &&(int other);
    int operator |(int other);
    int operator ^(int other);
    int operator &(int other);
    bool operator ==(int other);
    bool operator !=(int other);
    bool operator <=(int other);
    bool operator >=(int other);
    bool operator <(int other);
    bool operator >(int other);
    int operator <<(int other);
    int operator >>(int other);
    int operator +(int other);
    int operator -(int other);
    int operator *(int other);
    int operator /(int other);
    int operator %(int other);
    int operator +();
    int operator -();
    int operator ~();
    int operator !();
    int operator ++();
    int operator ++(int dummy);
    int operator --();
    int operator --(int dummy);
}

Basic 32 signed integer. Operators are the same as C/C++ operators.

bool

Outline

type bool {
    bool operator ||(bool other);
    bool operator &&(bool other);
    bool operator !();
}

Basic boolean type. Internally mapped to int.

decimal

Outline

type decimal {
    decimal operator ==(decimal other);
    decimal operator !=(decimal other);
    decimal operator <=(decimal other);
    decimal operator >=(decimal other);
    decimal operator <(decimal other);
    decimal operator >(decimal other);
    decimal operator +(decimal other);
    decimal operator -(decimal other);
    decimal operator *(decimal other);
    decimal operator /(decimal other);
    decimal operator %(decimal other);
    decimal operator +();
    decimal operator -();
}

Fixed point fractional value. A Q Number with 10 fractional bits.

string

Represents a string in the compiler. Has no runtime representation. Must be a literal string.

Maybe<T>

Outline

type Maybe<T> {
    constructor();
    constructor(T value);
    bool isEmpty();
    T get();
    Maybe<T> operator =(T value);
}

A generic type that optionally contains type T. There is no NULL in CBL, instead, Maybe<T> can be used to represent an empty value.

_IRType

Represents a type native to Command IR. Used internally.

Entity API

Entity

Outline

type Entity {
    __EntityPtr _ptr;

    constructor(__EntityPtr ptr);

    property EntityPos pos();
    property World world();
    property RuntimeEntityType type();

    Entity operator =(Entity other);
    void kill();
    SelectorFilter has_tag(string tag);
}

Represents an in-game entity. Not usually constructed manually (__EntityPtr is an internal type).

EntityLocal<T>

Outline

type EntityLocal<T> {
    T global;
    T operator[](Entity entity);
}

Represents a variable "local" to an entity i.e. a mapping of entity -> value. Currently only EntityLocal<int> is supported.

EntityPos

Outline

type EntityPos {
    __EntityPtr _ptr;

    constructor(__EntityPtr ptr);
    property EntityPosComponent x();
    property EntityPosComponent y();
    property EntityPosComponent z();
    vec3d as_vec();
}

Position of an entity. Can be converted to vec3d.

EntityPosComponent

Outline

type EntityPosComponent : decimal {
}

A decimal backed by an entity position rather than a scoreboard/NBT value.

EntityCollection

Outline

type EntityCollection {
    Entity first();
    EntityCollection sortNearest();
}

EntityType

Outline

type EntityType {
}

Type of an entity. Represented in the compiler.

Represents a collection of entities.

Entities

singleton Entities {
    EntityType area_effect_cloud;
    EntityType armor_stand;
    ...
}

All vanilla entity types.

RuntimeEntityType

Outline

type RuntimeEntityType {
    __EntityPtr _ptr;
    SelectorFilter operator==(EntityType other);
}

The type of entity represented at runtime.

SelectorFilter

Outline

type SelectorFilter {
}

A type that represents a filter for a selector. Used in filter (...) { ... } expressions.

Vector API

vec3<T>

Outline

type vec3<T> {
    T x;
    T y;
    T z;

    constructor(T x, T y, T z);

    vec3<T> operator *(T scalar);
}

A 3 dimensional vector of generic type T.

Built-in derivative types:

type vec3i is vec3<int>;

type vec3d: vec3<decimal> {
    constructor(decimal x, decimal y, decimal z);
    vec3i to_int();
}

World API

World

Outline

type World {
    __EntityPtr _ptr;

    constructor(__EntityPtr ptr);
    void spawn(EntityType type, vec3i pos);
}

Represents a minecraft world.

Block API

BlockType

Outline

type BlockType {
}

Blocks

Outline

singleton Blocks {
    BlockType air;
    BlockType stone;
    ...
}

Item API

ItemType

Outline

type ItemType {
}

Items

Outline

singleton Items {
    ItemType air;
    ItemType stone;
    ...
}

Event API

TagEvent

Outline

type TagEvent {
    void fire();
}

AdvEvent

Outline

type AdvEvent {
}

Events

singleton Events {
    TagEvent tick = TagEvent("minecraft:tick");
    TagEvent load = TagEvent("minecraft:load");
    ...
}

Game API

Game

Outline

singleton Game {
    EntityCollection entities;
    async void tick();
}

Text API

Text

Outline

type Text {
    _IRType _text;

    void append_ref(int &ref);
    Text operator+=(int val);
    Text operator+=(string str);
    Text operator<<(int val);
    Text operator<<(string str);
    Text operator=(Text other);
    void send_to_all();
}