Advertisement
bota

AE Crystals V2

Aug 1st, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.03 KB | None | 0 0
  1. local done = false
  2. local sleepp = 5
  3. local Debug = 2 --[[ 1 - on, 2 - off ]]
  4.  
  5. function Clear()
  6.     term.clear()
  7.     term.setCursorPos(1,1)
  8. end
  9.  
  10. function Bed()
  11.     local bed1 = sleepp
  12.     local bed2 = bed1 * 0.25
  13.     local bed3 = bed1 * 0.50
  14.     local bed4 = bed1 * 0.75
  15.  
  16.     print("Sleep ",bed1,"s more...")
  17.     sleep(bed2)
  18.     print("Sleep ",bed4,"s more...")
  19.     sleep(bed2)  
  20.     print("Sleep ",bed3,"s more...")
  21.     sleep(bed2)
  22.     print("Sleep ",bed2,"s more...")
  23.     sleep(bed2)
  24.     Clear()
  25. end
  26.  
  27. function Waiting()
  28.     Clear()
  29.     print("Waiting for job")
  30.     local event, p1 = os.pullEvent("turtle_inventory")
  31.     os.reboot()
  32. end
  33.  
  34. function sDown()
  35.     if Debug == 1 then
  36.         print("sDown")
  37.     end
  38.     for d = 1,12 do
  39.         turtle.select(d)
  40.         turtle.dropDown()
  41.     end
  42.     turtle.select(1)
  43.     for i = 1,12 do  
  44.         turtle.suckDown()
  45.     end
  46. end
  47.  
  48. function FileCheck()
  49.     if Debug == 1 then
  50.         print("FileCheck")
  51.     end
  52.     local file = fs.open("IterationFile", "r")
  53.     Iteration = file.readAll() 
  54.     file.close()
  55. end
  56.  
  57. function CheckItems()
  58.     if Debug == 1 then
  59.         print("CheckItems")
  60.     end
  61.     turtle.select(1)
  62.     if (turtle.getItemCount(1) == 0) then
  63.         FileCheck()
  64.         if tonumber(Iteration)>0 then
  65.             Iteration2 = Iteration - 1
  66.            
  67.             IterFile = io.open("IterationFile", "w")
  68.             IterFile : write(Iteration2)
  69.             IterFile : close()
  70.         else
  71.             IterFile = io.open("IterationFile", "w")
  72.             IterFile : write(2)
  73.             IterFile : close()
  74.             Waiting()
  75.         end
  76.     else
  77.         CompareTo()
  78.     end
  79. end
  80.  
  81. function CompareTo()
  82.     if Debug == 1 then
  83.         print("CompareTo")
  84.     end
  85.     for i = 1,12 do
  86.         turtle.select(i)
  87.         done = turtle.compareTo(16) or turtle.compareTo(15) or turtle.compareTo(14) or turtle.compareTo(13)
  88.         if done then
  89.             turtle.drop()
  90.         elseif turtle.compareTo(15) then
  91.         else
  92.             turtle.dropDown()
  93.         end
  94.     end
  95. end
  96.  
  97. function NewFile()
  98.     if Debug == 1 then
  99.         print("NewFile")
  100.     end
  101.     if not fs.exists("IterationFile") then
  102.         IterFile = io.open("IterationFile", "w")
  103.         IterFile : write(2)
  104.         IterFile : close()
  105.     end
  106. end
  107.  
  108. while true do
  109.     NewFile()
  110.     turtle.select(1)
  111.     sDown()
  112.     CheckItems()
  113.     Bed()
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement