Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local name = "ME Disposal"
- local version = "1.0a"
- local itemListFileName = "itemlist.txt"
- local itemList = {}
- function resetBridge()
- print("Unable to access ME Bridge.")
- print("Sending reset command to turtle.")
- redstone.setBundledOutput("left",1)
- while not colors.test(redstone.getBundledInput("left"),2) do
- os.sleep(1)
- end
- redstone.setBundledOutput("left",0)
- end
- local function doScreen(str)
- items = peripheral.call("bottom","listItems")
- while items == nil do
- resetBridge()
- os.sleep(1)
- items = peripheral.call("bottom","listItems")
- end
- term.clear()
- term.setCursorPos(1,1)
- print(name.." - ver "..version)
- print("------------------------------")
- print("Item | Max Qty | In ME")
- print("------------------------------")
- for i=1,#itemList do
- t=itemList[i]
- write(t[1])
- write(string.rep(" ",9-string.len(t[1])))
- write("| "..t[3])
- write(string.rep(" ",8-string.len(t[3])))
- write("| ")
- local found = false
- for id,qty in pairs(items) do
- if id==tonumber(t[2]) then
- print(qty)
- if qty>tonumber(t[3]) then
- discard = qty - tonumber(t[3])
- if discard > tonumber(t[4]) then
- discard = tonumber(t[4])
- end
- peripheral.call("bottom","retrieve",id,discard,0)
- end
- found = true
- end
- end
- if not found then
- print(0)
- end
- end
- print("------------------------------")
- print(str)
- end
- if not fs.exists(itemListFileName) then
- print("File ("..itemListFileName..") does not exist.")
- exit()
- end
- handle = fs.open(itemListFileName, "r")
- if handle == nil then
- print("Failed to open ("..itemListFileName..").")
- exit()
- end
- str = handle.readAll()
- for name,id,qty,stack in string.gmatch(str,"(%w+)|(%d+)|(%d+)|(%d+)") do
- table.insert(itemList,{name,id,qty,stack})
- end
- handle.close()
- if #itemList == 0 then
- print(itemListFileName.." contains no readable data.")
- exit()
- end
- while true do
- doScreen("")
- os.sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment