Advertisement
henritom

turtle.mining v1.1

Jul 7th, 2021 (edited)
1,580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local defaultDistanceTorch = 0
  2. local defaultDistanceBuild = 0
  3.  
  4. local distanceBuild = 0
  5. local distanceTorch = 0
  6. local itemsNeeded = 3
  7. local incorrectItems = 3
  8.  
  9. local checkFuel, checkChest, checkTorch, getInventory, checkInventory, dig
  10.  
  11. local fuelData = turtle.getItemDetail(1)
  12. local chestData = turtle.getItemDetail(2)
  13. local torchData = turtle.getItemDetail(3)
  14. local fullData = turtle.getItemDetail(16)
  15.  
  16. local fuel = 0
  17. local chest = 0
  18. local torch = 0
  19.  
  20. local function restart()
  21.     local itemsNeeded = 3
  22.     local incorrectItems = 3
  23.     term.clear()
  24.     getInventory()
  25.     checkInventory()
  26. end
  27.  
  28. local function start()
  29.     term.clear()
  30.     print("Turtle is ready to start!")
  31.     write("Distance: ")
  32.     local distanceInput = read()
  33.     distanceInput = tonumber(distanceInput)
  34.     if type(distanceInput) == "number" then
  35.         defaultDistanceBuild = distanceInput
  36.         distanceBuild = distanceInput
  37.        
  38.         term.clear()
  39.         print("Turtle is ready to start!")
  40.         write("Torch: ")
  41.         local torchInput = read()
  42.         torchInput  = tonumber(torchInput)
  43.         if type(torchInput) == "number" then
  44.             defaultDistanceTorch = torchInput
  45.             distanceTorch = torchInput
  46.             dig()
  47.         else
  48.             print("Please insert a number!")
  49.             sleep(0.5)
  50.             term.clear()
  51.             start()
  52.         end
  53.     else
  54.         print("Please insert a number!")
  55.         sleep(0.5)
  56.         term.clear()
  57.         start()
  58.     end
  59. end
  60.  
  61. local function work()
  62.     print("Mining... Distance: " .. distanceBuild .. "/" .. defaultDistanceBuild .. " Torches: " .. distanceTorch .. "/" .. defaultDistanceTorch)
  63.  
  64.     if turtle.detect() then
  65.         turtle.dig()
  66.         turtle.forward()
  67.         distanceBuild = distanceBuild - 1
  68.         distanceTorch = distanceTorch - 1
  69.     else
  70.         turtle.forward()
  71.     end
  72.  
  73.     if turtle.detectUp() then  
  74.         turtle.digUp()
  75.     end
  76.     dig()
  77. end
  78.  
  79. getInventory = function()
  80.     fuel = turtle.getItemCount(1)
  81.     chest = turtle.getItemCount(2)
  82.     torch = turtle.getItemCount(3)
  83. end
  84.  
  85. checkInventory = function()
  86.     term.clear()
  87.     print("Checking Fuel...")
  88.     if fuel == 0 then
  89.         print("Missing: Fuel - Slot 1")
  90.     else
  91.         print("Enough Fuel")
  92.         itemsNeeded = itemsNeeded - 1
  93.     end
  94.    
  95.     print(" ")
  96.     print("Checking Chests...")
  97.     if chest == 0 then
  98.         print("Missing: Chest - Slot 2")
  99.     else
  100.         print("Enough Chests")
  101.         itemsNeeded = itemsNeeded - 1
  102.     end
  103.    
  104.     print(" ")
  105.     print("Checking Torch...")
  106.     if torch == 0 then
  107.         print("Missing: Torch - Slot 3")
  108.     else
  109.         print("Enough Torch")
  110.         itemsNeeded = itemsNeeded - 1
  111.     end
  112.  
  113.     if itemsNeeded == 0 then
  114.         print(" ")
  115.         print("No more items needed!")
  116.         sleep(1.5)
  117.         checkFuel()
  118.     else
  119.         print(" ")
  120.         print("Not enough items!")
  121.     end
  122. end
  123.  
  124. checkFuel = function()
  125.     term.clear()
  126.     print("Checking Fuel Data...")
  127.     if fuelData then
  128.         if fuelData.name == "minecraft:coal" then
  129.             print("Correct Fuel Data: " .. fuelData.name)
  130.             incorrectItems = incorrectItems - 1
  131.             sleep(0.5)
  132.             checkChest()
  133.             local fullCheck = 1
  134.         else
  135.             print("Incorrect Fuel Data: " .. fuelData.name)
  136.         end
  137.     end
  138. end
  139.  
  140. checkChest = function()
  141.     term.clear()
  142.     print("Checking Chest Data...")
  143.     if chestData then
  144.         if chestData.name == "minecraft:chest" then
  145.             print("Correct Chest Data: " .. chestData.name)
  146.             incorrectItems = incorrectItems - 1
  147.             sleep(0.5)
  148.             checkTorch()
  149.         else
  150.             print("Incorrect Chest Data: " .. chestData.name)
  151.         end
  152.     end
  153. end
  154.  
  155. checkTorch = function()
  156.     term.clear()
  157.     print("Checking Torch Data...")
  158.     if torchData then
  159.         if torchData.name == "minecraft:torch" then
  160.             print("Correct Torch Data: " .. torchData.name)
  161.             incorrectItems = incorrectItems - 1
  162.             sleep(0.5)
  163.             start()
  164.         else
  165.             print("Incorrect Torch Data: " .. torchData.name)
  166.         end
  167.     end
  168. end
  169.  
  170. local function turnTurtle()
  171.     turtle.turnRight()
  172.     turtle.turnRight()
  173. end
  174.  
  175. local function placeChest()
  176.     print("Placing chest...")
  177.     if chestData then
  178.         if chestData.name == "minecraft:chest" then
  179.             print("Available Chests: " .. chestData.count)
  180.             turtle.digDown()
  181.             turtle.select(2)
  182.             turtle.placeDown()
  183.             print("Placed Chest!")
  184.             for chestSlot = 4, 16 do
  185.                 turtle.select(chestSlot)
  186.                 turtle.dropDown()
  187.             end
  188.         else
  189.             print("Incorrect Chest Data: " .. chestData.name .. " " .. chestData.count)
  190.         end
  191.     else
  192.         print("Not enough chests!")
  193.     end
  194. end
  195.  
  196. local function placeTorch()
  197.     print("Placing Torch...")
  198.     if torchData then
  199.         if torchData.name == "minecraft:torch" then
  200.             print("Available Torches: " .. torchData.count)
  201.             turnTurtle()
  202.             turtle.select(3)
  203.             turtle.place()
  204.             print("Placed Torch!")
  205.             turnTurtle()
  206.         else
  207.             print("Incorrect Torch Data: " .. torchData.name .. " " .. torchData.count)
  208.         end
  209.     else
  210.         print("Not enough Torches!")
  211.     end
  212. end
  213.  
  214. local function refuel()
  215.     print("Refueling...")
  216.     if fuelData then
  217.         if fuelData.name == "minecraft:coal" then
  218.             print("Available Fuel: " .. fuelData.count)
  219.             turtle.select(1)
  220.             turtle.refuel(1)
  221.         else
  222.             print("Incorrect Fuel Data: " .. fuelData.name .. " " .. fuelData.count)
  223.         end
  224.     else
  225.         print("Not enough Fuel!")
  226.     end
  227. end
  228.  
  229. dig = function()
  230.     term.clear()
  231.     if turtle.getFuelLevel() == 0 then
  232.         refuel()
  233.     end
  234.  
  235.     if fullData then
  236.         placeChest()
  237.     end
  238.  
  239.     if distanceTorch == 0 then
  240.         placeTorch()
  241.         distanceTorch = defaultDistanceTorch
  242.     end
  243.  
  244.     if distanceBuild == 0 then
  245.         placeChest()
  246.         placeTorch()
  247.         term.clear()
  248.         print("Done!")
  249.     else
  250.         work()
  251.     end
  252. end
  253.  
  254. restart()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement