Advertisement
jnsstnbrg

Turtle Enchanter

Mar 14th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. ench = peripheral.wrap("right")
  2. ench.setAutoCollect(true)
  3.  
  4. level = 0
  5.  
  6. function clear_inventory()
  7. for i = 2,15 do
  8. turtle.select(i)
  9. turtle.dropUp()
  10. end
  11. end
  12.  
  13. function enchant(ench)
  14. turtle.select(1)
  15. ench.collect()
  16. state = not redstone.getOutput("bottom")
  17.  
  18. if not turtle.compareTo(16) then
  19. turtle.dropUp()
  20. end
  21.  
  22. if turtle.getItemCount(1) == 0 then
  23. print("Out of books; taking from book chest.")
  24. while not turtle.suckDown() do
  25. print("No books in book chest. Sleeping for 1 minute.")
  26. sleep(60)
  27. end
  28. end
  29.  
  30. -- if we've gotten this far, we have some books in slot 1.
  31. print("Enchanting levels: " .. ench.getLevels() .. "\n")
  32. while ench.getLevels() >= 30 do
  33. turtle.select(1)
  34. if turtle.getItemCount(1) > 1 then
  35. turtle.transferTo(2, 1)
  36. turtle.select(2)
  37. end
  38. ench.enchant(30)
  39. while not turtle.dropUp() do
  40. print("Output chest full. Sleeping for 1 minute.")
  41. sleep(60)
  42. end
  43. turtle.select(1)
  44. end
  45. end
  46.  
  47. function attack()
  48. for i=1,10 do
  49. turtle.attack()
  50. sleep(0.1)
  51. end
  52. end
  53.  
  54. while true do
  55. if (level ~= ench.getLevels()) then
  56. level = ench.getLevels()
  57. if ((level <= 25 and level % 5 == 0) or level > 25) then
  58. print("Turtle at level: " .. level)
  59. end
  60. end
  61.  
  62. if (ench.getLevels() >= 30) then
  63. clear_inventory()
  64. enchant(ench)
  65. end
  66.  
  67. turtle.attack()
  68. --attack() -- attack for one second.
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement