Merge pull request #21 from Thomas--S/ta4-chest-itemstring

Lua Controller: Allow to get itemstring and description of 8x2000 chest contents
This commit is contained in:
Joachim Stolberg 2020-07-31 12:32:59 +02:00 committed by GitHub
commit 39d5704bff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -65,6 +65,16 @@ local function get_count(nvm, idx)
end
end
local function get_itemstring(nvm, idx)
if idx and idx > 0 then
nvm.inventory = nvm.inventory or {}
if nvm.inventory[idx] then
return nvm.inventory[idx].name or ""
end
end
return ""
end
local function inv_empty(nvm)
for _,item in ipairs(nvm.inventory or {}) do
if item.count and item.count > 0 then
@ -552,6 +562,9 @@ techage.register_node({"techage:ta4_chest"}, {
if topic == "count" then
local nvm = techage.get_nvm(pos)
return get_count(nvm, tonumber(payload) or 0)
elseif topic == "itemstring" then
local nvm = techage.get_nvm(pos)
return get_itemstring(nvm, tonumber(payload) or 0)
elseif topic == "state" then
local nvm = techage.get_nvm(pos)
return inv_state(nvm)

View File

@ -185,6 +185,19 @@ techage.lua_ctlr.register_action("door", {
" Hint: Use the Techage Programmer to\ndetermine the door position."
})
techage.lua_ctlr.register_function("item_description", {
cmnd = function(self, itemstring)
local item_def = minetest.registered_items[itemstring]
if item_def and item_def.description then
return item_def.description
end
return ""
end,
help = " $item_description(itemstring)\n"..
" Get the description for a specified itemstring.\n"..
' example: desc = $itemstring("default:apple")'
})
-- function not_protected(owner, number(s))
techage.lua_ctlr.not_protected = not_protected