Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- return true if two items are identical
- function isItemIdentical(item1, item2, ignoreQty)
- if not item1 then
- error("First item cannot be nil.")
- end
- if not item2 then
- error("Second item cannot be nil")
- end
- return compareItems(item1, item2, ignoreQty) and compareItems(item2, item1, ignoreQty)
- end
- -- compare recursively two items
- function compareItems(item1, item2, ignoreQty)
- for k,v in pairs(item1) do
- if type(v) ~= type(item2[k]) then
- return false
- end
- if type(v) == "table" then
- if not compareItems(v, item2[k], ignoreQty) then
- return false
- end
- else
- if (not ignoreQty and v ~= item2[k]) or (k ~= "qty" and v ~= item2[k]) then
- return false
- end
- end
- end
- return true
- end
- -- check if an item is present in a list of items
- function isItemInList(item1, itemList, ignoreQty)
- for k,item2 in pairs(itemList) do
- if isItemIdentical(item1, item2, ignoreQty) then
- return k
- end
- end
- return false
- end
- -- compare two list of items recursively
- function isItemListIdentical(items1, items2, ignoreQty)
- for _,item1 in pairs(items1) do
- if not isItemInList(item1, items2, ignoreQty) then
- return false
- end
- end
- for _,item2 in pairs(items2) do
- if not isItemInList(item2, items1, ignoreQty) then
- return false
- end
- end
- return true
- end
- -- returns true if the container contains an item, if no item specified then check for any item
- function containsItem(container, item)
- if container == nil then
- error("Container peripheral is nil")
- end
- for i=1,container.getInventorySize() do
- local item2 = container.getStackInSlot(i)
- if (item and isItemIdentical(item, item2, false)) or (not item and item2) then
- return true
- end
- end
- return false
- end
- -- move all items from a container to another
- function moveAllItems(container, outputContainerSide, delay)
- if container == nil then
- error("Container peripheral is nil")
- end
- for i=1,container.getInventorySize() do
- container.pushItem(outputContainerSide, i)
- if delay ~= nil then
- sleep(delay)
- end
- end
- end
Add Comment
Please, Sign In to add comment