added item.description() to itemlib, and update docs
This commit is contained in:
parent
b4d41a59e4
commit
59d706323a
@ -98,6 +98,13 @@ inventory.set_all_data(...)
|
|||||||
```
|
```
|
||||||
for moving is inefficient, use inventory.move or inventory.move_range.
|
for moving is inefficient, use inventory.move or inventory.move_range.
|
||||||
```lua
|
```lua
|
||||||
|
-- Get item caption
|
||||||
|
inventory.get_caption(
|
||||||
|
-- id of inventory
|
||||||
|
invid: int,
|
||||||
|
-- slot id
|
||||||
|
slot: int
|
||||||
|
)
|
||||||
-- Set item caption
|
-- Set item caption
|
||||||
inventory.set_caption(
|
inventory.set_caption(
|
||||||
-- id of inventory
|
-- id of inventory
|
||||||
@ -107,6 +114,13 @@ inventory.set_caption(
|
|||||||
-- Item Caption
|
-- Item Caption
|
||||||
caption: string
|
caption: string
|
||||||
)
|
)
|
||||||
|
-- Get item description
|
||||||
|
inventory.get_description(
|
||||||
|
-- id of inventory
|
||||||
|
invid: int,
|
||||||
|
-- slot id
|
||||||
|
slot: int
|
||||||
|
)
|
||||||
-- Set item description
|
-- Set item description
|
||||||
inventory.set_description(
|
inventory.set_description(
|
||||||
-- id of inventory
|
-- id of inventory
|
||||||
|
|||||||
@ -95,6 +95,13 @@ inventory.set_all_data(...)
|
|||||||
```
|
```
|
||||||
для перемещения вляется неэффективным, используйте inventory.move или inventory.move_range.
|
для перемещения вляется неэффективным, используйте inventory.move или inventory.move_range.
|
||||||
```lua
|
```lua
|
||||||
|
-- Получает имя предмета в слоте
|
||||||
|
inventory.get_caption(
|
||||||
|
-- id инвентаря
|
||||||
|
invid: int,
|
||||||
|
-- индекс слота
|
||||||
|
slot: int
|
||||||
|
)
|
||||||
-- Задает имя предмету в слоте
|
-- Задает имя предмету в слоте
|
||||||
inventory.set_caption(
|
inventory.set_caption(
|
||||||
-- id инвентаря
|
-- id инвентаря
|
||||||
@ -104,6 +111,13 @@ inventory.set_caption(
|
|||||||
-- Имя предмета
|
-- Имя предмета
|
||||||
caption: string
|
caption: string
|
||||||
)
|
)
|
||||||
|
-- Получает описание предмета в слоте
|
||||||
|
inventory.get_description(
|
||||||
|
-- id инвентаря
|
||||||
|
invid: int,
|
||||||
|
-- индекс слота
|
||||||
|
slot: int
|
||||||
|
)
|
||||||
-- Задает описание предмету в слоте
|
-- Задает описание предмету в слоте
|
||||||
inventory.set_description(
|
inventory.set_description(
|
||||||
-- id инвентаря
|
-- id инвентаря
|
||||||
|
|||||||
@ -10,6 +10,9 @@ item.index(name: str) -> int
|
|||||||
-- Возвращает название предмета, отображаемое в интерфейсе.
|
-- Возвращает название предмета, отображаемое в интерфейсе.
|
||||||
item.caption(itemid: int) -> str
|
item.caption(itemid: int) -> str
|
||||||
|
|
||||||
|
-- Возвращает описание предмета, отображаемое в интерфейсе.
|
||||||
|
item.description(itemid: int) -> str
|
||||||
|
|
||||||
-- Возвращает максимальный размер стопки для предмета.
|
-- Возвращает максимальный размер стопки для предмета.
|
||||||
item.stack_size(itemid: int) -> int
|
item.stack_size(itemid: int) -> int
|
||||||
|
|
||||||
|
|||||||
@ -128,6 +128,14 @@ function inventory.decrement(invid, slot, count)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function inventory.get_caption(invid, slot)
|
||||||
|
local item_id, count = inventory.get(invid, slot)
|
||||||
|
local caption = inventory.get_data(invid, slot, "caption")
|
||||||
|
if not caption then return item.caption(item_id) end
|
||||||
|
|
||||||
|
return caption
|
||||||
|
end
|
||||||
|
|
||||||
function inventory.set_caption(invid, slot, caption)
|
function inventory.set_caption(invid, slot, caption)
|
||||||
local itemid, itemcount = inventory.get(invid, slot)
|
local itemid, itemcount = inventory.get(invid, slot)
|
||||||
if itemid == 0 then
|
if itemid == 0 then
|
||||||
@ -139,6 +147,14 @@ function inventory.set_caption(invid, slot, caption)
|
|||||||
inventory.set_data(invid, slot, "caption", caption)
|
inventory.set_data(invid, slot, "caption", caption)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function inventory.get_description(invid, slot)
|
||||||
|
local item_id, count = inventory.get(invid, slot)
|
||||||
|
local description = inventory.get_data(invid, slot, "description")
|
||||||
|
if not description then return item.description(item_id) end
|
||||||
|
|
||||||
|
return description
|
||||||
|
end
|
||||||
|
|
||||||
function inventory.set_description(invid, slot, description)
|
function inventory.set_description(invid, slot, description)
|
||||||
local itemid, itemcount = inventory.get(invid, slot)
|
local itemid, itemcount = inventory.get(invid, slot)
|
||||||
if itemid == 0 then
|
if itemid == 0 then
|
||||||
|
|||||||
@ -57,6 +57,13 @@ static int l_caption(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_description(lua::State* L) {
|
||||||
|
if (auto def = get_item_def(L, 1)) {
|
||||||
|
return lua::pushstring(L, def->description);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_placing_block(lua::State* L) {
|
static int l_placing_block(lua::State* L) {
|
||||||
if (auto def = get_item_def(L, 1)) {
|
if (auto def = get_item_def(L, 1)) {
|
||||||
return lua::pushinteger(L, def->rt.placingBlock);
|
return lua::pushinteger(L, def->rt.placingBlock);
|
||||||
@ -108,6 +115,7 @@ const luaL_Reg itemlib[] = {
|
|||||||
{"defs_count", lua::wrap<l_defs_count>},
|
{"defs_count", lua::wrap<l_defs_count>},
|
||||||
{"icon", lua::wrap<l_get_icon>},
|
{"icon", lua::wrap<l_get_icon>},
|
||||||
{"caption", lua::wrap<l_caption>},
|
{"caption", lua::wrap<l_caption>},
|
||||||
|
{"description", lua::wrap<l_description>},
|
||||||
{"placing_block", lua::wrap<l_placing_block>},
|
{"placing_block", lua::wrap<l_placing_block>},
|
||||||
{"model_name", lua::wrap<l_model_name>},
|
{"model_name", lua::wrap<l_model_name>},
|
||||||
{"emission", lua::wrap<l_emission>},
|
{"emission", lua::wrap<l_emission>},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user