ksbd

Enchanting

Jun 12th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. --Constants:
  2.  
  3. local maxLevel = 30
  4. local waitTime = 20
  5.  
  6. --Variables:
  7.  
  8. local level = 0
  9. local x = 0
  10. --Functions:
  11.  
  12. function clear()
  13.     term.clear()
  14.     term.setCursorPos(1,1)
  15. end
  16.  
  17. function wait()
  18.     for i = 1 , waitTime do
  19.         clear()
  20.         print("Current level = "..m.getLevels()..".")
  21.         print("("..maxLevel-m.getLevels().." more levels until the next enchant.)")
  22.         print("")
  23.         print("Waiting: "..waitTime-x)
  24.         if x >= waitTime then
  25.             x = 1
  26.         else
  27.             x = x + 1
  28.         end
  29.         sleep(1)
  30.     end
  31. end
  32.  
  33. function getLevel()
  34.     level = m.getLevels()
  35. end
  36.  
  37. function collect()
  38.     m.getUp()
  39. end
  40.  
  41. function getBook()
  42.     turtle.select(1)
  43.     turtle.suck()
  44.     if turtle.getItemCount(1) > 1 then
  45.         turtle.drop(turtle.getItemCount(1) -1)
  46.     elseif turtle.getItemCount(1) == 1 then enchant()
  47.     else print("") print("No books...") sleep(2)
  48.     end
  49. end
  50.  
  51. function enchant()
  52.     turtle.select(1)
  53.     m.enchant(maxLevel)
  54. end
  55.  
  56. function deposit()
  57.     turtle.select(1)
  58.     turtle.dropDown()
  59. end
  60.  
  61. --MAIN PROGRAM:
  62.  
  63. m = peripheral.wrap("right")
  64.  
  65. while true do
  66.     collect()
  67.     level = 0
  68.     getLevel()
  69.     if level >= maxLevel then
  70.         getBook()
  71.         if turtle.getItemCount(1) == 1 then
  72.             enchant()
  73.             deposit()
  74.         end
  75.     end
  76. wait()
  77. end
Advertisement
Add Comment
Please, Sign In to add comment