Guest User

Minerv1

a guest
Apr 18th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.27 KB | None | 0 0
  1.  
  2. --This section sets the variables. WARNING, THESE ARE GLOBAL VARIABLES!!!!--
  3. store, fuel, torches, sand, gravel, dirt, stone = 1, 2, 3, 4, 5, 6, 7
  4. ore = false
  5. --x is "left/right" w/ left = +
  6. --y is "forward/back" w/ forward = +
  7. --z is "up/down" w/ up = +
  8. front, left, rear, right = 0,1,2,3
  9. x, y, z, o = 0,0,0,0 --Current Co-ordinates
  10. xo,yo,zo,oo = 0,0,0,0 --Origin Point, where the turtle starts the program
  11. xb,yb,zb,ob = 0,0,0,0 --Saved Co-ordinates, where the turtle goes back to betwwen routines
  12.  
  13. function turn() --just keep turning, turning, turning
  14. turtle.turnLeft()
  15. o = o + 1
  16. end
  17. function ff() --short for "Face-Forward"
  18. while (o)%4 ~= 0 do
  19. turn()
  20. end
  21. end
  22. function fl() --"face-left"
  23. while (o)%4 ~= 1 do
  24. turn()
  25. end
  26. end
  27. function fb() --"face-back"
  28. while (o)%4 ~= 2 do
  29. turn()
  30. end
  31. end
  32. function fr() --"face-right"
  33. while (o)%4 ~= 3 do
  34. turn()
  35. end
  36. end
  37.  
  38. --Actual Movement functions below this line.
  39. function forward()
  40. ff()
  41. turtle.dig()
  42. turtle.forward()
  43. y = y + 1
  44. end
  45. function left()
  46. fl()
  47. turtle.dig()
  48. turtle.forward()
  49. x = x +1
  50. end
  51. function back()
  52. fb()
  53. turtle.dig()
  54. turtle.forward()
  55. y = y - 1
  56. end
  57. function right()
  58. fr()
  59. turtle.dig()
  60. turtle.forward()
  61. x = x - 1
  62. end
  63. function up()
  64. turtle.digUp()
  65. turtle.up()
  66. z = z + 1
  67. end
  68. function down()
  69. turtle.digDown()
  70. turtle.down()
  71. z = z - 1
  72. end
  73.  
  74. --Go back functions
  75. function savearea() --The all important reference point, tells the turtle to go back to this spot when used
  76. xb,yb,zb,ob = x,y,z,o
  77. end
  78.  
  79. function goback()
  80. while xb ~= x do
  81. if xb > x then
  82. right()
  83. end
  84. if xb < x then
  85. left()
  86. end
  87. end
  88. while yb ~= y do
  89. if yb > y then
  90. back()
  91. end
  92. if yb < y then
  93. forward()
  94. end
  95. end
  96. while zb ~= z do
  97. if zb > z then
  98. down()
  99. end
  100. if zb < z then
  101. up()
  102. end
  103. end
  104. while ob ~= o do
  105. turn()
  106. end
  107. end
  108.  
  109. --Checks surrounding blocks against "noise" inventory
  110. function checkforward()
  111.     ff()
  112. if turtle.detect() then
  113. turtle.select(stone)
  114.  if turtle.compare() == false then
  115.  turtle.select(dirt)
  116.   if turtle.compare() == false then
  117.   turtle.select(gravel)
  118.    if turtle.compare() == false then
  119.    turtle.select(sand)
  120.     if turtle.compare() == false then
  121.      ore = true
  122.    end
  123.   end
  124.  end
  125. end
  126. end
  127. end
  128.  
  129. function checkleft()
  130.     fl()
  131. if turtle.detect() == true then
  132.  turtle.select(stone)
  133.  if turtle.compare() == false then
  134.   turtle.select(dirt)
  135.   if turtle.compare() == false then
  136.    turtle.select(gravel)
  137.    if turtle.compare() == false then
  138.     turtle.select(sand)
  139.     if turtle.compare() == false then
  140.      ore = true
  141.     end
  142.    end
  143.   end
  144.  end
  145. end
  146. end
  147.  
  148. function checkback()
  149. fb()
  150. if turtle.detect() == true then
  151.  turtle.select(stone)
  152.  if turtle.compare() == false then
  153.   turtle.select(dirt)
  154.   if turtle.compare() == false then
  155.    turtle.select(gravel)
  156.    if turtle.compare() == false then
  157.     turtle.select(sand)
  158.     if turtle.compare() == false then
  159.      ore = true
  160.     end
  161.    end
  162.   end
  163.  end
  164. end
  165. end
  166.  
  167. function checkright()
  168. fr()
  169. if turtle.detect() == true then
  170.  turtle.select(stone)
  171.  if turtle.compare() == false then
  172.   turtle.select(dirt)
  173.   if turtle.compare() == false then
  174.    turtle.select(gravel)
  175.    if turtle.compare() == false then
  176.     turtle.select(sand)
  177.     if turtle.compare() == false then
  178.      ore = true
  179.     end
  180.    end
  181.   end
  182.  end
  183. end
  184. end
  185.  
  186. function checkup()
  187. if turtle.detectUp() == true then
  188.  turtle.select(stone)
  189.  if turtle.compareUp() == false then
  190.   turtle.select(dirt)
  191.   if turtle.compareUp() == false then
  192.    turtle.select(gravel)
  193.    if turtle.compareUp() == false then
  194.     turtle.select(sand)
  195.     if turtle.compareUp() == false then
  196.      ore = true
  197.     end
  198.    end
  199.   end
  200.  end
  201. end
  202. end
  203.  
  204. function checkdown()
  205. if turtle.detectDown() == true then
  206.  turtle.select(stone)
  207.  if turtle.compareDown() == false then
  208.   turtle.select(dirt)
  209.   if turtle.compareDown() == false then
  210.    turtle.select(gravel)
  211.    if turtle.compareDown() == false then
  212.     turtle.select(sand)
  213.     if turtle.compareDown() == false then
  214.      ore = true
  215.     end
  216.    end
  217.   end
  218.  end
  219. end
  220. end
  221.  
  222. --The "Smart Mine" functions
  223.  
  224. function deepmine()
  225.     checkforward()
  226. if ore == true then
  227.     forward()
  228.     ore = false
  229.     deepmine()
  230. else checkup()
  231.     if ore == true then
  232.     up()
  233.     ore = false
  234.     deepmine()
  235. else checkdown()
  236.     if ore == true then
  237.     down()
  238.     ore = false
  239.     deepmine()
  240. else checkleft()
  241.     if ore == true then
  242.     left()
  243.     ore = false
  244.     deepmine()
  245. else checkback()
  246.     if ore == true then
  247.     back()
  248.     ore = false
  249.     deepmine()
  250. else checkright()
  251.     if ore == true then
  252.     right()
  253.     ore = false
  254.     deepmine()
  255.     end
  256. end
  257. end
  258. end
  259. end
  260. end
  261. goback()
  262. end
  263.  
  264. function checkrabbit()
  265. print("rabbit?")
  266. checkforward()
  267. print("check forward")
  268. if ore == true then
  269.     forward()
  270.     ore = false
  271.     deepmine()
  272. else
  273. print("Left?")
  274. checkleft()
  275. print("Check Left")
  276.     if ore == true then
  277.     left()
  278.     ore = false
  279.     deepmine()
  280. else checkback()
  281.     if ore == true then
  282.     back()
  283.     ore = false
  284.     deepmine()
  285. else checkright()
  286.     if ore == true then
  287.     right()
  288.     ore = false
  289.     deepmine()
  290. end
  291. end
  292. end
  293. end
  294. end
  295.  
  296. function checktunnel()
  297. checkup()
  298. if ore == true then
  299.     forward()
  300.     ore = false
  301.     deepmine()
  302. else checkleft()
  303.     if ore == true then
  304.     left()
  305.     ore = false
  306.     deepmine()
  307. else checkright()
  308.     if ore == true then
  309.     right()
  310.     ore = false
  311.     deepmine()
  312. end
  313. end
  314. end
  315. end
  316.  
  317. function checkreturn()
  318.     checkdown()
  319.     if ore == true then
  320.     down()
  321.     ore = false
  322.     deepmine()
  323. else checkleft()
  324.     if ore == true then
  325.     left()
  326.     ore = false
  327.     deepmine()
  328. else checkright()
  329.     if ore == true then
  330.     right()
  331.     ore = false
  332.     deepmine()
  333. end
  334. end
  335. end
  336. end
  337.  
  338. --Functions Actually to be used
  339. function start()
  340. term.clear()
  341.  term.setCursorPos(1,1)
  342.  print("Please place two unique enderchests in the last two slots, then torches, sand, gravel, dirt, and stone.")
  343.  write("How far down should I go? ")
  344.  depth = tostring( read())
  345.  write("How far forward should I go? ")
  346.  length = tostring( read())
  347. end
  348.  
  349. function rabbithole()
  350. for i=1,depth do
  351. savearea()
  352. print("lets mine")
  353. checkrabbit()
  354. down()
  355. end
  356. end
  357.  
  358. function tunnel()
  359. for i=1,length do
  360. savearea()
  361. checktunnel()
  362. forward()
  363. turtle.digDown()
  364. end
  365. end
  366.  
  367. function rere()
  368. down()
  369. for i = 1,length do
  370. savearea()
  371. back()
  372. checkreturn()
  373. end
  374. for i = 1,depth do
  375. savearea()
  376. up()
  377. end
  378. while ob ~= o do
  379. turn()
  380. end
  381. end
  382.  
  383. --Finally, the end of this crap
  384. start()
  385. rabbithole()
  386. tunnel()
  387. rere()
Advertisement
Add Comment
Please, Sign In to add comment