add drop-item model, new block functions

This commit is contained in:
MihailRis
2024-07-03 16:34:09 +03:00
parent 1c4e13dc67
commit 48b5be6bc9
11 changed files with 81 additions and 24 deletions
+14
View File
@@ -271,6 +271,19 @@ static int l_get_textures(lua::State* L) {
return 0;
}
static int l_get_model(lua::State* L) {
if (auto def = require_block(L)) {
switch (def->model) {
case BlockModel::block: return lua::pushstring(L, "block");
case BlockModel::aabb: return lua::pushstring(L, "aabb");
case BlockModel::xsprite: return lua::pushstring(L, "X");
case BlockModel::custom: return lua::pushstring(L, "custom");
case BlockModel::none: return lua::pushstring(L, "none");
}
return 0;
}
}
const luaL_Reg blocklib [] = {
{"index", lua::wrap<l_index>},
{"name", lua::wrap<l_name>},
@@ -295,5 +308,6 @@ const luaL_Reg blocklib [] = {
{"is_segment", lua::wrap<l_is_segment>},
{"seek_origin", lua::wrap<l_seek_origin>},
{"get_textures", lua::wrap<l_get_textures>},
{"get_model", lua::wrap<l_get_model>},
{NULL, NULL}
};
+14
View File
@@ -48,6 +48,19 @@ static int l_despawn(lua::State* L) {
return 0;
}
static int l_set_rig(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
auto assets = scripting::engine->getAssets();
std::string rigName = lua::require_string(L, 2);
auto rigConfig = assets->get<rigging::RigConfig>(rigName);
if (rigConfig == nullptr) {
throw std::runtime_error("rig not found '"+rigName+"'");
}
entity->setRig(rigConfig);
}
return 0;
}
static int l_get_pos(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
return lua::pushvec3_arr(L, entity->getTransform().pos);
@@ -160,6 +173,7 @@ const luaL_Reg entitylib [] = {
{"exists", lua::wrap<l_exists>},
{"spawn", lua::wrap<l_spawn>},
{"despawn", lua::wrap<l_despawn>},
{"set_rig", lua::wrap<l_set_rig>},
{NULL, NULL}
};