Dweller_Benthos

Minecraft Turtle program

Feb 10th, 2013
2,437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.54 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1, 1)
  3.  
  4. repeat
  5. print("Enter tunnel length (even digit): ")
  6. tunnellength = read()
  7. until tunnellength % 2 == 0
  8.  
  9. term.clear()
  10. term.setCursorPos(1, 1)
  11.  
  12. print("Place Fuel in Slot 1")
  13. print("Enter number for fuel type: ")
  14. print("")
  15. print("No Fuel Required = 0")
  16. print("Coal/Charcoal/Peat = 1")
  17. print("Coal Coke = 2")
  18. print("Biofuel Can = 3")
  19. print("Coalfuel Can = 4")
  20. print("Lava Cell = 5")
  21. fueltype = read()
  22.  
  23. function fueltypeset()
  24. if fueltype == "1" then
  25. fueltype = 80
  26. elseif fueltype == "2" then
  27. fueltype = 160
  28. elseif fueltype == "3" then
  29. fueltype = 520
  30. elseif fueltype == "4" then
  31. fueltype = 1520
  32. elseif fueltype == "5" then
  33. fueltype = 1000
  34. end
  35. end
  36. fueltypeset()
  37. term.clear()
  38. term.setCursorPos(1, 1)
  39.  
  40. print("Drop mined cobblestone? 0=No, 1=Yes")
  41. cobblesetting = read()
  42. term.clear()
  43. term.setCursorPos(1, 1)
  44. if cobblesetting == "1" then
  45. if turtle.getItemCount(2) < 1 then
  46. print("Place 1 cobblestone in Slot 2")
  47. print("")
  48. end
  49. end
  50.  
  51. print("Place torches? 0=No, 1=Yes")
  52. print("Place torches in Slot 3")
  53. torchsetting = read()
  54. term.clear()
  55. term.setCursorPos(1, 1)
  56. if torchsetting == "1" then
  57. if turtle.getItemCount(3) < tunnellength/8 then
  58. print("Warning: You will not have enough torches for entire tunnel length.")
  59. print("")
  60. print("")
  61. end
  62. end
  63.  
  64.  
  65. print("Return and deposit items to chest if inventory nears full?")
  66. print("0=No, 1=Yes")
  67. returnsetting  = read()
  68. term.clear()
  69. term.setCursorPos(1, 1)
  70. if returnsetting == "1" then
  71. print("Place chest immediately behind turtle.")
  72. end
  73.  
  74. print("")
  75. print("Begin mining?")
  76. print("0=Cancel Program, Any Key=Yes")
  77. beginmine = read()
  78. if beginmine == "0" then
  79. os.reboot()
  80. end
  81.  
  82. term.clear()
  83. term.setCursorPos(1,1)
  84. print("Tunneling " .. tunnellength .. " blocks, then returning.")
  85. sleep(2)
  86.  
  87. torchpos = 0
  88.  
  89. function progress()
  90. term.setCursorPos(1,3)
  91. print("Progress: " .. torchpos .. " of " .. tunnellength)
  92. end
  93.  
  94. function fuelcheck()
  95.     if turtle.getFuelLevel() ~= "unlimited" then
  96.         if turtle.getFuelLevel()/fueltype < 0.26 then
  97.         turtle.select(1)
  98.         turtle.refuel(1)
  99.         end
  100.     end
  101. end
  102.  
  103. function dropcobble()
  104.     local stackSize = turtle.getItemCount(2)
  105.     if cobblesetting == "1" then
  106.         if turtle.getFuelLevel() ~= "unlimited" then
  107.             if stackSize > 2 then
  108.                 stackSize = stackSize-1
  109.                 turtle.select(2)
  110.                 turtle.drop(stackSize)
  111.                 end
  112.         elseif turtle.getFuelLevel() == "unlimited" then
  113.             if stackSize > 2 then
  114.                     stackSize = stackSize-1
  115.                     turtle.select(2)
  116.                     turtle.drop(stackSize)
  117.                     end
  118.             turtle.select(1)
  119.             if turtle.compareTo(2) then
  120.                 turtle.drop()
  121.                 end
  122.            
  123.             end
  124.         end
  125. end
  126.  
  127.  
  128. function minewallRight()
  129. fuelcheck()
  130. turtle.select(1)
  131. turtle.dig()
  132. moveforward()
  133. turtle.digUp()
  134. turtle.digDown()
  135. torchpos = torchpos + 1
  136. progress()
  137. end
  138.  
  139. function minewallLeft()
  140. fuelcheck()
  141. turtle.select(1)
  142. turtle.dig()
  143. moveforward()
  144. turtle.digUp()
  145. turtle.digDown()
  146. torchpos = torchpos + 1
  147. progress()
  148. end
  149.  
  150. function minecycle()
  151. for z = 1, tunnellength/2 do
  152. minewallRight()
  153. minewallLeft()
  154. placetorch()
  155. end
  156. end
  157.  
  158. function placetorch()
  159.     if torchsetting == "1" then
  160.         if torchpos % 8 == 0 then
  161.         turtle.back()
  162.         turtle.select(3)
  163.         turtle.placeUp()
  164.         turtle.forward()
  165.         dropcobble()
  166.         fuelcheck()
  167.         fullinventory()
  168.         turtle.select(1)
  169.         end
  170.     else
  171.         if torchpos % 8 == 0 then
  172.         dropcobble()
  173.         fuelcheck()
  174.         fullinventory()
  175.         turtle.select(1)
  176.         end
  177.     end
  178. end
  179.  
  180. function moveforward()
  181. while not turtle.forward() do
  182. sleep(0.35)
  183. turtle.dig()
  184. end
  185. end
  186.  
  187. function turtlehome()
  188. for y = 1, tunnellength do
  189. fuelcheck()
  190.     if turtle.detectDown() == false then
  191.         turtle.select(16)
  192.         turtle.placeDown()
  193.     end
  194. moveforward()
  195. end
  196. end
  197.  
  198.  
  199. function fullinventory()
  200. local invcount = 0
  201.     if returnsetting == "1" then
  202.         for c = 4, 16 do
  203.             if turtle.getItemCount(c) > 0 then
  204.             invcount = invcount+1
  205.             end
  206.         end
  207.         if invcount > 12 then
  208.             turtle.turnLeft()
  209.             turtle.turnLeft()
  210.             fuelcheck()
  211.             for f = 1, torchpos+1 do
  212.             moveforward()
  213.             fuelcheck()
  214.             end
  215.             for d = 4, 16 do
  216.             turtle.select(d)
  217.             turtle.dropDown()
  218.             end
  219.             turtle.turnLeft()
  220.             turtle.turnLeft()
  221.             fuelcheck()
  222.             for f = 1, torchpos+1 do
  223.             moveforward()
  224.             fuelcheck()
  225.             end
  226.             invcount = 0
  227.         else
  228.             invcount = 0
  229.         end
  230.     end
  231. end
  232.  
  233.  
  234. fuelcheck()
  235. turtle.digUp()
  236. turtle.up()
  237. minecycle()
  238. turtle.down()
  239. turtle.turnLeft()
  240. turtle.turnLeft()
  241. fuelcheck()
  242. turtlehome()
  243. turtle.turnRight()
  244. turtle.turnRight()
  245. term.setCursorPos(1,5)
  246. print("Mining Successful")
  247. term.setCursorPos(1,7)
Advertisement
Add Comment
Please, Sign In to add comment