Advertisement
Ganeesya

classing

Apr 2nd, 2015
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. function loadList()
  2.     local r = {}
  3.     local f = fs.open("classlist","r") 
  4.     if f == nil then return r end
  5.  
  6.     local line = f.readLine()
  7.     while line do
  8.         r[line] = 1
  9.         write(line.."\n")
  10.         line = f.readLine()
  11.     end
  12.  
  13.     f.close()
  14.     return r
  15. end
  16.  
  17. function addList( add )
  18.     local f = fs.open("classlist","a")
  19.     f.writeLine(add)
  20.     write(add.."\n")
  21.     f.close()
  22. end
  23.  
  24. function isList(list,target)
  25.     if list[target] == nil then
  26.         return false
  27.     else
  28.         return true
  29.     end
  30. end
  31.  
  32. function checkSelf( list,self )
  33.     for k, v in pairs(self.getAllStacks()) do
  34.         if not isList(list,v.all().raw_name) then
  35.             addList(v.all().raw_name)
  36.             list[v.all().raw_name] = 1
  37.         end
  38.         turtle.select(k)
  39.         turtle.drop()
  40.     end
  41. end
  42.  
  43. local list = loadList()
  44. local chest = peripheral.wrap("front")
  45. local self = nil
  46.  
  47. for k, v in pairs(peripheral.getNames()) do
  48.     if peripheral.getType(v) == "tile_computercraft_turtle_name" then
  49.         self = peripheral.wrap(v)
  50.     end
  51. end
  52.  
  53. if not ( chest and chest.getInventorySize() > 20 ) then
  54.     write("need chest front.\n")
  55.     shell.exit()
  56. end
  57.  
  58. if not self then
  59.     write("need narcissictic turtle.\n")
  60.     shell.exit()
  61. end
  62.  
  63.  
  64. while true do
  65.     checkSelf(list,self)
  66.     local nonwait = false
  67.     for k, v in pairs(chest.getAllStacks()) do
  68.         if isList(list,v.all().raw_name) then
  69.             nonwait = chest.pushItem("down",k)
  70.         else
  71.             nonwait = chest.pushItem("up",k)
  72.         end
  73.         if not nonwait then sleep(1) end
  74.     end
  75.     sleep(0.1)
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement