Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local title = "SorteerToelie"
- local version = "v31.0.21_sikbeer1"
- local update_rate = .3 -- 1 second update time
- local barrels = 0
- local aantal = 0
- local posX, posY = 0
- local t1 = {
- name = "",
- item = "",
- aantal = 0,
- max = 0,
- order = 0
- }
- local t2 = {
- name = "",
- order = 0
- }
- local monitor = term.redirect(peripheral.find("monitor"))
- local function header()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.green)
- term.clear()
- term.setCursorPos(1,1)
- term.write(title .. " " .. version)
- term.setCursorPos(1,4)
- end
- local function getPeriphs()
- periphs = peripheral.getNames()
- table.sort(periphs)
- end
- local function makePeriphs()
- barrels = 0
- for i, name in pairs(periphs) do
- if peripheral.getType(name) == "mcp_mobius_betterbarrel" then
- local wrap = peripheral.wrap(name)
- if peripheral.isPresent(name) == true then
- item = wrap.getStoredItems()["display_name"]
- aantal = wrap.getStoredItems()["qty"]
- max = wrap.getMaxStoredItems()
- end
- t1[barrels] = {}
- t1[barrels].name = name
- t1[barrels].item = item
- t1[barrels].aantal = aantal
- t1[barrels].max = max
- barrels = barrels + 1
- end
- end
- end
- local function showPeriphs()
- header()
- term.setTextColor(colors.white)
- term.setCursorPos(4,5)
- term.write("Item")
- term.setCursorPos(44,5)
- term.write("Amount")
- term.setCursorPos(56,5)
- term.write("Max amount")
- term.setCursorPos(70,5)
- term.write("Order amount")
- x = 4
- i = 0
- r = 0
- repeat
- y = r + 6
- term.setCursorPos(x,y)
- term.setTextColor(colors.yellow)
- if (t1[i] ~= nil) then
- term.write(t1[i].item)
- end
- term.setCursorPos(x + 37,y)
- term.setTextColor(colors.blue)
- if (t1[i] ~= nil) then
- term.write(string.format("% 9d",t1[i].aantal))
- end
- term.setCursorPos(x + 53,y)
- term.setTextColor(colors.red)
- if (t1[i] ~= nil) then
- term.write(string.format("% 9d",t1[i].max))
- end
- term.setCursorPos(x + 67,y)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.blue)
- term.write(" + ")
- term.setBackgroundColor(colors.black)
- term.write(string.format("% 3d",t2[i].order))
- term.write(" ")
- term.setBackgroundColor(colors.blue)
- term.write(" - ")
- term.setBackgroundColor(colors.black)
- i = i + 1
- r = r + 1
- until (i == 32)
- end
- local function updatePeriphs()
- getPeriphs()
- makePeriphs()
- showPeriphs()
- end
- local function dumpItem(num,totaal)
- naam = t1[num]
- local wrap = peripheral.wrap(naam)
- wrap.pushItemIntoSlot("down",2,totaal,1)
- end
- local function checkClickPosition(mon)
- if posY >= 6 and posY <= 38 then
- if posX >= 71 and posX <= 73 then
- t2[posY - 6].order = t2[posY - 6].order + 1
- end
- if posX >= 78 and posX <= 80 then
- t2[posY - 6].order = t2[posY - 6].order - 1
- end
- end
- end
- getPeriphs()
- makePeriphs()
- for i = 0, 31 do
- t2[i] = {}
- t2[i].name = t1[i].name
- t2[i].order = 0
- end
- showPeriphs()
- local timer = os.startTimer(update_rate)
- while true do
- sleep(0)
- local event, p1, p2, p3 = os.pullEvent()
- if event == "timer" then
- updatePeriphs()
- timer = os.startTimer(update_rate)
- end
- if event == "peripheral" then
- updatePeriphs()
- end
- if event == "peripheral_detach" then
- updatePeriphs()
- end
- if event == "monitor_touch" then
- posX = p2
- posY = p3
- checkClickPosition(monitor)
- updatePeriphs()
- end
- if event == "key" then
- if p1 == keys.x then
- break
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement