Advertisement
Tibbz114

ComputerCraft Stripmine

Dec 24th, 2020 (edited)
2,557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.04 KB | None | 0 0
  1. local Version = 1.00
  2.  
  3. --Local
  4. local miningDistance = 0 -- How Far Did User Pick
  5. local shouldPlaceTorch = 0 -- When to Place Torch
  6. local TorchCount = turtle.getItemCount(1) -- How many items are in slot 1 (torch)
  7. local ItemChests = turtle.getItemCount(2) -- How many items are in slot 2 (chest)
  8. local FuelItemCount = turtle.getItemCount(3) -- How many items are in slot 3 (Fuel)
  9. local MD = 3 -- How Many Blocks Apart From Each Mine
  10. local NumberOfMines = 0 -- If Multi Mines Are ON then This will keep Count
  11. local Fuel = 0 -- if 2 then it is unlimited no fuel needed
  12. local NeedFuel = 0 -- If Fuel Need Then 1 if not Then 0
  13. local Way = 0 -- 1 = Left and 2 = Right
  14. local exception = false -- Used in initial and repeated inventory checks
  15.  
  16. local function FuelTurtle()
  17.     repeat
  18.         if turtle.getFuelLevel() == "unlimited" then
  19.             print("INFO: Server set for unlimited fuel")
  20.             Needfuel = 0
  21.         elseif turtle.getFuelLevel() < 100 then
  22.             print("INFO: Refueling from slot 3")
  23.             turtle.select(3)
  24.             turtle.refuel(1)
  25.             Needfuel = 1
  26.             FuelItemCount = FuelItemCount - 1
  27.         elseif FuelItemCount == 0 then
  28.             print("ERROR: Turtle ran out of fuel.")
  29.             os.shutdown()
  30.         elseif NeedFuel == 1 then
  31.             Needfuel = 0
  32.         end
  33.     until NeedFuel == 0
  34. end
  35.  
  36. local function CheckTurtleInventory()
  37.     if TorchCount == 0 then
  38.         print("ERROR: Turtle REQUIRES torches in slot 1!")
  39.         return true
  40.     else
  41.         print("INFO: Turtle has " .. TorchCount .. " starting torch(es).")
  42.     end
  43.     if ItemChests == 0 then
  44.         print("ERROR: Turtle REQUIRES chests in slot 2!")
  45.         return true
  46.     else
  47.         print("INFO: Turtle has " .. ItemChests .. " chests.")
  48.     end
  49.     if FuelItemCount == 0 then
  50.         print("ERROR: Turtle REQUIRES fuel items in slot 3! (Wooden Items, Types of Coal, Lava, Blaze Rod, etc.")
  51.         return true
  52.     else
  53.         print("INFO: Turtle has " .. FuelItemCount .. " fuel item(s).")
  54.     end
  55.     FuelTurtle()
  56.     return false
  57. end
  58.  
  59. --Mining
  60. local function ForwardM()
  61.     repeat
  62.         if turtle.detect() then
  63.             turtle.dig()
  64.         end
  65.         if turtle.forward() then -- sometimes sand and gravel and block and mix-up distance
  66.             TF = TF - 1
  67.             shouldPlaceTorch = shouldPlaceTorch + 1
  68.         end
  69.         if turtle.detectUp() then
  70.             turtle.digUp()
  71.         end
  72.         turtle.select(4)
  73.         turtle.placeDown()
  74.         if shouldPlaceTorch == 8 then -- Every 10 Block turtle place torch
  75.             if TorchCount > 0 then
  76.                 turtle.turnLeft()
  77.                 turtle.turnLeft()
  78.                 turtle.select(1)
  79.                 turtle.place()
  80.                 turtle.turnLeft()
  81.                 turtle.turnLeft()
  82.                 TorchCount = TorchCount - 1
  83.                 shouldPlaceTorch = shouldPlaceTorch - 8
  84.             else
  85.                 print("ERROR: Turtle ran out of torches!")
  86.                 return true
  87.             end
  88.         end
  89.         if turtle.getItemCount(16)>0 then -- If slot 16 in turtle has item slot 5 to 16 will go to chest
  90.             if ItemChests > 0 then
  91.                 turtle.select(2)
  92.                 turtle.digDown()
  93.                 turtle.placeDown()
  94.                 ItemChests = ItemChests - 1
  95.                 for slot = 5, 16 do
  96.                     turtle.select(slot)
  97.                     turtle.dropDown()
  98.                     sleep(1.5)
  99.                 end
  100.                 turtle.select(5)
  101.             else
  102.                 print("ERROR: Turtle ran out of chests!")
  103.                 return true
  104.             end
  105.         end
  106.         FuelTurtle()
  107.     until TF == 0
  108.     return false
  109. end
  110.  
  111. --Warm Up For Back Program
  112. local function WarmUpForBackProgram() -- To make turn around so it can go back
  113.     turtle.turnLeft()
  114.     turtle.turnLeft()
  115.     turtle.up()
  116. end
  117.  
  118. --Back Program
  119. local function Back()
  120.     repeat
  121.         if turtle.forward() then -- sometimes sand and gravel and block and mix-up distance
  122.             TB = TB - 1
  123.         end
  124.         if turtle.detect() then -- Sometimes sand and gravel can happen and this will fix it
  125.             if TB ~= 0 then
  126.                 turtle.dig()
  127.             end
  128.         end
  129.     until TB == 0
  130. end
  131.  
  132. -- Multimines Program
  133. local function MultiMines()
  134.     if Way == 2 then
  135.         turtle.turnLeft()
  136.         turtle.down()
  137.     else
  138.         turtle.turnRight()
  139.         turtle.down()
  140.     end
  141.     repeat
  142.         if turtle.detect() then
  143.             turtle.dig()
  144.         end
  145.         if turtle.forward() then
  146.             MD = MD - 1
  147.         end
  148.         if turtle.detectUp() then
  149.             turtle.digUp()
  150.         end
  151.     until MD == 0
  152.     if Way == 2 then
  153.         turtle.turnLeft()
  154.     else
  155.         turtle.turnRight()
  156.     end
  157.     if NumberOfMines == 0 then
  158.         print("INFO: Mining Complete!")
  159.     else
  160.         NumberOfMines = NumberOfMines - 1
  161.     end
  162. end
  163.  
  164. -- Restart
  165. local function Restart()
  166.     TF = miningDistance
  167.     TB = miningDistance
  168.     MD = 3
  169.     shouldPlaceTorch = 0
  170. end
  171.  
  172. -- Starting
  173. function Start()
  174.     repeat
  175.         exception = ForwardM()
  176.         if exception == true then
  177.             return
  178.         end
  179.         WarmUpForBackProgram()
  180.         Back()
  181.         MultiMines()
  182.         Restart()
  183.     until NumberOfMines == 0
  184. end
  185.  
  186. -- Start
  187. print("== Mining Turtle v" .. Version .. "==")
  188. print("This program allows your ComputerCraft turtle to Stripmine for you.")
  189.  
  190. print("How many blocks forward do you want each strip to be?")
  191. input = io.read()
  192. miningDistance = tonumber(input)
  193. TF = miningDistance
  194. TB = miningDistance
  195.  
  196. print("How many strips do you want the turtle to mine?")
  197. input3 = io.read()
  198. NumberOfMines = tonumber(input3)
  199.  
  200. if NumberOfMines > 1 then
  201.     while Way == 0
  202.     do
  203.         print("Would you like each strip mine to be made to the left or right of the original?")
  204.         input2 = io.read()
  205.         if input2 == "left" then
  206.             Way = 1
  207.         elseif input2 == "right" then
  208.             Way = 2
  209.         else
  210.             print("ERROR: The only proper responses are 'left' or 'right'. (without the quotes)")
  211.         end
  212.     end
  213. end
  214.  
  215. exception = CheckTurtleInventory()
  216. if exception == false then
  217.     Start()
  218. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement