Advertisement
cragrim

Direwolf20mystcraft-books

Jun 20th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. -- All credit to Direwolf20 :) Instructions:
  2. -- https://www.youtube.com/watch?v=z6RmM7KP150
  3. -- Some slight modifications
  4. local data = {}
  5. rednet.open("right")
  6. p = peripheral.wrap("bottom")
  7.  
  8. function clearInv()
  9.    for i = 1,16 do
  10.       turtle.select(i)
  11.       turtle.dropDown()
  12.    end
  13. end
  14.  
  15. function checkSlots(id)
  16.    data = {}
  17.    local slot
  18.    local name
  19.    local slots = p.getAllStacks()
  20.    for i,j in pairs(slots) do
  21.       slot = i
  22.       name = j["destination"]
  23. --      print(name)
  24.       data[slot]=name
  25.    end
  26.    rednet.send(id,"done")
  27. end
  28.  
  29. function removeSlot(slot)
  30.    p.pushItem("up", slot, 1)
  31.    rs.setOutput("left", true)
  32.    sleep(1)
  33.    rs.setOutput("left", false)
  34. end
  35.  
  36. function book(slot,id)
  37.    p.pushItem("up", slot, 1)
  38.    turtle.select(1)
  39.    turtle.drop()
  40.    sleep(5)
  41.    getBook()
  42.    turtle.select(1)
  43.    turtle.dropDown()
  44.    rednet.send(tonumber(id), "done")
  45. end
  46.  
  47. function getBook()
  48.    turtle.suck()
  49. end
  50.  
  51. function getNames(id)
  52.    local nameTbl = textutils.serialize(data)
  53.    rednet.send(tonumber(id), nameTbl)
  54. end
  55.  
  56. clearInv()
  57.  
  58. while true do
  59.    local id, msg, dis = rednet.receive()
  60.    local newmsg = string.match(msg, "%a+")
  61. --   print(msg)
  62.    if newmsg == "checkSlots" then
  63.      checkSlots(id)
  64.    elseif newmsg == "getNames" then
  65.      getNames(id)
  66.    elseif newmsg == "remove" then
  67.      removeSlot(tonumber(string.match(msg, "%d+")))
  68.      rednet.send(id,"done")
  69.    elseif newmsg == "books" then
  70.      slot = string.match(msg, "%d+")
  71.      book(tonumber(slot), id)
  72.    end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement