SummitSummit

XPSlayer

Jul 6th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. -- get the current level of the turtle
  2. function getLvl()
  3. curLev = m.getLevels()
  4. return curLev
  5. end
  6.  
  7. -- Check if nLvl(default=30) levels have been reached, if not wait, if yes, return true.
  8. function checkLevel(nLvl)
  9. getLvl()
  10. if curLev<nLvl then
  11. printStatus("gathering XP", curLev)
  12. turtle.attack()
  13. sleep(0.2)
  14. turtle.select(1)
  15. turtle.dropDown()
  16. return false
  17. else
  18. printStatus("moving to enchant area", getLvl())
  19. return true
  20. end
  21.  
  22. end
  23.  
  24. -- Look for items to enchant in slots 2 through 14, if there are none, default to findBooks()
  25. function getItems()
  26. for i=2,14 do
  27. if turtle.getItemCount(i)>0 then
  28. turtle.select(i)
  29. turtle.transferTo(1,1)
  30. turtle.select(1)
  31. return true
  32. end
  33. end
  34. -- print("no items found, trying to find books")
  35. if findBook() then
  36. -- print("Books found")
  37. return true
  38. else
  39. return false
  40. end
  41.  
  42. end
  43.  
  44. -- Get books from inventory slot 15 and put 1 in slot 1, returning true, if not return false
  45. function findBook()
  46. if turtle.getItemCount(15)>=1 then
  47. turtle.select(15)
  48. turtle.transferTo(1,1)
  49. turtle.select(1)
  50. return true
  51. else
  52. return false
  53. end
  54. end
  55.  
  56. -- enchant the book in slot one and drop it into the chest underneath the turtle
  57. function enchantBook(nLvl)
  58. if m.enchant(nLvl) then
  59. turtle.dropDown()
  60. else
  61. error("Unexpected error while trying to enchant")
  62. end
  63.  
  64. end
  65.  
  66. -- End program with a message
  67.  
  68. function exitMsg(exitNr)
  69. if exitNr == 1 then exitStr="Out of fuel. Place more fuel in slot 16 and restart the program"
  70. elseif exitNr == 2 then exitStr="No more items or books"
  71. -- elseif exitNr == 3 then exitStr=""
  72. -- elseif exitNr == 4 then exitStr=""
  73. -- elseif exitNr == then exitStr=""
  74.  
  75. end
  76. term.clear()
  77. term.setCursorPos(2,2)
  78. sleep(0.5)
  79. print(exitStr)
  80. run.state="end"
  81. end
  82.  
  83.  
  84.  
  85. function printIntro()
  86. term.clear()
  87. print("---------------------------------------")
  88. print("------- XPSlayer 0.1 by Summit --------")
  89. print("---------------------------------------")
  90. print()
  91. print("This turtle will automatically enchant items in its inventory")
  92. print("Place any items in slots 2 through 14")
  93. print("Place some books in slot 15.")
  94. print("Place some fuel in slot 16")
  95. print("Press any key to start")
  96. print()
  97.  
  98. end
  99.  
  100. function printStatus(curTask, curLvl)
  101. term.clear()
  102. term.setCursorPos(1,1)
  103. print("------- XPSlayer 0.1 by Summit --------")
  104. term.setCursorPos(2,4)
  105. io.write(string.format("Current Task: %s", curTask))
  106. term.setCursorPos(2,6)
  107. io.write(string.format("Current Level: %s", curLvl))
  108. end
  109.  
  110.  
  111. --INIT
  112. m=peripheral.wrap("right")
  113. m.setAutoCollect(true)
  114. nLvl=30
  115. run = {}
  116. run.state="running"
  117. screenw, screenh = term.getSize()
  118.  
  119. -- Main Program
  120.  
  121. printIntro()
  122. os.pullEvent()
  123.  
  124. -- start main loop
  125. while run.state=="running" do
  126. while not checkLevel(nLvl) do
  127. sleep(1)
  128.  
  129. end
  130. -- checkFuel()
  131. -- loadState()
  132.  
  133. printStatus("enchanting", getLvl())
  134. sleep(2)
  135. if getItems() then
  136. enchantBook(nLvl)
  137. sleep(2)
  138. -- moveForward(5)
  139. else
  140. exitMsg(2)
  141. end
  142. end
Advertisement
Add Comment
Please, Sign In to add comment