Red-Thirten

mineHall 7.0

Sep 9th, 2020
756
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. debug = true
  2.  
  3. term.clear()
  4. term.setCursorPos(1,1)
  5. print("===============================")
  6. print("Welcome to MineHall - 7.0")
  7. print("(c)2019 Lilkingjr13 & NGXII")
  8. print("===============================")
  9. print("")
  10.  
  11. print("How long do you want your hall to be?:")
  12. length = read()
  13.  
  14. print("How wide do you want your hall to be?:")
  15. width = read()
  16.  
  17. print("How tall do you want your hall to be?:")
  18. height = read()
  19.  
  20. print("Would you like to place torches? (Y/N):")
  21. print("(Put torches in 1st slot of Turtle)")
  22. torch = read()
  23. if torch == "yes" or torch == "y" or torch == "Y" then
  24. print("How often to place a torch?")
  25. print("Every ? blocks...")
  26. torchfreq= read()
  27.  
  28. --Check for valid number for torch frequency
  29. while tonumber(torchfreq) == nil or tonumber(torchfreq)< 1 do
  30.         print("Incorrect Parameter - Please Enter a NUMBER greater than 0")
  31.         torchfreq = read()
  32.     end
  33. else
  34.     torch = false
  35. end
  36.  
  37. print("Press enter to start mining... (Enter x to terminate)")
  38. go = read()
  39. if go == "x" then
  40. error()
  41. end
  42.  
  43.  
  44. --Variable Definition
  45.  
  46. --Check for valid number for length
  47. while tonumber(length) == nil or tonumber(length) < 1 do
  48. print("Incorrect Length Parameter - Please Enter a NUMBER greater than 0")
  49. length = read()
  50. end
  51.  
  52. --Check for valid number for width
  53. while tonumber(width) == nil or tonumber(width) < 1 do
  54. print("Incorrect Width Parameter - Please Enter a NUMBER greater than 0")
  55. width = read()
  56. end
  57.  
  58. --Check for valid number for height
  59. while tonumber(height) == nil or tonumber(height) < 1 do
  60. print("Incorrect Height Parameter - Please Enter a NUMBER greater than 0")
  61. height = read()
  62. end
  63.  
  64. length = tonumber(length)
  65. width = tonumber(width-1)
  66. height= tonumber(height)
  67.  
  68. if torch == "yes" then
  69. torch = true
  70. torchfreq = tonumber(torchfreq)
  71. else
  72.     torch = false
  73. end
  74.  
  75. left = false        --”left” determines if its on the left side of the mine
  76. origin = true       --determines if at origin
  77. going = true        --determines if going away from the origin
  78. done = false        --determines if done with program
  79. blockCount = 0  --Counts blocks successfully mined
  80. moveCount = 0   --Counts successful forward moves
  81.  
  82. --Define Functions
  83.  
  84. function mine()
  85.     if height == 1 then
  86.         if turtle.dig() then
  87.                 blockCount = blockCount + 1
  88.         end
  89.     elseif height == 2 then
  90.         if turtle.dig() then
  91. blockCount = blockCount + 1
  92.     end
  93.  
  94.     if turtle.digUp() then
  95.             blockCount = blockCount + 1
  96.     end
  97.     elseif height > 2 then
  98.         if turtle.dig() then
  99.                 blockCount = blockCount + 1
  100.         end
  101.         if turtle.digUp() then
  102.                 blockCount = blockCount + 1
  103.         end
  104.         if turtle.digDown() then
  105.                 blockCount = blockCount + 1
  106.         end
  107.     else
  108.         print("Incorrect Height Parameter")
  109.         if debug == true then
  110.                 print("Error at mine()")
  111.         end
  112.     end
  113. end
  114.  
  115.  
  116. function advance()
  117.     result = turtle.forward()
  118.     if result == false then
  119.         if debug == true then print("I can't move!") end
  120.         fuel = turtle.getFuelLevel()
  121.         if fuel == 0 then
  122.                 if debug == true then print("I'm out of fuel!") end
  123.                 turtle.refuel(3)
  124.                 if debug == true then print("I refuelled") end
  125.         else
  126.                 if debug == true then print("I have hit an obstacle!") end
  127.                 mine()
  128.         end
  129.         advance()
  130.     else
  131.         if debug == true then print("I moved!") end
  132.     end
  133. end          
  134.      
  135.  
  136. function mineLayer()
  137. if origin == true then
  138. turtle.turnLeft()
  139. if height > 2 then
  140. turtle.digUp()
  141.                 eres = turtle.up()
  142.                 if eres == false then
  143.                         turtle.refuel(3)
  144.                         turtle.up()
  145.                 end
  146.         end
  147. for i=0, tonumber((width/2)-1) do
  148.                     mine()
  149.                     advance()
  150.             end
  151.             origin = false
  152.             turtle.turnRight()
  153.             left = true
  154.     else
  155.             mine()
  156.             advance()
  157. --Turn to start mining
  158.             if left == true then
  159.                     turtle.turnRight()
  160.             else
  161.                     turtle.turnLeft()
  162.         end
  163. --Mine Forward
  164. for i=1, width do
  165.                 mine()
  166. advance()
  167. moveCount = moveCount + 1
  168. end
  169. --Flip the left variable
  170.         if left == true then
  171. left = false
  172. else
  173. left = true
  174.         end
  175. --Turn
  176.         if left == true then
  177. turtle.turnRight()
  178. else
  179. turtle.turnLeft()
  180. end
  181. end
  182. end
  183.  
  184.  
  185. function escalate(upNum)
  186.     --Turn around
  187.     turtle.dig()
  188.     advance()
  189.     turtle.turnLeft()
  190.     turtle.turnLeft()
  191. for uCount=1, upNum do
  192. turtle.digUp()
  193.         eres = turtle.up()
  194.         if eres == false then
  195.                     turtle.refuel(3)
  196.                     turtle.up()
  197.         end
  198.         if debug == true then print("escalated") end
  199.     end
  200.     --Flop the left variable
  201.     if left == true then
  202.             left = false
  203.     else
  204.             left = true
  205.     end
  206.     --Flip the direction variable
  207.     if going == true then
  208.         going = false
  209.     else
  210.         going = true
  211.     end
  212. end
  213.  
  214.  
  215. function home()
  216. --Turn To Center
  217.     if left == true then
  218.         turtle.turnRight()
  219.     else
  220.         turtle.turnLeft()
  221.     end
  222. mine()   
  223. --Move to Center
  224.     for move=0, ((width/2) -1) do
  225.         advance()
  226.     end
  227. --Turn To Home
  228.     if left == true then
  229.         turtle.turnRight()
  230.     else
  231.         turtle.turnLeft()
  232.     end
  233. --Check for which end of mine
  234.     if going == false then
  235.         for walk = 0, (length-1) do
  236.                 advance()
  237.         end
  238.         turtle.turnLeft()
  239.         turtle.turnLeft()
  240.     end
  241. --Drop to second to bottom layer
  242.     for i=0, (height-4) do
  243.         turtle.down()
  244.     end
  245. --Go Home
  246.     for i=0, (length-1) do
  247.         advance()
  248.         if torch then
  249.                 if (i % torchfreq) == 0 then
  250.                         turtle.placeDown()
  251.                 end
  252.         end
  253.     end
  254. end
  255.  
  256.  
  257. function mineSlab()
  258. for count=0, (length) do
  259.     mineLayer()
  260.     count = count + 1
  261.     end
  262. end
  263.  
  264.  
  265. --START PROGRAM
  266. print("Starting Mining")
  267.  
  268. if height < 4 then
  269.     mineSlab()
  270. else
  271.     for repeats=1, ((height/3)-1) do
  272.         mineSlab()
  273.         escalate(3)
  274.     end
  275.     mineSlab()
  276.     rem = (height%3)
  277.     escalate(rem)
  278.     mineSlab()
  279. end
  280. home()
  281. done = true  
  282.  
  283.  
  284. --Print End Results
  285.  
  286. print("Successfuly mined a "..width.."x"..length.."x"..height.." cube!")
  287. print("And collected a total of "..blockCount.." items!")
  288. print("Mining Complete.")
  289. --End Program
  290.  
RAW Paste Data