Advertisement
Guest User

Untitled

a guest
Jun 4th, 2013
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. --Place chest to hold your enchanted items in front of turtle.
  2. --Place chest to hold unenchanted books above turtle
  3.  
  4. m=peripheral.wrap("right")
  5. m.setAutoCollect(true)
  6. local level = 0
  7.  
  8. function checkLevel()
  9.     level = m.getLevels()
  10.     print("Current level: "..level)
  11.     return level
  12. end
  13.  
  14. function enchantBook()
  15.     print("Enchanting...")
  16.     turtle.select(2)
  17.     m.enchant(30)
  18.     turtle.drop()
  19. end
  20.  
  21. function checkBook()
  22.     turtle.select(1)
  23.     if turtle.getItemCount(2) > 1 then
  24.         turtle.select(2)
  25.         turtle.drop()
  26.     elseif turtle.getItemCount(2) == 0 then
  27.         if turtle.getItemCount(1) == 0 then
  28.             turtle.suckUp()
  29.             if turtle.getItemCount(1) == 0 then
  30.                 print("Out of books.")
  31.             else
  32.                 turtle.transferTo(2,1)
  33.                 enchantBook()
  34.             end
  35.         else
  36.             turtle.transferTo(2, 1)
  37.             enchantBook()
  38.         end
  39.     else
  40.         enchantBook()
  41.     end
  42. end
  43.  
  44. --main program
  45. print("I am an Enchanting Turtle.")
  46. while true do
  47.     if checkLevel() >= 30 then
  48.         checkBook()
  49.     end
  50.     sleep (10)
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement