add block.is_extended, .get_size, .is_segment and .seek_origin
This commit is contained in:
parent
90ed175915
commit
1abb2cf327
@ -13,29 +13,32 @@
|
||||
#include "../../../content/Content.hpp"
|
||||
#include "../../../logic/BlocksController.hpp"
|
||||
|
||||
int l_block_name(lua_State* L) {
|
||||
static Block* require_block(lua_State* L) {
|
||||
auto indices = scripting::content->getIndices();
|
||||
lua_Integer id = lua_tointeger(L, 1);
|
||||
if (static_cast<size_t>(id) >= indices->countBlockDefs()) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
auto def = indices->getBlockDef(id);
|
||||
lua_pushstring(L, def->name.c_str());
|
||||
return 1;
|
||||
return indices->getBlockDef(id);
|
||||
}
|
||||
|
||||
int l_block_material(lua_State* L) {
|
||||
auto indices = scripting::content->getIndices();
|
||||
lua_Integer id = lua_tointeger(L, 1);
|
||||
if (static_cast<size_t>(id) >= indices->countBlockDefs()) {
|
||||
return 0;
|
||||
static int l_name(lua_State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
lua_pushstring(L, def->name.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto def = indices->getBlockDef(id);
|
||||
lua_pushstring(L, def->material.c_str());
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_is_solid_at(lua_State* L) {
|
||||
static int l_material(lua_State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
lua_pushstring(L, def->material.c_str());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_is_solid_at(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -44,18 +47,53 @@ int l_is_solid_at(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_blocks_count(lua_State* L) {
|
||||
static int l_count(lua_State* L) {
|
||||
lua_pushinteger(L, scripting::indices->countBlockDefs());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_block_index(lua_State* L) {
|
||||
static int l_index(lua_State* L) {
|
||||
std::string name = lua_tostring(L, 1);
|
||||
lua_pushinteger(L, scripting::content->requireBlock(name).rt.id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_set_block(lua_State* L) {
|
||||
static int l_is_extended(lua_State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
lua_pushboolean(L, def->rt.extended);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_get_size(lua_State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
return lua::pushivec3(L, def->size.x, def->size.y, def->size.z);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_is_segment(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
auto vox = scripting::level->chunks->get(x, y, z);
|
||||
|
||||
lua_pushboolean(L, vox->state.segment);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_seek_origin(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
auto vox = scripting::level->chunks->get(x, y, z);
|
||||
auto def = scripting::indices->getBlockDef(vox->id);
|
||||
|
||||
return lua::pushivec3(L, scripting::level->chunks->seekOrigin({x, y, z}, def, vox->state));
|
||||
}
|
||||
|
||||
static int l_set(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -76,7 +114,7 @@ int l_set_block(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_get_block(lua_State* L) {
|
||||
static int l_get(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -86,7 +124,7 @@ int l_get_block(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_get_block_x(lua_State* L) {
|
||||
static int l_get_x(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -103,7 +141,7 @@ int l_get_block_x(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
int l_get_block_y(lua_State* L) {
|
||||
static int l_get_y(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -120,7 +158,7 @@ int l_get_block_y(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
int l_get_block_z(lua_State* L) {
|
||||
static int l_get_z(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -137,7 +175,7 @@ int l_get_block_z(lua_State* L) {
|
||||
}
|
||||
}
|
||||
|
||||
int l_get_block_rotation(lua_State* L) {
|
||||
static int l_get_rotation(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -147,7 +185,7 @@ int l_get_block_rotation(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_set_block_rotation(lua_State* L) {
|
||||
static int l_set_rotation(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -156,7 +194,7 @@ int l_set_block_rotation(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_get_block_states(lua_State* L) {
|
||||
static int l_get_states(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -166,7 +204,7 @@ int l_get_block_states(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_set_block_states(lua_State* L) {
|
||||
static int l_set_states(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -182,7 +220,7 @@ int l_set_block_states(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_get_block_user_bits(lua_State* L) {
|
||||
static int l_get_user_bits(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -200,7 +238,7 @@ int l_get_block_user_bits(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_set_block_user_bits(lua_State* L) {
|
||||
static int l_set_user_bits(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -223,7 +261,7 @@ int l_set_block_user_bits(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_is_replaceable_at(lua_State* L) {
|
||||
static int l_is_replaceable_at(lua_State* L) {
|
||||
lua_Integer x = lua_tointeger(L, 1);
|
||||
lua_Integer y = lua_tointeger(L, 2);
|
||||
lua_Integer z = lua_tointeger(L, 3);
|
||||
@ -232,35 +270,36 @@ int l_is_replaceable_at(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_block_caption(lua_State* L) {
|
||||
auto indices = scripting::content->getIndices();
|
||||
lua_Integer id = lua_tointeger(L, 1);
|
||||
if (static_cast<size_t>(id) >= indices->countBlockDefs()) {
|
||||
return 0;
|
||||
static int l_caption(lua_State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
lua_pushstring(L, def->caption.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto def = indices->getBlockDef(id);
|
||||
lua_pushstring(L, def->caption.c_str());
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg blocklib [] = {
|
||||
{"index", lua_wrap_errors<l_block_index>},
|
||||
{"name", lua_wrap_errors<l_block_name>},
|
||||
{"material", lua_wrap_errors<l_block_material>},
|
||||
{"caption", lua_wrap_errors<l_block_caption>},
|
||||
{"defs_count", lua_wrap_errors<l_blocks_count>},
|
||||
{"index", lua_wrap_errors<l_index>},
|
||||
{"name", lua_wrap_errors<l_name>},
|
||||
{"material", lua_wrap_errors<l_material>},
|
||||
{"caption", lua_wrap_errors<l_caption>},
|
||||
{"defs_count", lua_wrap_errors<l_count>},
|
||||
{"is_solid_at", lua_wrap_errors<l_is_solid_at>},
|
||||
{"is_replaceable_at", lua_wrap_errors<l_is_replaceable_at>},
|
||||
{"set", lua_wrap_errors<l_set_block>},
|
||||
{"get", lua_wrap_errors<l_get_block>},
|
||||
{"get_X", lua_wrap_errors<l_get_block_x>},
|
||||
{"get_Y", lua_wrap_errors<l_get_block_y>},
|
||||
{"get_Z", lua_wrap_errors<l_get_block_z>},
|
||||
{"get_states", lua_wrap_errors<l_get_block_states>},
|
||||
{"set_states", lua_wrap_errors<l_set_block_states>},
|
||||
{"get_rotation", lua_wrap_errors<l_get_block_rotation>},
|
||||
{"set_rotation", lua_wrap_errors<l_set_block_rotation>},
|
||||
{"get_user_bits", lua_wrap_errors<l_get_block_user_bits>},
|
||||
{"set_user_bits", lua_wrap_errors<l_set_block_user_bits>},
|
||||
{"set", lua_wrap_errors<l_set>},
|
||||
{"get", lua_wrap_errors<l_get>},
|
||||
{"get_X", lua_wrap_errors<l_get_x>},
|
||||
{"get_Y", lua_wrap_errors<l_get_y>},
|
||||
{"get_Z", lua_wrap_errors<l_get_z>},
|
||||
{"get_states", lua_wrap_errors<l_get_states>},
|
||||
{"set_states", lua_wrap_errors<l_set_states>},
|
||||
{"get_rotation", lua_wrap_errors<l_get_rotation>},
|
||||
{"set_rotation", lua_wrap_errors<l_set_rotation>},
|
||||
{"get_user_bits", lua_wrap_errors<l_get_user_bits>},
|
||||
{"set_user_bits", lua_wrap_errors<l_set_user_bits>},
|
||||
{"is_extended", lua_wrap_errors<l_is_extended>},
|
||||
{"get_size", lua_wrap_errors<l_get_size>},
|
||||
{"is_segment", lua_wrap_errors<l_is_segment>},
|
||||
{"seek_origin", lua_wrap_errors<l_seek_origin>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -21,6 +21,13 @@ namespace lua {
|
||||
return 3;
|
||||
}
|
||||
|
||||
inline int pushivec3(lua_State* L, glm::ivec3 vec) {
|
||||
lua_pushinteger(L, vec.x);
|
||||
lua_pushinteger(L, vec.y);
|
||||
lua_pushinteger(L, vec.z);
|
||||
return 3;
|
||||
}
|
||||
|
||||
inline int pushvec3(lua_State* L, glm::vec3 vec) {
|
||||
lua_pushnumber(L, vec.x);
|
||||
lua_pushnumber(L, vec.y);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user