Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local api = {}
- function api.getStorageCounts(itemCounts)
- local storageCounts = {}
- for key, _ in pairs(toLuaTable(itemCounts)) do
- storageCounts[key] = 0
- end
- local storage = peripheral.wrap("bottom")
- for _, item in pairs(storage.list()) do
- if storageCounts[item.name] then
- storageCounts[item.name] = storageCounts[item.name] + item.count
- end
- end
- return toTurtiTable(storageCounts)
- end
- function api.pullCraftingItems(config, targetCount)
- config = toLuaTable(config)
- local pulled = {}
- for key, _ in pairs(config) do
- pulled[key] = 0
- end
- local storage = peripheral.wrap("bottom")
- local chest = peripheral.wrap("left")
- for sourceSlot, item in pairs(storage.list()) do
- for targetSlot, name in pairs(config) do
- if item.name == name and pulled[targetSlot] < targetCount then
- local toPull = targetCount - pulled[targetSlot]
- --storage.pullItems(peripheral.getName(storage), )
- end
- end
- end
- end
- function api.printItemCounts()
- local counts = {}
- local itemNames = {}
- local foundOne = false
- for i = 1, 16 do
- local detail = turtle.getItemDetail(i, true)
- if detail ~= nil then
- if counts[detail.name] == nil then
- counts[detail.name] = detail.count
- else
- counts[detail.name] = counts[detail.name] + detail.count
- end
- itemNames[detail.name] = detail.displayName
- foundOne = true
- end
- end
- if not foundOne then
- return
- end
- local storage = peripheral.wrap("bottom")
- for _, item in pairs(storage.list()) do
- if counts[item.name] then
- counts[item.name] = counts[item.name] + item.count
- end
- end
- local c = 0
- term.clear()
- term.setCursorPos(1, 1)
- for name, count in pairs(counts) do
- if c == 12 then
- c = 0
- term.setTextColor(256)
- io.write("Press Enter to continue")
- term.setTextColor(1)
- io.read()
- term.clear()
- term.setCursorPos(1, 1)
- end
- io.write(itemNames[name] .. " ")
- term.setTextColor(8192)
- io.write(tostring(count))
- term.setTextColor(1)
- print("")
- c = c + 1
- end
- term.setTextColor(256)
- term.setCursorPos(1, 13)
- io.write("Press Enter to continue")
- term.setTextColor(1)
- io.read()
- end
- return {
- name = "searchLib",
- api = api
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement