Advertisement
arismoko

stripmine

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