Merge pull request #330 from MihailRis/item-models

Add item models
This commit is contained in:
MihailRis
2024-11-01 12:34:05 +03:00
committed by GitHub
66 changed files with 541 additions and 557 deletions
+31 -15
View File
@@ -10,55 +10,71 @@ static const ItemDef* get_item_def(lua::State* L, int idx) {
return indices->items.get(id);
}
static int l_item_name(lua::State* L) {
static int l_name(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
return lua::pushstring(L, def->name);
}
return 0;
}
static int l_item_index(lua::State* L) {
static int l_index(lua::State* L) {
auto name = lua::require_string(L, 1);
return lua::pushinteger(L, content->items.require(name).rt.id);
}
static int l_item_stack_size(lua::State* L) {
static int l_stack_size(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
return lua::pushinteger(L, def->stackSize);
}
return 0;
}
static int l_item_defs_count(lua::State* L) {
static int l_defs_count(lua::State* L) {
return lua::pushinteger(L, indices->items.count());
}
static int l_item_get_icon(lua::State* L) {
static int l_get_icon(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
switch (def->iconType) {
case item_icon_type::none:
case ItemIconType::NONE:
return 0;
case item_icon_type::sprite:
case ItemIconType::SPRITE:
return lua::pushstring(L, def->icon);
case item_icon_type::block:
case ItemIconType::BLOCK:
return lua::pushstring(L, "block-previews:" + def->icon);
}
}
return 0;
}
static int l_item_caption(lua::State* L) {
static int l_caption(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
return lua::pushstring(L, def->caption);
}
return 0;
}
static int l_placing_block(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
return lua::pushinteger(L, def->rt.placingBlock);
}
return 0;
}
static int l_model_name(lua::State* L) {
if (auto def = get_item_def(L, 1)) {
return lua::pushstring(L, def->modelName);
}
return 0;
}
const luaL_Reg itemlib[] = {
{"index", lua::wrap<l_item_index>},
{"name", lua::wrap<l_item_name>},
{"stack_size", lua::wrap<l_item_stack_size>},
{"defs_count", lua::wrap<l_item_defs_count>},
{"icon", lua::wrap<l_item_get_icon>},
{"caption", lua::wrap<l_item_caption>},
{"index", lua::wrap<l_index>},
{"name", lua::wrap<l_name>},
{"stack_size", lua::wrap<l_stack_size>},
{"defs_count", lua::wrap<l_defs_count>},
{"icon", lua::wrap<l_get_icon>},
{"caption", lua::wrap<l_caption>},
{"placing_block", lua::wrap<l_placing_block>},
{"model_name", lua::wrap<l_model_name>},
{NULL, NULL}};
+1 -1
View File
@@ -85,7 +85,7 @@ static int l_set_rot(lua::State* L) {
static int l_get_dir(lua::State* L) {
if (auto player = get_player(L, 1)) {
return lua::pushvec3(L, player->camera->front);
return lua::pushvec3(L, player->fpCamera->front);
}
return 0;
}