Advertisement
TJtheDJ701

Untitled

Sep 24th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. local locked = true
  2.  
  3. while locked == true do
  4. term.clear()
  5. term.setCursorPos(1, 1)
  6. term.setCursorBlink(true)
  7. textutils.slowWrite("Welcome Lucas... \nPassword: ")
  8. local ePass = read("*")
  9. term.clear()
  10. term.setCursorPos(1, 1)
  11.  
  12. if ePass == "pass" then
  13. locked = false
  14. textutils.slowPrint("Correct!")
  15.  
  16. -- Initializing --
  17. local rowsMined = {0}
  18.  
  19. local totalRows = {0}
  20.  
  21. local hallLength = {0}
  22.  
  23. local fuelNeeded = {0}
  24.  
  25. local fuelLevel = turtle.getFuelLevel()
  26. local fuelLimit = turtle.getFuelLimit()
  27. local startConfirmed = "No"
  28. local slot = turtle.getSelectedSlot()
  29. local itemSpace = turtle.getItemSpace()
  30. local torchCounter = 0
  31.  
  32. -- Declaring Functions --
  33. -- Help from the user Foogles (http://www.computercraft.info/forums2/index.php?/user/46239-foogles/) -- THANK YOU FOR THIS BUG SOLUTION ;)
  34. function forward()
  35. local x = turtle.forward()
  36. if (x == false) then return forward() end
  37. end
  38.  
  39. local function clear(column, row)
  40. term.clear()
  41.  
  42. if column == nil and row == nil then
  43. column = 1
  44. row = 1
  45. elseif row == nil then
  46. row = 1
  47. elseif column == nil then
  48. column = 1
  49. end
  50.  
  51. term.setCursorPos(column, row)
  52. end
  53.  
  54. local function checkNumber(varToCheck)
  55. assert(type(varToCheck) == "number", "Program expected number. Got string or something else instead.")
  56. end
  57.  
  58. local function fallingBlock()
  59. local success, data = turtle.inspect()
  60.  
  61. local fBlocks = {
  62. sand = "minecraft:sand",
  63. gravel = "minecraft:gravel",
  64. anvil = "minecraft:anvil",
  65. dragon_egg = "minecraft:dragon_egg"
  66. }
  67.  
  68. if data.name == fBlocks.sand or data.name == fBlocks.gravel or data.name == fBlocks.anvil or data.name == fBlocks.dragon_egg then
  69. return true
  70. else
  71. return false
  72. end
  73. end
  74.  
  75. local function dig(length, back)
  76. for i = 1, length do
  77. torchCounter = torchCounter + 1
  78.  
  79. while fallingBlock() == true do
  80. turtle.dig()
  81. sleep(1)
  82. end
  83.  
  84. turtle.dig()
  85. forward()
  86. turtle.digDown()
  87.  
  88. if torchCounter >= 8 then
  89. turtle.select(16)
  90.  
  91. if turtle.getItemSpace() < 64 then
  92. local data = turtle.getItemDetail()
  93.  
  94. if data.name == "minecraft:torch" then
  95. turtle.placeDown()
  96. end
  97. end
  98.  
  99. torchCounter = 0
  100. turtle.select(1)
  101. end
  102. end
  103.  
  104. if back == true then
  105. turtle.turnLeft()
  106. turtle.turnLeft()
  107.  
  108. for i = 2, length do
  109. forward()
  110. end
  111.  
  112. forward()
  113. turtle.turnLeft()
  114. turtle.turnLeft()
  115. end
  116. end
  117.  
  118. -- Welcome Message + Input --
  119. clear(1, 1)
  120. print("Welcome to the Strip Mining Program. by twisttaan")
  121. sleep(1)
  122. print("Please enter a Hall/Strip Length (x = x block/s): ")
  123. hallLength[1] = io.read()
  124. hallLength[1] = tonumber(hallLength[1])
  125. checkNumber(hallLength[1])
  126. print("Please enter a number of rows:")
  127. totalRows[1] = io.read()
  128. totalRows[1] = tonumber(totalRows[1])
  129. checkNumber(totalRows[1])
  130. print("Calculating if turtle has enough fuel...")
  131. fuelNeeded[1] = (hallLength[1] * 3 * totalRows[1]) + (12 * totalRows[1])
  132. sleep(1.0)
  133. assert(fuelNeeded[1] < fuelLimit, "Your fuel Limit is too low. Try an advanced turtle.")
  134. assert(fuelNeeded[1] < fuelLevel, "Your turtle hasn't enought fuel.")
  135. print("Your turtle has enough fuel. Please place a chest behind the turtle.")
  136. sleep(2.0)
  137. clear(1, 1)
  138. print("Place a chest behind the turtle.")
  139. print("Place Torches to place in Slot 16 (Bottom right hand corner)")
  140. write("Press any key to start the program.")
  141. local skip = io.read()
  142. -- Post initialization --
  143. local rowsToMine = totalRows[1] - rowsMined[1]
  144. clear(1, 1)
  145. turtle.select(1)
  146.  
  147. -- Main Loop --
  148. for i = 1, totalRows[1] do
  149. turtle.select(1)
  150. dig(3, false)
  151. turtle.turnLeft()
  152. dig(hallLength[1], true)
  153. rowsMined[1] = rowsMined[1] + 1
  154. clear(1, 1)
  155. print("Rows Mined: ", rowsMined[1])
  156. local z = 1
  157. turtle.select(15)
  158.  
  159. if turtle.getItemSpace() < 64 then
  160. turtle.turnLeft()
  161.  
  162. for i = 1, rowsMined[1] * 3 + 1 do
  163. forward()
  164. end
  165.  
  166. for i = 1, 15 do
  167. turtle.select(z)
  168. z = z + 1
  169. turtle.drop(64)
  170. end
  171.  
  172. turtle.turnRight()
  173. turtle.turnRight()
  174.  
  175. for i = 1, rowsMined[1] * 3 + 1 do
  176. forward()
  177. end
  178.  
  179. turtle.turnLeft()
  180. end
  181.  
  182. turtle.turnRight()
  183. rowsToMine = totalRows[1] - rowsMined[1]
  184. end
  185.  
  186. -- Ending --
  187. do
  188. print("Putting Items into chest.")
  189. turtle.turnLeft()
  190. turtle.turnLeft()
  191.  
  192. for i = 1, (rowsMined[1] * 3) + 1 do
  193. forward()
  194. end
  195.  
  196. z = 1
  197.  
  198. for i = 1, 16 do
  199. turtle.select(z)
  200. z = z + 1
  201. turtle.drop(64)
  202. end
  203. end
  204.  
  205. turtle.select(1)
  206. print("Mining Complete.")
  207. sleep(2)
  208. clear(1, 1)
  209. end
  210. end
  211.  
  212. return textutils.slowPrint("Go away willlly"), (1), os.shutdown(), (2) -- Most likely Willy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement