Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local backgroundColor = colors.blue
- local altBackgroundColor = colors.lightBlue
- local greetingOne = "active link: "
- --"Please choose your"
- local greetingTwo = "no active link"
- --"destination"
- local timerDelay = 8
- -- computer front points northward
- local dirs = {front="north",left="east",back="south",right="west"}
- local dir = nil
- local mon = peripheral.find("monitor")
- local chest = nil
- local slot = nil
- for i,v in pairs(rs.getSides()) do
- if peripheral.getType(v) == "ender_chest" then
- chest = peripheral.wrap(v)
- dir = dirs[v]
- elseif peripheral.getType(v) == "book_receptacle" then
- slot = peripheral.wrap(v)
- end
- end
- if not chest or not dir or not slot or not mon then print("Error while trying to find chest, slot or monitor"); error() end
- local chestSlot = nil
- function removeActiveBook()
- if slot.getStackInSlot(1) then
- print("remove ",chestSlot)
- if chestSlot then
- if slot.pushItemIntoSlot(dir,1,1,chestSlot) ~=1 then
- if slot.pushItem(dir,1,1) ~= 1 then print("Error while moving book into chest"); error() end
- end
- chestSlot = nil
- else
- if slot.pushItem(dir,1,1) ~= 1 then print("Error while moving book to chest"); error() end
- end
- end
- end
- removeActiveBook()
- sleep(1)
- local nDest = 4
- local destTable = {}
- local timer = nil
- function padStr(str, len)
- if #str > len then do return string.sub(str,1,len) end
- else do return str .. string.rep(' ', len - #str) end
- end
- end
- function waitForTouchEvent()
- repeat
- event, side, monX, monY = os.pullEvent() --"monitor_touch")
- if event == "timer" and side == timer then
- removeActiveBook()
- drawUserInterface()
- end
- until event == "monitor_touch"
- removeActiveBook()
- if nDest > 0 and (monY-3 > 0) and (monY-3 <= nDest) then
- chestSlot = destTable[monY - 3]
- print("place ",chestSlot)
- if slot.pullItem(dir,chestSlot,1) ~= 1 then chestSlot = nil; print("Error while moving book to slot") end
- timer = os.startTimer(timerDelay)
- end
- end
- function drawUserInterface()
- destTable = {}
- local books = chest.getAllStacks()
- local monX, monY = mon.getSize()
- mon.setBackgroundColor(backgroundColor)
- mon.clear()
- mon.setCursorPos(1,1)
- local active = slot.getStackInSlot(1)
- if active and active.rawName == "item.myst.linkbook" then
- mon.write(greetingOne)
- mon.setCursorPos(1,2)
- mon.write(active.destination)
- else
- mon.write(greetingTwo)
- end
- --
- --mon.write(greetingTwo)
- nDest = 0
- local i = 0
- for n,book in pairs(books) do
- if book.rawName == "item.myst.linkbook" then
- i = i + 1
- destTable[i] = n
- mon.setCursorPos(1, i + 3)
- if (i % 2 == 0) then
- mon.setBackgroundColor(altBackgroundColor)
- else
- mon.setBackgroundColor(backgroundColor)
- end
- name = padStr(book.destination,monX)
- mon.write(name)
- end
- end
- if not i then
- mon.setCursorPos(1, 4)
- mon.write("No Entries")
- end
- nDest = #destTable
- end
- while true do
- drawUserInterface()
- waitForTouchEvent()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement