Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- inventory to remove items from
- storage_controller = peripheral.wrap("occultism:storage_controller_0")
- -- inventory to store big amount of items in
- targetInventory = peripheral.wrap("minecraft:chest_0")
- if fs.exists("addItem") == false then
- shell.run("pastebin", "get", "8f0wHqLK", "addItem")
- shell.run("addItem")
- end
- -- Connect peripherals
- local sides = {"left", "right", "top", "bottom", "front", "back"}
- for i, side in ipairs(sides) do
- local device = peripheral.getType(side)
- if device == "modem" then
- rednet.open(side)
- elseif device == "monitor" then
- monitor = peripheral.wrap(side)
- elseif device then
- inventory = peripheral.wrap(side)
- end
- end
- -- load the list of wanted items
- wantedItems = dofile("wanteditems.lua")
- switchmenu = false
- targetName = peripheral.getName(targetInventory)
- function getItemCounts()
- -- keep track of the total amount of each item to be moved
- totalAmount = {}
- -- loop through all wanted items
- for wantedItemName, wantedAmount in pairs(wantedItems) do
- -- initialize the total amount of each item to be moved
- totalAmount[wantedItemName] = 0
- for slot, item in pairs(storage_controller.list()) do
- if item.name == wantedItemName then
- totalAmount[wantedItemName] = totalAmount[wantedItemName] + item.count
- -- print(wantedItemName, totalAmount[wantedItemName])
- end
- end
- end
- end
- function calculateDifference()
- removeAmount = {}
- for items, count in pairs(wantedItems) do
- -- removeAmount[items] = 0
- if totalAmount[items] > count then
- removeAmount[items] = totalAmount[items] - count
- term.setTextColor(colors.yellow)
- -- print(items, removeAmount[items])
- term.setTextColor(colors.white)
- suckItem(items, count)
- end
- end
- end
- function centerText(monitor, y, text)
- local w, h = monitor.getSize()
- local x = math.floor((w - string.len(text) + 2) / 2)
- monitor.setCursorPos(x , y)
- monitor.write(text)
- end
- function splitAndWrite(str)
- local index = string.find(str, " ")
- if index then
- local firstPart = string.sub(str, 1, index)
- local secondPart = string.sub(str, index+1)
- centerText(monitor, 4, firstPart)
- centerText(monitor, 5, secondPart)
- else
- centerText(monitor, 4, str)
- end
- end
- function suckItem(itemName, targetCount)
- monitor.setTextColor(colors.black)
- monitor.setBackgroundColor(colors.yellow)
- for slot, item in pairs(storage_controller.list()) do
- -- centerText(monitor, 3, screenKey)
- if item.name == itemName then
- while removeAmount[item.name] > 0 do
- if removeAmount[item.name] == 0 then
- break
- end
- if removeAmount[item.name] >= item.count then
- countCC = item.count
- else
- countCC = removeAmount[item.name]
- end
- local transferred = storage_controller.pushItems(peripheral.getName(targetInventory), slot, countCC)
- -- sleep(0.1)
- removeAmount[item.name] = removeAmount[item.name] - transferred
- -- print(slot, item.name, removeAmount[item.name], countCC)
- displayCount = removeAmount[item.name]
- monitor.clear()
- screenKey = string.match(item.name, ":(.*)")
- screenKey = string.gsub(screenKey, "_", " ")
- monitor.setTextScale(0.5)
- monitor.setCursorPos(1,1)
- splitAndWrite(screenKey)
- centerText(monitor, 6, tostring(displayCount))
- if item.count > 0 then
- suckItem(itemName, targetCount)
- end
- break
- end
- end
- end
- end
- function allthethings()
- getItemCounts()
- monitor.setBackgroundColor(colors.green)
- monitor.clear()
- centerText(monitor, 4, "Waiting")
- calculateDifference()
- sleep(1)
- end
- function switchToMenu()
- local event, key, isHeld = os.pullEvent("mouse_click")
- if event then
- switchmenu = true
- end
- end
- while true do
- term.clear()
- x, y = term.getSize()
- term.setCursorPos(9,y/2)
- print("Click to search and add items.")
- if switchmenu == true then
- shell.run("addItem")
- switchmenu = false
- end
- parallel.waitForAny(allthethings, switchToMenu)
- end
- -- scanAndSendInventories(targetInventory)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement