Advertisement
henritom

turtle.mining 1.0

Jul 7th, 2021 (edited)
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.13 KB | None | 0 0
  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.     if turtle.detect() then
  63.         turtle.dig()
  64.         turtle.forward()
  65.         distanceBuild = distanceBuild - 1
  66.         distanceTorch = distanceTorch - 1
  67.     else
  68.         turtle.forward()
  69.     end
  70.  
  71.     if turtle.detectUp() then  
  72.         turtle.digUp()
  73.     end
  74.     dig()
  75. end
  76.  
  77. getInventory = function()
  78.     fuel = turtle.getItemCount(1)
  79.     chest = turtle.getItemCount(2)
  80.     torch = turtle.getItemCount(3)
  81. end
  82.  
  83. checkInventory = function()
  84.     term.clear()
  85.     print("Checking Fuel...")
  86.     if fuel == 0 then
  87.         print("Missing: Fuel - Slot 1")
  88.     else
  89.         print("Enough Fuel")
  90.         itemsNeeded = itemsNeeded - 1
  91.     end
  92.    
  93.     print(" ")
  94.     print("Checking Chests...")
  95.     if chest == 0 then
  96.         print("Missing: Chest - Slot 2")
  97.     else
  98.         print("Enough Chests")
  99.         itemsNeeded = itemsNeeded - 1
  100.     end
  101.    
  102.     print(" ")
  103.     print("Checking Torch...")
  104.     if torch == 0 then
  105.         print("Missing: Torch - Slot 3")
  106.     else
  107.         print("Enough Torch")
  108.         itemsNeeded = itemsNeeded - 1
  109.     end
  110.  
  111.     if itemsNeeded == 0 then
  112.         print(" ")
  113.         print("No more items needed!")
  114.         sleep(1.5)
  115.         checkFuel()
  116.     else
  117.         print(" ")
  118.         print("Not enough items!")
  119.     end
  120. end
  121.  
  122. checkFuel = function()
  123.     term.clear()
  124.     print("Checking Fuel Data...")
  125.     if fuelData then
  126.         if fuelData.name == "minecraft:coal" then
  127.             print("Correct Fuel Data: " .. fuelData.name)
  128.             incorrectItems = incorrectItems - 1
  129.             sleep(0.5)
  130.             checkChest()
  131.             local fullCheck = 1
  132.         else
  133.             print("Incorrect Fuel Data: " .. fuelData.name)
  134.         end
  135.     end
  136. end
  137.  
  138. checkChest = function()
  139.     term.clear()
  140.     print("Checking Chest Data...")
  141.     if chestData then
  142.         if chestData.name == "minecraft:chest" then
  143.             print("Correct Chest Data: " .. chestData.name)
  144.             incorrectItems = incorrectItems - 1
  145.             sleep(0.5)
  146.             checkTorch()
  147.         else
  148.             print("Incorrect Chest Data: " .. chestData.name)
  149.         end
  150.     end
  151. end
  152.  
  153. checkTorch = function()
  154.     term.clear()
  155.     print("Checking Torch Data...")
  156.     if torchData then
  157.         if torchData.name == "minecraft:torch" then
  158.             print("Correct Torch Data: " .. torchData.name)
  159.             incorrectItems = incorrectItems - 1
  160.             sleep(0.5)
  161.             start()
  162.         else
  163.             print("Incorrect Torch Data: " .. torchData.name)
  164.         end
  165.     end
  166. end
  167.  
  168. local function turnTurtle()
  169.     turtle.turnRight()
  170.     turtle.turnRight()
  171. end
  172.  
  173. local function placeChest()
  174.     print("Placing chest...")
  175.     if chestData then
  176.         if chestData.name == "minecraft:chest" then
  177.             print("Available Chests: " .. chestData.count)
  178.             turtle.digDown()
  179.             turtle.select(2)
  180.             turtle.placeDown()
  181.             print("Placed Chest!")
  182.             for chestSlot = 4, 16 do
  183.                 turtle.select(chestSlot)
  184.                 turtle.dropDown()
  185.             end
  186.         else
  187.             print("Incorrect Chest Data: " .. chestData.name .. " " .. chestData.count)
  188.         end
  189.     else
  190.         print("Not enough chests!")
  191.     end
  192. end
  193.  
  194. local function placeTorch()
  195.     print("Placing Torch...")
  196.     if torchData then
  197.         if torchData.name == "minecraft:torch" then
  198.             print("Available Torches: " .. torchData.count)
  199.             turnTurtle()
  200.             turtle.select(3)
  201.             turtle.place()
  202.             print("Placed Torch!")
  203.             turnTurtle()
  204.         else
  205.             print("Incorrect Torch Data: " .. torchData.name .. " " .. torchData.count)
  206.         end
  207.     else
  208.         print("Not enough Torches!")
  209.     end
  210. end
  211.  
  212. local function refuel()
  213.     print("Refueling...")
  214.     if fuelData then
  215.         if fuelData.name == "minecraft:coal" then
  216.             print("Available Fuel: " .. fuelData.count)
  217.             turtle.select(1)
  218.             turtle.refuel(1)
  219.         else
  220.             print("Incorrect Fuel Data: " .. fuelData.name .. " " .. fuelData.count)
  221.         end
  222.     else
  223.         print("Not enough Fuel!")
  224.     end
  225. end
  226.  
  227. dig = function()
  228.     term.clear()
  229.     if turtle.getFuelLevel() == 0 then
  230.         refuel()
  231.     end
  232.  
  233.     if fullData then
  234.         placeChest()
  235.     end
  236.  
  237.     if distanceTorch == 0 then
  238.         placeTorch()
  239.         distanceTorch = defaultDistanceTorch
  240.     end
  241.     print("mining...")
  242.  
  243.     if distanceBuild == 0 then
  244.         print("done...")
  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