Chunk Generation API Functions

Back

You can call these functions from within the Chunk Generation Lua state. Note that you are inside that Lua state when the __main function of a block script is called by the engine. So roughly speaking, you can call these functions from within the __main function of every block script.

Clearing Everything

//Clearing all.
void clear_all(string block_type);

Getting "State" Variables

bool   state_get_b(string var);
int    state_get_i(string var);
float  state_get_f(string var);
Vector state_get_v(string var);
string state_get_s(string var);

Setting Chunk Variables

//Setting blocks variables of the block
//that is the current chunk being generated.
void chunk_set_b(string var, bool   value);
void chunk_set_i(string var, int    value);
void chunk_set_f(string var, float  value);
void chunk_set_v(string var, Vector value);
void chunk_set_s(string var, string value);

Setting Block Variables

//Setting block variables (of blocks within the chunk).
void block_set_b(int x, int y, int z, string var, bool value)
void block_set_i(int x, int y, int z, string var, int value)
void block_set_f(int x, int y, int z, string var, float value)
void block_set_v(int x, int y, int z, string var, Vector value)
void block_set_s(int x, int y, int z, string var, string value)

Block Type Integer Codes

int    bt_str_to_code(string block_type);
string bt_code_to_str(int block_type_code);

void set_default_block_c(int block_type_code);
void clear_blocks_c(int block_type_code);
void set_pos_c(int x, int y, int z, int block_type_code);
int  get_pos_c(int x, int y, int z);
void create_rect_c(
    int block_type_code,
    int min_x, int min_y, int min_z,
    int max_x, int max_y, int max_z);
void create_sprinkles_c(
    int min_x, int min_y, int min_z,
    int max_x, int max_y, int max_z,
    float prob,
    int block_type_code);

Blocks

//Basic block functions.
void set_default_block(string block_type);
void clear_blocks(string block_type);
void set_pos(int x, int y, int z, string block_type);
string get_pos(int x, int y, int z);

//More block functions.
void create_rect(
    string block_type,
    int min_x, int min_y, int min_z,
    int max_x, int max_y, int max_z);
void create_sprinkles(
    int min_x, int min_y, int min_z,
    int max_x, int max_y, int max_z,
    float prob, string block_type);

//Exotic block functions: Mazes.
void maze_start();
void maze_add_vertex(int x, int y, int z);
void maze_add_edge(
    int x1, int y1, int z1,
    int x2, int y2, int z2);
void maze_end();
bool maze_edge_open(
    int x1, int y1, int z1,
    int x2, int y2, int z2);
int maze_num_edges_from_vertex(
    int x, int y, int z);
POS maze_deepest_vertex(LIST source_vertices);

//Exotic block functions: Caves.
void caves_start();
void caves_set_5x5x5();
void caves_set_num_nodes(
    float min_nodes, float max_nodes);
void caves_set_nodes(
    float frac_large_node,
    float small_node_min_rad,
    float small_node_max_rad,
    float large_node_min_rad,
    float large_node_max_rad);
void caves_set_edges(
    float max_edge_dist,
    float frac_large_edge,
    float small_edge_min_rad,
    float small_edge_max_rad,
    float large_edge_min_rad,
    float large_edge_max_rad);
void caves_end();
bool caves_close_to_node(
    int x, int y, int z);
INFO caves_close_to_node2(
    int x, int y, int z);
bool caves_close_to_edge(
    int x, int y, int z);

Pseudo Random

//Pseudo random functions.
void srand(int seed);
float randf();
int randi(int min_i, int max_i);

Getting Time

int   get_sys_time();
float get_game_time();

Getting Chunk Generation Input

//Getting the input.
int    get_level();
int    get_input_path_length();
PATH   get_input_path();
BTS    get_input_path_bts();
string get_input_path_bt(int level);
string get_input_adj_bt(int dx, int dy, int dz);
string get_input_parent_adj_bt(int dx, int dy, int dz);
bool   get_input_path_block_var_exists(int level, string var, string type);
bool   get_input_path_block_b(int level, string var);
int    get_input_path_block_i(int level, string var);
float  get_input_path_block_f(int level, string var);
Vector get_input_path_block_v(int level, string var);
string get_input_path_block_s(int level, string var);

Creating Seeds from Chunk Generation Input

//Pseudo random seeds.
int seed_normal();
int seed_nearby(int dx, int dy, int dz);
int seed_xy();
int seed_xz();
int seed_yz();
int seed_normal_chop(int chop);
int seed_nearby_chop(int dx, int dy, int dz, int chop);
int seed_xy_chop(int chop);
int seed_xz_chop(int chop);
int seed_yz_chop(int chop);
int seed_from_last_of_type(string type);

Environment Rects

//Env rects.
void add_env_rect(
    int min_x, int min_y, int min_z,
    int max_x, int max_y, int max_z, string type);

Basic Entities

//Basic ents (BEnts).
void add_bent(int x, int y, int z, string type);
void add_bent_i(int x, int y, int z, string type, int param);
void add_bent_s(int x, int y, int z, string type, string param);
void bent_set_param_i(int x, int y, int z, int new_param_value);
void bent_set_param_s(int x, int y, int z, string new_param_value);

Moving Entities

//Moving ents (MEnts).
void add_ment(int x, int y, int z, string type);
void ment_start(int x, int y, int z, string type);
void ment_set_b(string key, bool value);
void ment_set_i(string key, int value);
void ment_set_f(string key, double value);
void ment_set_v(string key, float x, float y, float z);
void ment_set_s(string key, string value);
void ment_end();

Block Types

//Getting information about block types.
bool bt_get_is_solid_physically(string block_type);

Virtual Chunks

CLASS get_vchunk_data(int chop, int dx, int dy, int dz);
CLASS chunk_bbox_to_vchunk(int chop);

Perlin Noise

CLASS get_perlin_data_xyz(     int chop, int salt);
CLASS get_perlin_data_xyz_tail(int chop, int salt);
CLASS get_perlin_data_xy(      int chop, int salt);
CLASS get_perlin_data_xy_tail( int chop, int salt);

void cache_perlin_data_xyz(int handle, LIST seeds);
void cache_perlin_data_xy( int handle, LIST seeds);

float perlin_noise_xyz(int handle, float x, float y, float z);
float perlin_noise_xy( int handle, float x, float y);

Xar Chunk Generation

void create_xar_chunk(string bt);

Deprecated

//Do not use these functions.

//Blue type.
void set_blue_type_up();
void set_blue_type_down(int x, int y, int z);
void set_blue_type_terminal(int x, int y, int z);

Debugging

//Debugging functions.
void print(string str);
void exit();
void dump_lua_env();