Lua Controller: Allow to get itemstring and description of 8x2000 chest contents
As suggested by the player "baumeister".
This commit is contained in:
parent
eac2cef4c7
commit
61f874a918
@ -65,6 +65,16 @@ local function get_count(nvm, idx)
|
|||||||
end
|
end
|
||||||
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)
|
local function inv_empty(nvm)
|
||||||
for _,item in ipairs(nvm.inventory or {}) do
|
for _,item in ipairs(nvm.inventory or {}) do
|
||||||
if item.count and item.count > 0 then
|
if item.count and item.count > 0 then
|
||||||
@ -552,6 +562,9 @@ techage.register_node({"techage:ta4_chest"}, {
|
|||||||
if topic == "count" then
|
if topic == "count" then
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
return get_count(nvm, tonumber(payload) or 0)
|
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
|
elseif topic == "state" then
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
return inv_state(nvm)
|
return inv_state(nvm)
|
||||||
|
@ -185,6 +185,19 @@ techage.lua_ctlr.register_action("door", {
|
|||||||
" Hint: Use the Techage Programmer to\ndetermine the door position."
|
" 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))
|
-- function not_protected(owner, number(s))
|
||||||
techage.lua_ctlr.not_protected = not_protected
|
techage.lua_ctlr.not_protected = not_protected
|
||||||
|
Loading…
Reference in New Issue
Block a user