diff --git a/command.lua b/command.lua index 281d84b..ffaa369 100644 --- a/command.lua +++ b/command.lua @@ -357,3 +357,22 @@ function tubelib.put_item(inv, listname, item) end return false end + +-- Get the number of items from the given ItemList. +-- Returns nil if the number is not available. +function tubelib.get_num_items(inv, listname, num) + if inv:is_empty(listname) then + return nil + end + local size = inv:get_size(listname) + for idx = 1, size do + local items = inv:get_stack(listname, idx) + if items:get_count() >= num then + local taken = items:take_item(num) + inv:set_stack(listname, idx, items) + return taken + end + end + return nil +end + diff --git a/init.lua b/init.lua index 2e57f19..4a35cd5 100644 --- a/init.lua +++ b/init.lua @@ -11,6 +11,7 @@ History: 2017-09-08 v0.01 first version 2017-09-12 v0.02 bugfix in tubelib.get_pos() and others + 2017-09-21 v0.03 function get_num_items added ]]-- @@ -40,6 +41,8 @@ tubelib.knownNodes = { tubelib.legacyNodes = { ["default:chest_locked"] = true, ["default:chest"] = true, + ["default:chest_locked_open"] = true, + ["default:chest_open"] = true, ["default:furnace"] = true, ["default:furnace_active"] = true, }