SHOW:
|
|
- or go back to the newest paste.
| 1 | local backgroundColor = colors.blue | |
| 2 | local altBackgroundColor = colors.lightBlue | |
| 3 | - | local greetingOne = "Please choose your" |
| 3 | + | local greetingOne = "active link: " |
| 4 | - | local greetingTwo = "destination" |
| 4 | + | --"Please choose your" |
| 5 | local greetingTwo = "no active link" | |
| 6 | --"destination" | |
| 7 | local timerDelay = 8 | |
| 8 | ||
| 9 | -- computer front points northward | |
| 10 | local dirs = {front="north",left="east",back="south",right="west"}
| |
| 11 | local dir = nil | |
| 12 | ||
| 13 | local mon = peripheral.find("monitor")
| |
| 14 | ||
| 15 | local chest = nil | |
| 16 | local slot = nil | |
| 17 | ||
| 18 | for i,v in pairs(rs.getSides()) do | |
| 19 | if peripheral.getType(v) == "ender_chest" then | |
| 20 | chest = peripheral.wrap(v) | |
| 21 | dir = dirs[v] | |
| 22 | elseif peripheral.getType(v) == "book_receptacle" then | |
| 23 | slot = peripheral.wrap(v) | |
| 24 | end | |
| 25 | end | |
| 26 | ||
| 27 | 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
| |
| 28 | ||
| 29 | - | if slot.pushItem(dir,1,1) ~= 1 then print("Error while moving book to chest"); error() end
|
| 29 | + | local chestSlot = nil |
| 30 | ||
| 31 | function removeActiveBook() | |
| 32 | if slot.getStackInSlot(1) then | |
| 33 | print("remove ",chestSlot)
| |
| 34 | if chestSlot then | |
| 35 | if slot.pushItemIntoSlot(dir,1,1,chestSlot) ~=1 then | |
| 36 | if slot.pushItem(dir,1,1) ~= 1 then print("Error while moving book into chest"); error() end
| |
| 37 | end | |
| 38 | chestSlot = nil | |
| 39 | else | |
| 40 | if slot.pushItem(dir,1,1) ~= 1 then print("Error while moving book to chest"); error() end
| |
| 41 | end | |
| 42 | end | |
| 43 | end | |
| 44 | ||
| 45 | removeActiveBook() | |
| 46 | sleep(1) | |
| 47 | ||
| 48 | local nDest = 4 | |
| 49 | local destTable = {}
| |
| 50 | local timer = nil | |
| 51 | ||
| 52 | function padStr(str, len) | |
| 53 | if #str > len then do return string.sub(str,1,len) end | |
| 54 | else do return str .. string.rep(' ', len - #str) end
| |
| 55 | end | |
| 56 | - | if slot.pullItem(dir,destTable[monY - 3],1) ~= 1 then print("Error while moving book to slot") end
|
| 56 | + | |
| 57 | ||
| 58 | function waitForTouchEvent() | |
| 59 | repeat | |
| 60 | event, side, monX, monY = os.pullEvent() --"monitor_touch") | |
| 61 | if event == "timer" and side == timer then | |
| 62 | removeActiveBook() | |
| 63 | drawUserInterface() | |
| 64 | end | |
| 65 | until event == "monitor_touch" | |
| 66 | removeActiveBook() | |
| 67 | if nDest > 0 and (monY-3 > 0) and (monY-3 <= nDest) then | |
| 68 | - | mon.write(greetingOne) |
| 68 | + | chestSlot = destTable[monY - 3] |
| 69 | - | mon.setCursorPos(1,2) |
| 69 | + | print("place ",chestSlot)
|
| 70 | - | mon.write(greetingTwo) |
| 70 | + | if slot.pullItem(dir,chestSlot,1) ~= 1 then chestSlot = nil; print("Error while moving book to slot") end
|
| 71 | timer = os.startTimer(timerDelay) | |
| 72 | end | |
| 73 | end | |
| 74 | ||
| 75 | function drawUserInterface() | |
| 76 | destTable = {}
| |
| 77 | local books = chest.getAllStacks() | |
| 78 | local monX, monY = mon.getSize() | |
| 79 | mon.setBackgroundColor(backgroundColor) | |
| 80 | mon.clear() | |
| 81 | mon.setCursorPos(1,1) | |
| 82 | local active = slot.getStackInSlot(1) | |
| 83 | if active and active.rawName == "item.myst.linkbook" then | |
| 84 | mon.write(greetingOne) | |
| 85 | mon.setCursorPos(1,2) | |
| 86 | mon.write(active.destination) | |
| 87 | else | |
| 88 | mon.write(greetingTwo) | |
| 89 | end | |
| 90 | -- | |
| 91 | --mon.write(greetingTwo) | |
| 92 | nDest = 0 | |
| 93 | local i = 0 | |
| 94 | for n,book in pairs(books) do | |
| 95 | if book.rawName == "item.myst.linkbook" then | |
| 96 | i = i + 1 | |
| 97 | destTable[i] = n | |
| 98 | mon.setCursorPos(1, i + 3) | |
| 99 | if (i % 2 == 0) then | |
| 100 | mon.setBackgroundColor(altBackgroundColor) | |
| 101 | else | |
| 102 | mon.setBackgroundColor(backgroundColor) | |
| 103 | end | |
| 104 | name = padStr(book.destination,monX) | |
| 105 | mon.write(name) | |
| 106 | end | |
| 107 | end | |
| 108 | if not i then | |
| 109 | mon.setCursorPos(1, 4) | |
| 110 | mon.write("No Entries")
| |
| 111 | end | |
| 112 | nDest = #destTable | |
| 113 | end | |
| 114 | ||
| 115 | while true do | |
| 116 | drawUserInterface() | |
| 117 | waitForTouchEvent() | |
| 118 | end |