Advertisement
YannMarcotte

Advanced Branch Mining Turtle + Lava Refuel (second/over)

Mar 26th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.43 KB | None | 0 0
  1. --Variable Declarations
  2. local mainShaftDim = "2x2"
  3. local sideShaftDim = "2x1"
  4. local shaftFreq = "3"
  5. local totalCost = 0
  6. local input = ""
  7. local length = 0
  8. local currentPos = 1
  9. local chestDist = 0
  10. local doFuel = false
  11.  
  12.  
  13.  
  14. -- Function Declarations
  15.  
  16. -- Refuels the turtle with slots 1-15
  17. function refuel()
  18.     for i=1,15,1 do
  19.         turtle.select(i)
  20.         turtle.refuel(turtle.getItemCount(i))
  21.     end
  22.     turtle.select(1)
  23. end
  24.  
  25. function dig()
  26.     local block,type = turtle.inspect()
  27.     if type.name == "minecraft:flowing_lava" then
  28.     turtle.select(1)
  29.     turtle.place()
  30.     refuel()
  31.     else
  32.     turtle.dig()
  33.     end
  34. end
  35.  
  36. function digUp()
  37.     local block,type = turtle.inspectUp()
  38.     if type.name == "minecraft:flowing_lava" then
  39.     turtle.select(1)
  40.     turtle.placeUp()
  41.     refuel()
  42.     else
  43.     turtle.digUp()
  44.     end
  45. end
  46.  
  47. -- Mines the main 2x2 shaft of the system
  48. function mainShaft()
  49.     turtle.select(1)
  50.     for i=1,4,1 do
  51.         while turtle.detect() == true do
  52.             dig()
  53.         end
  54.         turtle.forward()
  55.         while turtle.detectUp() do
  56.             digUp()
  57.         end
  58.         turtle.turnRight()
  59.         while turtle.detect() == true do
  60.             dig()
  61.         end
  62.         turtle.forward()
  63.         while turtle.detectUp() do
  64.             digUp()
  65.         end
  66.         turtle.turnRight()
  67.         turtle.turnRight()
  68.         while turtle.detect() do
  69.             dig()
  70.         end
  71.         turtle.forward()
  72.         turtle.turnRight()
  73.     end
  74.     turtle.turnRight()
  75.     turtle.turnRight()
  76.     turtle.forward()
  77.     turtle.turnLeft()
  78.     turtle.forward()
  79.     turtle.turnLeft()
  80.     turtle.forward()
  81.     turtle.turnLeft()
  82.     turtle.forward()
  83.     turtle.turnRight()
  84. end
  85.  
  86. -- Mines a 2x1 side shaft off of the main shaft of the system
  87. function sideShaft()
  88.     turtle.select(1)
  89.     for i=0,10,1 do
  90.         while turtle.detect() == true do
  91.             dig()
  92.         end
  93.         turtle.forward()
  94.         while turtle.detectUp() == true do
  95.             digUp()
  96.         end
  97.     end
  98.     turtle.turnRight()
  99.     turtle.turnRight()
  100.     turtle.turnRight()
  101.     turtle.turnRight()
  102.     turtle.select(1)
  103.     for i=0,10,1 do
  104.         while turtle.detect() == true do
  105.             dig()
  106.         end
  107.         turtle.forward()
  108.         while turtle.detectUp() == true do
  109.             digUp()
  110.         end
  111.     end
  112.     turtle.turnRight()
  113.     turtle.turnRight()
  114.     turtle.up()
  115.     for i=1,23,1 do
  116.         while turtle.detect() do
  117.             dig()
  118.         end
  119.         turtle.forward()
  120.     end
  121.     turtle.down()
  122. end
  123.  
  124.  
  125. -- Places all the goodies in the designated chest
  126. function deposit()
  127.     for i=1, (chestDist), 1 do
  128.         turtle.forward()
  129.     end
  130.     for i=2, 15, 1 do
  131.         turtle.select(i)
  132.         turtle.drop()
  133.     end
  134.     refuel()
  135.     if turtle.getFuelLevel() < (108 + 2 * chestDist) then
  136.         stopMining()
  137.     end
  138.     turtle.turnRight()
  139.     turtle.turnRight()
  140.     for i=1, (chestDist), 1 do
  141.         turtle.forward()
  142.     end
  143.  
  144. end
  145.  
  146. -- Stops mining for some reason or another
  147. function stopMining()
  148.     if turtle.getFuelLevel() < (108 + 2 * chestDist) then
  149.         print("I am low on fuel.")
  150.         local remainFuel = 0
  151.         for i=currentPos, length, 1 do
  152.             remainFuel = (108 + 2 * (4 * i + 1))
  153.         end
  154.         print("I need "..remainFuel.." to finish.")
  155.         print("That's "..(remainFuel/80).." coal or "..(remainFuel/1000).." lava.")
  156.         print("Type (cont) to refuel & continue mining.")
  157.         doFuel = true
  158.     end
  159.     if turtle.getItemCount(16) < 6 then
  160.         print("I am low on torches.")
  161.         print("Place more in slot 9...")
  162.         while turtle.getItemCount(16) < 6 do
  163.             sleep(1)
  164.         end
  165.         print("Type (cont) to continue mining.")
  166.         doFuel = false
  167.     end
  168.     local cont = false
  169.     while cont == false do
  170.         --[[
  171.         if rs.getInput("right") == true then --Flickers RS torch on right of chest
  172.             rs.setOutput("right", false)
  173.         else
  174.             rs.setOutput("right", true)
  175.         end
  176.         ]]
  177.         local input = io.read()
  178.         if input == "cont" then
  179.  
  180.             if doFuel then
  181.                 refuel()
  182.             end
  183.  
  184.             turtle.turnRight()
  185.             turtle.turnRight()
  186.             for i=1, chestDist, 1 do
  187.                 turtle.forward()
  188.             end
  189.             currentPos = currentPos + 1
  190.             run()
  191.         else
  192.             print("Incorrect input.")
  193.         end
  194.     end
  195. end
  196.  
  197. -- Run the mining loop
  198. function run()
  199.     while currentPos < length do
  200.         chestDist = (currentPos * 4 + 4)
  201.         mainShaft()
  202.         turtle.turnLeft()
  203.         sideShaft()
  204.         sideShaft()
  205.         turtle.turnLeft()
  206.         deposit()
  207.         currentPos = currentPos + 1
  208.     end
  209. end
  210.  
  211. -- Alert system for user, using the redstone torch
  212. function idle()
  213.     print("Mining Complete")
  214.     print("Type (end) to terminate program")
  215.     local input = "null"
  216.     rs.setOutput("right", true)
  217.     while input ~= "end" do
  218.         input = io.read()
  219.     end
  220.     rs.setOutput("right", false)
  221. end
  222.  
  223. --Execution
  224. print("----------------------------------")
  225. print("Branch Mine Turtle Activated")
  226. print("----------------------------------")
  227. sleep(2)
  228. print("Beginning Mine w. Following Specs:")
  229. print("Main Shaft: "..mainShaftDim)
  230. print("Side Shafts: "..sideShaftDim)
  231. print("Branch Frequency: "..shaftFreq)
  232. print("----------------------------------")
  233.  
  234. print("Number of Shafts:")
  235. length = tonumber(read())
  236. currentPos = 0
  237. print("----------------------------------")
  238.  
  239. for x = length, 0, -1 do
  240.     totalCost = totalCost + (108 + 2 * (4 * x + 1))
  241. end
  242.  
  243.  
  244. print("Current Fuel: "..turtle.getFuelLevel())
  245. print("Fuel cost: "..totalCost)
  246. print("Coal cost: "..(totalCost/80))
  247. print("Lava cost: "..(totalCost/1000))
  248. sleep(2)
  249. print("----------------------------------")
  250. print("Would you like to refuel now (y/n)?")
  251. input = io.read()
  252. if input == "y" then
  253.     refuel()
  254.     print("Refueled.")
  255. else
  256.     print("Did not refuel.")
  257. end
  258. print("Turtle now has "..turtle.getFuelLevel().." fuel.")
  259. print("----------------------------------")
  260.  
  261. print("Now beginning mining!")
  262.  
  263. run()
  264. turtle.turnRight()
  265. turtle.turnRight()
  266. for i=1, chestDist, 1 do
  267.     turtle.forward()
  268. end
  269. idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement